Stratego
Download
1 / 101

Stratego - PowerPoint PPT Presentation


  • 125 Views
  • Uploaded on

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:

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Stratego' - dorcas


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Stratego

Stratego

Song Zhou

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


Introduction
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/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









What is wrong with abstract 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
Mix an Object Language With a Meta Language

  • Object Language inside Meta Language:

    • Extending Meta Language witha quotation operator that lets the meta-programmer indicate object languagefragments.

  • Meta Language inside Object Language:

    • Antiquotation allows the use of meta-programming languageconstructs in these object language fragments to splice meta-computed objectcode into a fragment.

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


Example
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
Syntax Definition Formalism

  • Both the Stratego syntax and the object language syntax is specified using the Syntax Definition Formalism (SDF)

  • AnSDF production sym1 ... symn -> sym declares that an expression of sort symcan be constructed by the concatenation of expressions of sorts sym1 to symn.

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

  • SDF integrates thedefinition of lexical and context-free syntax in one formalism.

  • The formalismis modular

    • the syntax definition of a language can be divided intosmaller (reusable) modules

    • syntax definitions for separate languages caneasily be combined.



Tiger s yntax d e fi nition in sdf
TigerSyntax Definition in SDF


Corresponding a bstract s yntax s ignature
Corresponding Abstract SyntaxSignature


Syntax combination
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)



Theoretical problems
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



Generic d e fi nition of m eta explode
Generic termDefinition of Meta-explode


Summarize
Summarize term

  • Rules rewriting

  • Transformation strategy

  • First-Class Pattern Matching

  • Scoped Dynamic Rewrite Rules

  • Concrete Object Syntax


ad