101
Stratego Song Zhou *Include slides from http://www.stratego-language.org/Stratego/SlidesForSoftwareGener ation2001

Stratego

Embed Size (px)

DESCRIPTION

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: - PowerPoint PPT Presentation

Citation preview

  • StrategoSong Zhou

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

  • IntroductionStratego is a language for the specification of transformation systems based on the paradigm of program rewriting strategies.Basic components:Rules: basic transformation stepsStrategies: control application of rules

  • Stratego/XTStratego 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 treeBack End:GPP: a generic pretty-printer to emit the syntax tree outCommunication LanguageAterm: 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 SyntaxProblemsEasy for computer to processDifficult for human being to read and writeMaybe to verbose to be specifiedSolutionDirectly employ the concrete object syntax to specify the rewriting rules in Stratego

  • Mix an Object Language With a Meta LanguageObject 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.

  • ExampleEvalPlus : |[ i + j ]| -> |[ k ]| where (i, j) => kTraceProcedure : |[ function ~f(~* xs) = ~e ]| -> |[ function ~f(~* xs) = (print(~String((f," entry\\n"))); ~e; print(~String((f,"exit\\n"))))]|

  • Syntax Definition FormalismBoth 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 CombinationThe object language syntax definition can be imported into Stratego syntax definitionWe also need define an additional combinationial syntax definiton, to specify the glues (quotation mark and antiquotaion mark)

  • Example of Combinational Syntax Definition

  • Theoretical ProblemsOnly 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-ExplodeConvert concrete object syntax term into Stratego syntax term

  • Generic Definition of Meta-explode

  • SummarizeRules rewritingTransformation strategyFirst-Class Pattern MatchingScoped Dynamic Rewrite RulesConcrete Object Syntax