SlideShare a Scribd company logo
1 of 29
Download to read offline
Decor ated
     Attribute Gr ammar s
    Attribute Evaluation Meets Strategic Programming




CC 2009, York, UK

Lennart Kats, TU Delft (me)
Tony Sloane, Macquarie
Eelco Visser, TU Delft
March 19, 2009



Software Engineering Research Group
Context

• Domain-specific languages
   • example: WebDSL
   • language composition and extension
• SDF/SGLR + Stratego/XT
   • abstract syntax trees
   • traversal, rewrite rules
Trees and Attribute Grammars

• Attributes
   • Declarative, compositional equations
   • Express dependencies between nodes
• Attribute evaluator
   • Determines evaluation
     order
Basic Example: Global Minimum

                          def Root(t):
                           id.min := t.min
                           t.gmin := t.min

                          def Fork(t1, t2):
                           id.min := <min> (t1.min,t2.min)
                           t1.gmin := id.gmin
                           t2.gmin := id.gmin

                          def Leaf(v):
                           id.min := v
• Synthesized: flows up
Basic Example: Global Minimum

                          def Root(t):
                           id.min := t.min
                           t.gmin := t.min

                          def Fork(t1, t2):
                           id.min := <min> (t1.min,t2.min)
                           t1.gmin := id.gmin
                           t2.gmin := id.gmin

                          def Leaf(v):
                           id.min := v
• Synthesized: flows up
• Inherited: flows down
Basic Example: Global Minimum

                                def Root(t):
         min=
         min=6                   id.min := t.min
                                 t.gmin := t.min
         min=6
                                def Fork(t1, t2):
                                 id.min := <min> (t1.min,t2.min)
    min=
    min=22
                                 t1.gmin := id.gmin
                          min=6
                                 t2.gmin := id.gmin

                                def Leaf(v):
min=31
min=             min=
                 min=22
                                 id.min := v
Basic Example: Global Minimum

                             def Root(t):
         min=
         min=6
                      gmin=6 id.min := t.min
                      gmin=
                              t.gmin := t.min
         min=6
                                def Fork(t1, t2):
                                 id.min := <min> (t1.min,t2.min)
    min=
    min=22
                                 t1.gmin := id.gmin
                          min=6
                                 t2.gmin := id.gmin

                                def Leaf(v):
min=31
min=             min=
                 min=22
                                 id.min := v
Global Minimum: Identifying Copy Rules

                             def Root(t):
         min=
         min=6
                      gmin=6 id.min := t.min
                      gmin=
                              t.gmin := t.min
         min=6
                                def Fork(t1, t2):
                                 id.min := <min> (t1.min,t2.min)
    min=
    min=22
                                 t1.gmin := id.gmin
                          min=6
                                 t2.gmin := id.gmin

                                def Leaf(v):
min=31
min=             min=
                 min=22
                                 id.min := v
Introducing Decorators

• Abstract over traversal or evaluation pattern
   • Express intent
      • min: “upward flow”
      • gmin: “downward flow”
   • May introduce default behavior
   • May modify existing behavior
Example: up/down copying decorators

                  def Root(t):
                   id.min := t.min
                   t.gmin := t.min

                  def Fork(t1, t2):
                   id.min := <min> (t1.min,t2.min)
                   t1.gmin := id.gmin
                   t2.gmin := id.gmin

                  def Leaf(v):
                   id.min := v
Example: up/down copying decorators

                  def Root(t):
                   t.gmin := t.min

                  def Fork(t1, t2):
                   id.min := <min> (t1.min,t2.min)

                  def Leaf(v):
                   id.min := v

                  def down gmin
                  def up   min
