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

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

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