from object algebras to attribute grammars
play

From Object Algebras to Attribute Grammars Tillmann Rendel Jonathan - PowerPoint PPT Presentation

From Object Algebras to Attribute Grammars Tillmann Rendel Jonathan Brachthuser Klaus Ostermann University of Marburg University of Tbingen http://www.informatik.uni-marburg.de/~rendel/oa2ag Presentation by Tillmann Rendel at the


  1. From Object Algebras to Attribute Grammars Tillmann Rendel · Jonathan Brachthäuser · Klaus Ostermann University of Marburg · University of Tübingen http://www.informatik.uni-marburg.de/~rendel/oa2ag Presentation by Tillmann Rendel at the International Conference on Object-Oriented Programming, Systems, Languages, and Applications Portland, Oregon, October 23, 2014

  2. Tree Traversals 1/15

  3. Tree Traversals 1/15

  4. Tree Traversals How to structure a program that contains multiple traversals of complex trees? 1/15

  5. Folds & Traversal Schemes in functional programming Visitor Pattern in object-oriented programming Church Encoding in theoretical work Attribute Grammars for compiler construction 2/15

  6. Gibbons (2006) Folds & Traversal Schemes in functional programming Visitor Pattern in object-oriented programming Hinze (2006) Middelkoop Buchlovsky & et al. (2011) Thielecke (2006) Oliveira et al . (2008) Oliveira et al. (2013) Chirica & Martin (1979) Johnsson (1987) Church Encoding in theoretical work Attribute Grammars for compiler construction 2/15

  7. Gibbons (2006) Folds & Traversal Schemes in functional programming Visitor Pattern in object-oriented programming Hinze (2006) Middelkoop Buchlovsky & et al. (2011) Thielecke (2006) Oliveira et al . (2008) Oliveira et al. (2013) Chirica & Martin (1979) Johnsson (1987) Church Encoding in theoretical work Attribute Grammars for compiler construction this paper 2/15

  8. Gibbons (2006) Folds & Traversal Schemes in functional programming Visitor Pattern in object-oriented programming Hinze (2006) Middelkoop Buchlovsky & et al. (2011) Thielecke (2006) Oliveira et al . (2008) Oliveira et al. (2013) Chirica & Martin (1979) Johnsson (1987) Church Encoding in theoretical work Attribute Grammars Object Algebras for compiler construction in Scala this paper 2/15

  9. Bottom-Up Data Flow 3/15

  10. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  11. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  12. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  13. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  14. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  15. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  16. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  17. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  18. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  19. Synthesized Attributes Grammar Equations e 0 → n { Lit } e 0. value = n e 1 → e 2 "+" e 3 { Add } e 1 .value = e 2 .value + e 3 .value Signature Algebra trait Sig[ E ] { val Alg = new Sig[Int] { ⇒ E def Lit = n ⇒ n def Lit: Int def Add: ( E , E ) ⇒ E def Add = ( e 2 , e 3 ) ⇒ e 2 + e 3 } } 4/15

  20. Top-Down Data Flow 5/15

  21. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ true def Add 1 : E def Add 2 : ( E , E ) ⇒ E def Add 2 = ( e 1 , e 2 ) ⇒ false } } 6/15

  22. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ true def Add 1 : E def Add 2 : ( E , E ) ⇒ E def Add 2 = ( e 1 , e 2 ) ⇒ false } } 6/15

  23. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ true def Add 1 : E def Add 2 : ( E , E ) ⇒ E def Add 2 = ( e 1 , e 2 ) ⇒ false } } 6/15

  24. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ true def Add 1 : E def Add 2 : ( E , E ) ⇒ E def Add 2 = ( e 1 , e 2 ) ⇒ false } } 6/15

  25. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ true def Add 1 : E def Add 2 : ( E , E ) ⇒ E def Add 2 = ( e 1 , e 2 ) ⇒ false } } 6/15

  26. Inherited Attributes Grammar Equations e 0 → n { Lit } e 2 . left = true e 1 → e 2 "+" e 3 { Add } e 3 .left = false Signature Algebra trait Sig[ E ] { val Alg = new Sig[Bool] { ⇒ E def Add 1 = e ⇒ true def Add 1 : E def Add 2 : ( E , E ) ⇒ E def Add 2 = ( e 1 , e 2 ) ⇒ false } } 6/15

  27. Composition 7/15

  28. Composition compose 7/15

  29. Composition compose 7/15

  30. Composition assemble 7/15

  31. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]: ( A , B ) ⇒ A with B Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ O def Lit: Int def Add: ( E , E ) ⇒ C ⇒ O } 8/15

  32. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]: ( A , B ) ⇒ A with B Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ O def Lit: Int def Add: ( E , E ) ⇒ C ⇒ O } 8/15

  33. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]: ( A , B ) ⇒ A with B Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ O def Lit: Int def Add: ( E , E ) ⇒ C ⇒ O } 8/15

  34. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]: ( A , B ) ⇒ A with B Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ O def Lit: Int def Add: ( E , E ) ⇒ C ⇒ O } 8/15

  35. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]: ( A , B ) ⇒ A with B Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ O def Lit: Int def Add: ( E , E ) ⇒ C ⇒ O } 8/15

  36. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]: ( A , B ) ⇒ A with B Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ O def Lit: Int def Add: ( E , E ) ⇒ C ⇒ O } 8/15

  37. compose( , ) = Extensible Records trait HasValue { def value: Int } trait HasLeft { def left: Bool } def mix[ A , B ]: ( A , B ) ⇒ A with B Dependency Tracking trait Sig[- E , - C , + O ] { ⇒ C ⇒ O def Lit: Int def Add: ( E , E ) ⇒ C ⇒ O } 8/15

Recommend


More recommend