Download presentation
Presentation is loading. Please wait.
Published byKerry Dean Modified over 9 years ago
1
Stratego Song Zhou *Include slides from http://www.stratego- language.org/Stratego/SlidesForSoftwareGeneration2001http://www.stratego- language.org/Stratego/SlidesForSoftwareGeneration2001
2
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
3
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
4
Transformation Rules
5
Outline
28
Transformation Strategies
44
Traversal
58
First-Class Pattern Matching
76
Scoped Dynamic Rewrite Rules
88
Concrete Object Syntax
89
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
90
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.
91
Example EvalPlus : |[ i + j ]| -> |[ k ]| where (i, j) => k TraceProcedure : |[ function ~f(~* xs) = ~e ]| -> |[ function ~f(~* xs) = (print(~String( (f," entry\\n"))); ~e; print(~String( (f,"exit\\n"))))]|
92
Syntax Definition Formalism Both the Stratego syntax and the object language syntax is specified using the Syntax Definition Formalism (SDF) An SDF production sym 1... sym n -> sym declares that an expression of sort sym can be constructed by the concatenation of expressions of sorts sym 1 to sym n. 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.
93
Stratego Syntax Definition in SDF
94
Tiger Syntax Definition in SDF
95
Corresponding Abstract Syntax Signature
96
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)
97
Example of Combinational Syntax Definition
98
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
99
Meta-Explode Convert concrete object syntax term into Stratego syntax term
100
Generic Definition of Meta-explode
101
Summarize Rules rewriting Transformation strategy First-Class Pattern Matching Scoped Dynamic Rewrite Rules Concrete Object Syntax
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.