stratego song zhou *include slides from language.org/stratego/slidesforsoftwaregeneration2001...

Post on 14-Jan-2016

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Stratego

Song Zhou

*Include slides from http://www.stratego-language.org/Stratego/SlidesForSoftwareGeneration2001

Introduction

Stratego is “a language for the specification of transformation systems based on the paradigm of program rewriting strategies”.

Basic components: Rules: basic transformation steps Strategies: control application of rules

Stratego/XT Stratego is only a term-rewriting language. “Term in,

Term out.” XT can combine Stratego with other tools to create a transformation system.

Front End: SGLR: a generic parser creating syntax tree

Back End: GPP: a generic pretty-printer to emit the syntax tree

out Communication Language

Aterm: a term exchange format

Transformation Rules

Outline

Transformation Strategies

Traversal

First-Class Pattern Matching

Scoped Dynamic Rewrite Rules

Concrete Object Syntax

What is wrong with Abstract Syntax

Problems Easy for computer to process Difficult for human being to read and

write Maybe to verbose to be specified

Solution Directly employ the concrete object

syntax to specify the rewriting rules in Stratego

Mix an Object Language With a Meta Language Object Language inside Meta Language:

Extending Meta Language with a quotation operator that lets the meta-programmer indicate object language fragments.

Meta Language inside Object Language: Antiquotation allows the use of meta-programming

language constructs in these object language fragments to splice meta-computed object code into a fragment.

If Meta Language equals Object Language then the syntax extension is easy by just adding quote and antiquote operators to Meta Language.

Example EvalPlus : |[ i + j ]| -> |[ k ]|

where <add>(i, j) => k TraceProcedure :

|[ function ~f(~* xs) = ~e ]| -> |[ function ~f(~* xs) = (print(~String(<conc-strings>(f," entry\\n"))); ~e; print(~String(<conc-strings>(f,"exit\\n"))))]|

Syntax Definition Formalism Both the Stratego syntax and the object language syntax is

specified using the Syntax Definition Formalism (SDF) An SDF production sym1 ... symn -> sym declares that an

expression of sort sym can be constructed by the concatenation of expressions of sorts sym1 to symn.

SDF supports regular expression operators such as {Exp ";"}*, which denotes a list of Expressions separated by ; semicolons.

SDF integrates the definition of lexical and context-free syntax in one formalism.

The formalism is modular the syntax definition of a language can be divided into smaller

(reusable) modules syntax definitions for separate languages can easily be

combined.

Stratego Syntax Definition in SDF

Tiger Syntax Definition in SDF

Corresponding Abstract SyntaxSignature

Syntax Combination

The object language syntax definition can be imported into Stratego syntax definition

We also need define an additional combinationial syntax definiton, to specify the glues (quotation mark and antiquotaion mark)

Example of Combinational Syntax Definition

Theoretical Problems

Only full class of CFG have closure property. LL, LR and other subclasses of CFG are not closed under composition.

SDF2 supports scannerless generalized-LR parsing

Meta-Explode Convert concrete

object syntax term into Stratego syntax term

Generic Definition of Meta-explode

Summarize

Rules rewriting Transformation strategy First-Class Pattern Matching Scoped Dynamic Rewrite Rules Concrete Object Syntax

top related