Introducing Decorators (ct'd)

Based on strategic programming
• Programmable: decorators available as a library
• Generic: independent of a particular tree
• Reflective: may use properties of attributes


decorator down(a) =     decorator up(a) =
 if a.defined then       if a.defined then
    a                       a
 else                    else
    id.parent.down(a)       id.child(id.up(a))
 end                     end
Basic Building Blocks of Decorators
    Arguments
• attribute a                 Reflective attributes
• functions, terms           • a.defined
                             • a.attribute-name
                             • a.signature


decorator down(a) =
 if a.defined then         Tree access attributes
    a                   • id.parent
 else                   • id.child(c), id.prev-sibling, ...
    id.parent.down(a)
 end
                             Recursion
Abstraction Using Decorators (1)

Boilerplate code elimination:
• avoid repetitive code (e.g., “copy rules”)
• reduce accidental complexity
• implement some of the boilerplate-coping
  mechanisms of other AG systems
Abstraction Using Decorators (2)

Control over evaluation:
• tracing
  tracing
• memoization
• assertions
            def trace gmin

            decorator trace(a) =
             t := id;
             a;
             log(|[a.attribute-name, " at ", t.path, ": ", id])
Abstraction Using Decorators (2)

Control over evaluation:
• tracing
• memoization
  memoization
• assertions
                decorator default-caching(a) =
                 if id.get-cached(a) then
                    id.get-cached(a)
                 elseif a then
                    ...
                    a;
                   ...set-cached...
                 end
Abstraction Using Decorators (2)

Control over evaluation:
• tracing
• memoization
• assertions def assert-after(<leq> (id.gmin, id.min)) gmin
  assertions
               decorator assert-after(a, c) =
                t := id;
                a;
                id.set-cached-for(a|t);
                if not(<c> t) then
                  fatal-err(|["Assertion failed for ",
                              a.attribute-name, " at ", t.path])
                end
Abstraction Using Decorators (3)

Help in typical compiler front-end tasks:
• name analysis
• type analysis
• control- and data-flow analysis

encapsulation of recurring attribution patterns
Type Analysis with Aster

def type:                            Concrete syntax [Visser 2002]
 Int(i)           → IntType           VarDecl(x, t)
 |[ var x : t ; ]| → t
 Var(x)           → id.lookup-local(|x).type
 |[ f (arg*) ]|   → id.lookup-function(|f, arg*).type
 ...


 Reference attributes [Hedin 2000]
 look up declaration nodes
   var x : Int;
Type Analysis with Aster:
  Using Decorators (1)

Lookup decorators require:
• Lookup type (ordered, unordered, global, ...)
• Tree nodes to fetch
• Scoping definition

def lookup-ordered(id.is-scope) lookup-local(|x):
 |[ var x : t ; ]| → id
 |[     x : t ]| → id
Type Analysis with Aster:
  Using Decorators (2)

Lookup decorators require:
• Lookup type (ordered, unordered, global, ...)
• Tree nodes to fetch
• Scoping definition

def is-scope:
 |[ { s* } ]|                          → id
 |[ function x(param*) : t { stm* } ]| → id
 ...
Type Analysis with Aster:
 Using Decorators (3)

def lookup-unordered(id.is-scope) lookup-function(|x, arg*):
 |[ function x (param*) : t { stm* } ]| → id
    where
      argtype*     := arg*.map(id.type);
      paramtype* := param*.map(id.type);
      paramtype*.eq(|argtype*)
Type Analysis with Aster:
 Decorator Definitions
decorator down lookup-ordered(a, is-s) = function x() : Int {
 if a then                                       var j : Int;
    a                 Decorator stacking         ...
 else                                          }
    id.prev-sibling(id.lookup-inside(a, is-s))
 end                                           function y() : Int {
                                                 if (true) {
decorator lookup-inside(a, is-scope) =             var i : Int;
 if a then                                       }
    a                                            return j;
 else if not(is-scope) then                    }
    // enter preceding subtrees
    id.child(id.lookup-inside(a, is-scope))
 end
Error Reporting Using Decorators

def errors:                           module Constraints
 |[ while (e) s ]| → "Condition must be of type Boolean"
    where not(e.type  BoolType)

 ...


                                            module Reporting
def collect-all add-error-context errors
                                              Decorator stacking
decorator add-error-context(a) =
 <conc-strings > (a," at ", id.pp, " in ", id.file, ":",
                  id.linenumber)
Control-flow Analysis (1)

def default(id.default-succ) succ:
 |[ if (e) s1 else s2 ]| → [s1, s2]
 |[ return e ; ]|        → []
 |[ { s1; s* } ]|        → [s1]
 ...

decorator default(a, default) =
 if a.defined then
    a
 else
    default
 end
Control-flow Analysis (2)

def down default-succ:
 Program(_) → []
 [s1, s2 | _ ].s1 → [s2]
 ...
“But Wait, There's More!”

• Data-flow analysis
  • reaching definitions, liveness, ...
  • data-flow equations as attribute equations
  • circular (fixed point) attribute evaluation
• Deriving the reverse control flow

// Statement copies itself to successors
def contributes-to(id.succ) pred:
  stm → id
Go Figures!

•   Syntax:      3   modules    341   lines
•   Compiler:   25   modules   2831   lines
•   Library:    25   modules   1845   lines
•   Tests:      33   modules   1531   lines
    Total:      86 modules     6548 lines
Concluding Remarks
 • Language growth in the hands of the users
     • decorators implement automatic copy rules, self rules,
       collection attributes, circular attributes, ...
 • Combine generic behavior with (simple) reflection
 • Future:
     • Library, language extension
     • IDE integration

Decorated Attribute Grammars. Attribute Evaluation Meets Strategic
Programming. Lennart C. L. Kats, Anthony M. Sloane, and Eelco Visser.
18th International Conference on Compiler Construction (CC 2009).
http://www.strategoxt.org/Stratego/Aster

More Related Content

What's hot

TensorFlow Tutorial
TensorFlow TutorialTensorFlow Tutorial
TensorFlow TutorialNamHyuk Ahn
 
Computer security
Computer security Computer security
Computer security Harry Potter
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonshin
 
Declarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesDeclarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesEelco Visser
 
The Challenge of Bringing FEZ to PlayStation Platforms
The Challenge of Bringing FEZ to PlayStation PlatformsThe Challenge of Bringing FEZ to PlayStation Platforms
The Challenge of Bringing FEZ to PlayStation PlatformsMiguel Angel Horna
 
Lesson 8: Basic Differentiation Rules
Lesson 8: Basic Differentiation RulesLesson 8: Basic Differentiation Rules
Lesson 8: Basic Differentiation RulesMatthew Leingang
 
Class 29: Inheritance
Class 29: InheritanceClass 29: Inheritance
Class 29: InheritanceDavid Evans
 
23 industrial engineering
23 industrial engineering23 industrial engineering
23 industrial engineeringmloeb825
 
Google Go For Ruby Hackers
Google Go For Ruby HackersGoogle Go For Ruby Hackers
Google Go For Ruby HackersEleanor McHugh
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real Worldosfameron
 

What's hot (15)

TensorFlow Tutorial
TensorFlow TutorialTensorFlow Tutorial
TensorFlow Tutorial
 
Computer security
Computer security Computer security
Computer security
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
 
Declarative Name Binding and Scope Rules
Declarative Name Binding and Scope RulesDeclarative Name Binding and Scope Rules
Declarative Name Binding and Scope Rules
 
The Challenge of Bringing FEZ to PlayStation Platforms
The Challenge of Bringing FEZ to PlayStation PlatformsThe Challenge of Bringing FEZ to PlayStation Platforms
The Challenge of Bringing FEZ to PlayStation Platforms
 
Lesson 8: Basic Differentiation Rules
Lesson 8: Basic Differentiation RulesLesson 8: Basic Differentiation Rules
Lesson 8: Basic Differentiation Rules
 
Hammurabi
HammurabiHammurabi
Hammurabi
 
Scala best practices
Scala best practicesScala best practices
Scala best practices
 
SA09 Realtime education
SA09 Realtime educationSA09 Realtime education
SA09 Realtime education
 
Class 29: Inheritance
Class 29: InheritanceClass 29: Inheritance
Class 29: Inheritance
 
23 industrial engineering
23 industrial engineering23 industrial engineering
23 industrial engineering
 
Core C#
Core C#Core C#
Core C#
 
Google Go For Ruby Hackers
Google Go For Ruby HackersGoogle Go For Ruby Hackers
Google Go For Ruby Hackers
 
TensorFlow
TensorFlowTensorFlow
TensorFlow
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 

Viewers also liked

Assessing Feedback for Indirect Shared Interaction
Assessing Feedback for Indirect Shared InteractionAssessing Feedback for Indirect Shared Interaction
Assessing Feedback for Indirect Shared InteractionJorge Cardoso
 
Language Study M3 B8
Language Study M3 B8Language Study M3 B8
Language Study M3 B8Gracie Lee
 
A framework for context-aware adaptation in public displays
A framework for context-aware adaptation in public displaysA framework for context-aware adaptation in public displays
A framework for context-aware adaptation in public displaysJorge Cardoso
 
Service Oriented Enterprise Architecture and Service Oriented Enterprise
Service Oriented Enterprise Architecture and Service Oriented EnterpriseService Oriented Enterprise Architecture and Service Oriented Enterprise
Service Oriented Enterprise Architecture and Service Oriented EnterpriseYan Zhao
 
Evaluation of a programming toolkit for interactive public display applications
Evaluation of a programming toolkit for interactive public display applicationsEvaluation of a programming toolkit for interactive public display applications
Evaluation of a programming toolkit for interactive public display applicationsJorge Cardoso
 
Computer Vision For Computer Music
Computer Vision For Computer MusicComputer Vision For Computer Music
Computer Vision For Computer MusicJorge Cardoso
 

Viewers also liked (8)

Assessing Feedback for Indirect Shared Interaction
Assessing Feedback for Indirect Shared InteractionAssessing Feedback for Indirect Shared Interaction
Assessing Feedback for Indirect Shared Interaction
 
Internet of Things
Internet of Things Internet of Things
Internet of Things
 
Attribute
AttributeAttribute
Attribute
 
Language Study M3 B8
Language Study M3 B8Language Study M3 B8
Language Study M3 B8
 
A framework for context-aware adaptation in public displays
A framework for context-aware adaptation in public displaysA framework for context-aware adaptation in public displays
A framework for context-aware adaptation in public displays
 
Service Oriented Enterprise Architecture and Service Oriented Enterprise
Service Oriented Enterprise Architecture and Service Oriented EnterpriseService Oriented Enterprise Architecture and Service Oriented Enterprise
Service Oriented Enterprise Architecture and Service Oriented Enterprise
 
Evaluation of a programming toolkit for interactive public display applications
Evaluation of a programming toolkit for interactive public display applicationsEvaluation of a programming toolkit for interactive public display applications
Evaluation of a programming toolkit for interactive public display applications
 
Computer Vision For Computer Music
Computer Vision For Computer MusicComputer Vision For Computer Music
Computer Vision For Computer Music
 

Similar to Decorated Attribute Grammars (CC 2009)

06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptxMouDhara1
 
CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)Hiroki Mizuno
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1Little Tukta Lita
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonTendayi Mawushe
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Languagemspline
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)François Sarradin
 
