growing a syntax
play

Growing a Syntax Eric Allen 1 , Ryan Culpepper 2 , Janus Dam Nielsen - PowerPoint PPT Presentation

Growing a Language Objectives and Example Syntax Normalization Summary Growing a Syntax Eric Allen 1 , Ryan Culpepper 2 , Janus Dam Nielsen 3 , Jon Rafkind 4 , and Sukyoung Ryu 1 1 Sun Microsystems 2 Northeastern University 3 Aarhus University 4


  1. Growing a Language Objectives and Example Syntax Normalization Summary Growing a Syntax Eric Allen 1 , Ryan Culpepper 2 , Janus Dam Nielsen 3 , Jon Rafkind 4 , and Sukyoung Ryu 1 1 Sun Microsystems 2 Northeastern University 3 Aarhus University 4 University of Utah Foundations of Object-Oriented Languages, 2009

  2. Growing a Language Objectives and Example Syntax Normalization Summary Outline Growing a Language 1 Fortress Introduction Growing a Language XML Example Introduction Objectives and Example 2 Syntactic Abstraction Goals XML as an Example Syntax Normalization 3 Parsing and Transformation

  3. Growing a Language Objectives and Example Syntax Normalization Summary Fortress Introduction Outline Growing a Language 1 Fortress Introduction Growing a Language XML Example Introduction Objectives and Example 2 Syntactic Abstraction Goals XML as an Example Syntax Normalization 3 Parsing and Transformation

  4. Growing a Language Objectives and Example Syntax Normalization Summary Fortress Introduction The Fortress Programming Language A multicore language for scientists and engineers

  5. Growing a Language Objectives and Example Syntax Normalization Summary Fortress Introduction The Fortress Programming Language A multicore language for scientists and engineers Run your whiteboard in parallel!

  6. Growing a Language Objectives and Example Syntax Normalization Summary Fortress Introduction The Fortress Programming Language A multicore language for scientists and engineers Run your whiteboard in parallel! v norm = v / � v || c ij = a ik b kj � k ← 0 : n C = A ∪ B y = 3 x sin x cos 2 x log log x

  7. Growing a Language Objectives and Example Syntax Normalization Summary Fortress Introduction The Fortress Programming Language A multicore language for scientists and engineers Run your whiteboard in parallel! v norm = v / � v || c ij = a ik b kj � k ← 0 : n C = A ∪ B y = 3 x sin x cos 2 x log log x

  8. Growing a Language Objectives and Example Syntax Normalization Summary Fortress Introduction The Fortress Programming Language A multicore language for scientists and engineers Run your whiteboard in parallel! v norm = v / � v || c ij = a ik b kj � k ← 0 : n C = A ∪ B y = 3 x sin x cos 2 x log log x Growing a Language Guy L. Steele Jr., keynote talk OOPSLA 1998 Higher-Order and Symbolic Computation 12, 221-236 (1999)

  9. Growing a Language Objectives and Example Syntax Normalization Summary Growing a Language Outline Growing a Language 1 Fortress Introduction Growing a Language XML Example Introduction Objectives and Example 2 Syntactic Abstraction Goals XML as an Example Syntax Normalization 3 Parsing and Transformation

  10. Growing a Language Objectives and Example Syntax Normalization Summary Growing a Language Growing a Language “So I think the sole way to win is to plan for growth with help from the users.” Guy L. Steele Jr. keynote talk, OOPSLA 1998; Higher-Order and Symbolic Computation 12, 221-236 (1999)

  11. Growing a Language Objectives and Example Syntax Normalization Summary Growing a Language Design Strategy Consider how a proposed language feature might be provided by a library rather than building features directly into the compiler. This requires control over both syntax and semantics, not just the ability to add new functions and methods.

  12. Growing a Language Objectives and Example Syntax Normalization Summary XML Example Introduction Outline Growing a Language 1 Fortress Introduction Growing a Language XML Example Introduction Objectives and Example 2 Syntactic Abstraction Goals XML as an Example Syntax Normalization 3 Parsing and Transformation

  13. Growing a Language Objectives and Example Syntax Normalization Summary XML Example Introduction XML in Fortress x = < html xmlns = “ http://www.w3.org/1999/xhtml ” > < title > Project Fortress </ title > < body /> </ html > < body />. hasElements x . children x . attributes XML literals in Fortress Seamless integration DOM operations on values

  14. Growing a Language Objectives and Example Syntax Normalization Summary XML Example Introduction XML in Fortress x = < html xmlns = “ http://www.w3.org/1999/xhtml ” > < title > Project Fortress </ title > < body /> </ html > < body />. hasElements x . children x . attributes XML literals in Fortress Seamless integration DOM operations on values

  15. Growing a Language Objectives and Example Syntax Normalization Summary XML Example Introduction XML in Fortress x = < html xmlns = “ http://www.w3.org/1999/xhtml ” > < title > Project Fortress </ title > < body /> </ html > < body />. hasElements x . children x . attributes XML literals in Fortress Seamless integration DOM operations on values

  16. Growing a Language Objectives and Example Syntax Normalization Summary XML Example Introduction Desugaring XML The XML literal: < html xmlns = “ http://www.w3.org/1999/xhtml ” > < title > Project Fortress </ title > < body /> </ html > Desugars to: Element ( Header ( “ html ” , � Attribute ( “ xmlns ” , “ http://www.w3.org/1999/xhtml ” ) � ) , � Element ( Header ( “ title ” , � � ) , � CData ( “ Project Fortress ” ) � , “ title ” ) , Element ( Header ( “ body ” , � � ) , � � , “ body ” ) � , “ html ” )

  17. Growing a Language Objectives and Example Syntax Normalization Summary XML Example Introduction Basic XML DOM Structure in Fortress object Element ( info : Header , contents : List � Content � , endTag : String ) extends Content getter name () : String getter hasElements () : Boolean getter children () : List � Element � getter cdata () : CData getter attributes () : List � Attribute � getter toXml () : String end trait Content end object CData ( c : String ) extends Content end object Header ( startTag : String , attributes : List � Attribute � ) end object Attribute ( key : String , val : String ) end

  18. Growing a Language Objectives and Example Syntax Normalization Summary XML Example Introduction Desugaring XML Design Strategy Consider how a proposed language feature might be provided by a library rather than building features directly into the compiler XML desugaring is provided by syntactic abstraction in a library

  19. Growing a Language Objectives and Example Syntax Normalization Summary Syntactic Abstraction Goals Outline Growing a Language 1 Fortress Introduction Growing a Language XML Example Introduction Objectives and Example 2 Syntactic Abstraction Goals XML as an Example Syntax Normalization 3 Parsing and Transformation

  20. Growing a Language Objectives and Example Syntax Normalization Summary Syntactic Abstraction Goals Syntactic Abstraction Goals New syntax indistinguishable from core syntax Similar syntax for definition/use of a language extension Composition of independent language extensions Expansion into other language extensions Mutually recursive definition of language extensions

  21. Growing a Language Objectives and Example Syntax Normalization Summary XML as an Example Outline Growing a Language 1 Fortress Introduction Growing a Language XML Example Introduction Objectives and Example 2 Syntactic Abstraction Goals XML as an Example Syntax Normalization 3 Parsing and Transformation

  22. Growing a Language Objectives and Example Syntax Normalization Summary XML as an Example Grammar of XML Literals in Fortress grammar xml extends { Expression , Symbols } Expr | := x : XExpr ⇒ < [ x ] > XExpr ::= b : startTag c : XmlContent e : endTag ⇒ < [ Element ( b , c , e ) ] > | b : startTag e : endTag ⇒ < [ Element ( b , � � , e ) ] > XmlContent ::= s : XmlIdentifier ⇒ < [ � CData ( s ) � ] > | { x : XExpr SPACE } + ⇒ < [ � x ** � ] > startTag ::= < s : XmlIdentifier { a : Attribute SPACE } ∗ > ⇒ < [ Header ( s , � a ** � ] > endTag ::= </ s : XmlIdentifier > ⇒ < [ s ] > end

  23. Growing a Language Objectives and Example Syntax Normalization Summary XML as an Example Examples of Goals New syntax indistinguishable from core syntax < body /> . hasElements Similar syntax for definition/use of a language extension < s : XmlIdentifier { a : Attribute SPACE } ∗ /> ⇒ . . . < html xmlns = “ http://www.w3.org/1999/xhtml ” />

  24. Growing a Language Objectives and Example Syntax Normalization Summary XML as an Example Examples of Goals Composition of independent language extensions grammar xml extends { Expression , Symbols } Expansion into other language extensions . . . ⇒ < [ < body /> ] > Mutually recursive definition of language extensions

  25. Growing a Language Objectives and Example Syntax Normalization Summary Parsing and Transformation Outline Growing a Language 1 Fortress Introduction Growing a Language XML Example Introduction Objectives and Example 2 Syntactic Abstraction Goals XML as an Example Syntax Normalization 3 Parsing and Transformation

  26. Growing a Language Objectives and Example Syntax Normalization Summary Parsing and Transformation Syntax Normalization Parsing stage - transforms a source program (in text) into a parsed program (in node expression) Transformation stage - transforms the parsed program into a program in executable core Fortress AST

Recommend


More recommend