Swift for tensorflow
Swift for tensorflowSwift for tensorflow
Swift for tensorflow규영 허
 
Scala implicits
Scala implicitsScala implicits
Scala implicitsnkpart
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Mozaic Works
 
"Mesh of Periodic Minimal Surfaces in CGAL."
"Mesh of Periodic Minimal Surfaces in CGAL.""Mesh of Periodic Minimal Surfaces in CGAL."
"Mesh of Periodic Minimal Surfaces in CGAL."Vissarion Fisikopoulos
 
What is TensorFlow and why do we use it
What is TensorFlow and why do we use itWhat is TensorFlow and why do we use it
What is TensorFlow and why do we use itRobert John
 

Similar to Decorated Attribute Grammars (CC 2009) (20)

06 Recursion in C.pptx
06 Recursion in C.pptx06 Recursion in C.pptx
06 Recursion in C.pptx
 
CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)CoqでGCの証明をしてみたよ(LT)
CoqでGCの証明をしてみたよ(LT)
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
โปรแกรมย่อยและฟังชั่นมาตรฐาน ม.6 1
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in Python
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
Computing on Encrypted Data
Computing on Encrypted DataComputing on Encrypted Data
Computing on Encrypted Data
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
 
Swift for tensorflow
Swift for tensorflowSwift for tensorflow
Swift for tensorflow
 
Trafaret: monads and python
Trafaret: monads and pythonTrafaret: monads and python
Trafaret: monads and python
 
Python speleology
Python speleologyPython speleology
Python speleology
 
Scala implicits
Scala implicitsScala implicits
Scala implicits
 
Lec16
Lec16Lec16
Lec16
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
Stefan Kanev: Clojure, ClojureScript and Why They're Awesome at I T.A.K.E. Un...
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
"Mesh of Periodic Minimal Surfaces in CGAL."
"Mesh of Periodic Minimal Surfaces in CGAL.""Mesh of Periodic Minimal Surfaces in CGAL."
"Mesh of Periodic Minimal Surfaces in CGAL."
 
What is TensorFlow and why do we use it
What is TensorFlow and why do we use itWhat is TensorFlow and why do we use it
What is TensorFlow and why do we use it
 

More from lennartkats

Docker at Cloud9 IDE
Docker at Cloud9 IDEDocker at Cloud9 IDE
Docker at Cloud9 IDElennartkats
 
Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)lennartkats
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloudlennartkats
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language developmentlennartkats
 
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...lennartkats
 
The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)lennartkats
 
Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)lennartkats
 
Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...
Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...
Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...lennartkats
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)lennartkats
 
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...lennartkats
 

More from lennartkats (10)

Docker at Cloud9 IDE
Docker at Cloud9 IDEDocker at Cloud9 IDE
Docker at Cloud9 IDE
 
Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloud
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
 
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
 
The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)
 
Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)
 
Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...
Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...
Providing Rapid Feedback in Generated Modular Language Environments (OOPSLA 2...
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
Mixing Source and Bytecode: A Case for Compilation By Normalization (OOPSLA 2...
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Decorated Attribute Grammars (CC 2009)

  • 1. Decor ated Attribute Gr ammar s Attribute Evaluation Meets Strategic Programming CC 2009, York, UK Lennart Kats, TU Delft (me) Tony Sloane, Macquarie Eelco Visser, TU Delft March 19, 2009 Software Engineering Research Group
  • 2. Context • Domain-specific languages • example: WebDSL • language composition and extension • SDF/SGLR + Stratego/XT • abstract syntax trees • traversal, rewrite rules
  • 3. Trees and Attribute Grammars • Attributes • Declarative, compositional equations • Express dependencies between nodes • Attribute evaluator • Determines evaluation order
  • 4. Basic Example: Global Minimum def Root(t): id.min := t.min t.gmin := t.min def Fork(t1, t2): id.min := <min> (t1.min,t2.min) t1.gmin := id.gmin t2.gmin := id.gmin def Leaf(v): id.min := v • Synthesized: flows up
  • 5. Basic Example: Global Minimum def Root(t): id.min := t.min t.gmin := t.min def Fork(t1, t2): id.min := <min> (t1.min,t2.min) t1.gmin := id.gmin t2.gmin := id.gmin def Leaf(v): id.min := v • Synthesized: flows up • Inherited: flows down
  • 6. Basic Example: Global Minimum def Root(t): min= min=6 id.min := t.min t.gmin := t.min min=6 def Fork(t1, t2): id.min := <min> (t1.min,t2.min) min= min=22 t1.gmin := id.gmin min=6 t2.gmin := id.gmin def Leaf(v): min=31 min= min= min=22 id.min := v
  • 7. Basic Example: Global Minimum def Root(t): min= min=6 gmin=6 id.min := t.min gmin= t.gmin := t.min min=6 def Fork(t1, t2): id.min := <min> (t1.min,t2.min) min= min=22 t1.gmin := id.gmin min=6 t2.gmin := id.gmin def Leaf(v): min=31 min= min= min=22 id.min := v
  • 8. Global Minimum: Identifying Copy Rules def Root(t): min= min=6 gmin=6 id.min := t.min gmin= t.gmin := t.min min=6 def Fork(t1, t2): id.min := <min> (t1.min,t2.min) min= min=22 t1.gmin := id.gmin min=6 t2.gmin := id.gmin def Leaf(v): min=31 min= min= min=22 id.min := v
  • 9. Introducing Decorators • Abstract over traversal or evaluation pattern • Express intent • min: “upward flow” • gmin: “downward flow” • May introduce default behavior • May modify existing behavior
  • 10. Example: up/down copying decorators def Root(t): id.min := t.min t.gmin := t.min def Fork(t1, t2): id.min := <min> (t1.min,t2.min) t1.gmin := id.gmin t2.gmin := id.gmin def Leaf(v): id.min := v
  • 11. Example: up/down copying decorators def Root(t): t.gmin := t.min def Fork(t1, t2): id.min := <min> (t1.min,t2.min) def Leaf(v): id.min := v def down gmin def up min
  • 12. Introducing Decorators (ct'd) Based on strategic programming • Programmable: decorators available as a library • Generic: independent of a particular tree • Reflective: may use properties of attributes decorator down(a) = decorator up(a) = if a.defined then if a.defined then a a else else id.parent.down(a) id.child(id.up(a)) end end
  • 13. Basic Building Blocks of Decorators Arguments • attribute a Reflective attributes • functions, terms • a.defined • a.attribute-name • a.signature decorator down(a) = if a.defined then Tree access attributes a • id.parent else • id.child(c), id.prev-sibling, ... id.parent.down(a) end Recursion
  • 14. Abstraction Using Decorators (1) Boilerplate code elimination: • avoid repetitive code (e.g., “copy rules”) • reduce accidental complexity • implement some of the boilerplate-coping mechanisms of other AG systems
  • 15. Abstraction Using Decorators (2) Control over evaluation: • tracing tracing • memoization • assertions def trace gmin decorator trace(a) = t := id; a; log(|[a.attribute-name, " at ", t.path, ": ", id])
  • 16. Abstraction Using Decorators (2) Control over evaluation: • tracing • memoization memoization • assertions decorator default-caching(a) = if id.get-cached(a) then id.get-cached(a) elseif a then ... a; ...set-cached... end
  • 17. Abstraction Using Decorators (2) Control over evaluation: • tracing • memoization • assertions def assert-after(<leq> (id.gmin, id.min)) gmin assertions decorator assert-after(a, c) = t := id; a; id.set-cached-for(a|t); if not(<c> t) then fatal-err(|["Assertion failed for ", a.attribute-name, " at ", t.path]) end
  • 18. Abstraction Using Decorators (3) Help in typical compiler front-end tasks: • name analysis • type analysis • control- and data-flow analysis encapsulation of recurring attribution patterns
  • 19. Type Analysis with Aster def type: Concrete syntax [Visser 2002] Int(i) → IntType VarDecl(x, t) |[ var x : t ; ]| → t Var(x) → id.lookup-local(|x).type |[ f (arg*) ]| → id.lookup-function(|f, arg*).type ... Reference attributes [Hedin 2000] look up declaration nodes var x : Int;
  • 20. Type Analysis with Aster: Using Decorators (1) Lookup decorators require: • Lookup type (ordered, unordered, global, ...) • Tree nodes to fetch • Scoping definition def lookup-ordered(id.is-scope) lookup-local(|x): |[ var x : t ; ]| → id |[ x : t ]| → id
  • 21. Type Analysis with Aster: Using Decorators (2) Lookup decorators require: • Lookup type (ordered, unordered, global, ...) • Tree nodes to fetch • Scoping definition def is-scope: |[ { s* } ]| → id |[ function x(param*) : t { stm* } ]| → id ...
  • 22. Type Analysis with Aster: Using Decorators (3) def lookup-unordered(id.is-scope) lookup-function(|x, arg*): |[ function x (param*) : t { stm* } ]| → id where argtype* := arg*.map(id.type); paramtype* := param*.map(id.type); paramtype*.eq(|argtype*)
  • 23. Type Analysis with Aster: Decorator Definitions decorator down lookup-ordered(a, is-s) = function x() : Int { if a then var j : Int; a Decorator stacking ... else } id.prev-sibling(id.lookup-inside(a, is-s)) end function y() : Int { if (true) { decorator lookup-inside(a, is-scope) = var i : Int; if a then } a return j; else if not(is-scope) then } // enter preceding subtrees id.child(id.lookup-inside(a, is-scope)) end
  • 24. Error Reporting Using Decorators def errors: module Constraints |[ while (e) s ]| → "Condition must be of type Boolean" where not(e.type  BoolType) ... module Reporting def collect-all add-error-context errors Decorator stacking decorator add-error-context(a) = <conc-strings > (a," at ", id.pp, " in ", id.file, ":", id.linenumber)
  • 25. Control-flow Analysis (1) def default(id.default-succ) succ: |[ if (e) s1 else s2 ]| → [s1, s2] |[ return e ; ]| → [] |[ { s1; s* } ]| → [s1] ... decorator default(a, default) = if a.defined then a else default end
  • 26. Control-flow Analysis (2) def down default-succ: Program(_) → [] [s1, s2 | _ ].s1 → [s2] ...
  • 27. “But Wait, There's More!” • Data-flow analysis • reaching definitions, liveness, ... • data-flow equations as attribute equations • circular (fixed point) attribute evaluation • Deriving the reverse control flow // Statement copies itself to successors def contributes-to(id.succ) pred: stm → id
  • 28. Go Figures! • Syntax: 3 modules 341 lines • Compiler: 25 modules 2831 lines • Library: 25 modules 1845 lines • Tests: 33 modules 1531 lines Total: 86 modules 6548 lines
  • 29. Concluding Remarks • Language growth in the hands of the users • decorators implement automatic copy rules, self rules, collection attributes, circular attributes, ... • Combine generic behavior with (simple) reflection • Future: • Library, language extension • IDE integration Decorated Attribute Grammars. Attribute Evaluation Meets Strategic Programming. Lennart C. L. Kats, Anthony M. Sloane, and Eelco Visser. 18th International Conference on Compiler Construction (CC 2009). http://www.strategoxt.org/Stratego/Aster