71
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

From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

From Object Algebrasto Attribute Grammars

Tillmann Rendel · Jonathan Brachthäuser · Klaus OstermannUniversity of Marburg · University of Tübingen

http://www.informatik.uni-marburg.de/~rendel/oa2ag

Presentation by Tillmann Rendel at the International Conferenceon Object-Oriented Programming, Systems, Languages, and ApplicationsPortland, Oregon, October 23, 2014

Page 2: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Tree Traversals

1/15

Page 3: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Tree Traversals

1/15

Page 4: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Tree Traversals

How to structurea programthat containsmultiple traversalsof complex trees?

1/15

Page 5: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Visitor Patternin object-oriented programming

Folds & Traversal Schemesin functional programming

Church Encodingin theoretical work

Attribute Grammarsfor compiler construction

2/15

Page 6: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Visitor Patternin object-oriented programming

Folds & Traversal Schemesin functional programming

Church Encodingin theoretical work

Attribute Grammarsfor compiler construction

Hinze (2006)

Chirica & Martin (1979) Johnsson (1987)

Gibbons (2006)

Buchlovsky & Thielecke (2006) Oliveira et al. (2008)Oliveira et al. (2013)

Middelkoop et al. (2011)

2/15

Page 7: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Visitor Patternin object-oriented programming

Folds & Traversal Schemesin functional programming

Church Encodingin theoretical work

Attribute Grammarsfor compiler construction

Hinze (2006)

Chirica & Martin (1979) Johnsson (1987)

Gibbons (2006)

Buchlovsky & Thielecke (2006) Oliveira et al. (2008)Oliveira et al. (2013)

this paper

Middelkoop et al. (2011)

2/15

Page 8: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Visitor Patternin object-oriented programming

Folds & Traversal Schemesin functional programming

Church Encodingin theoretical work

Object Algebrasin Scala

Attribute Grammarsfor compiler construction

Hinze (2006)

Chirica & Martin (1979) Johnsson (1987)

Gibbons (2006)

Buchlovsky & Thielecke (2006) Oliveira et al. (2008)Oliveira et al. (2013)

this paper

Middelkoop et al. (2011)

2/15

Page 9: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Bottom-Up Data Flow

3/15

Page 10: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 11: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 12: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 13: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 14: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 15: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 16: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 17: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 18: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 19: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Synthesized Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Lit: Int ⇒ E def Add: (E, E) ⇒ E}

Equationse0.value = ne1 .value = e2.value + e3.value

Algebraval Alg = new Sig[Int] { def Lit = n ⇒ n def Add = (e2, e3) ⇒ e2 + e3}

4/15

Page 20: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Top-Down Data Flow

5/15

Page 21: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Inherited Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Add1: E ⇒ E def Add2: (E, E) ⇒ E}

Equationse2 .left = truee3 .left = false

Algebraval Alg = new Sig[Bool] { def Add1 = e ⇒ true def Add2 = (e1, e2) ⇒ false}

6/15

Page 22: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Inherited Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Add1: E ⇒ E def Add2: (E, E) ⇒ E}

Equationse2 .left = truee3 .left = false

Algebraval Alg = new Sig[Bool] { def Add1 = e ⇒ true def Add2 = (e1, e2) ⇒ false}

6/15

Page 23: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Inherited Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Add1: E ⇒ E def Add2: (E, E) ⇒ E}

Equationse2 .left = truee3 .left = false

Algebraval Alg = new Sig[Bool] { def Add1 = e ⇒ true def Add2 = (e1, e2) ⇒ false}

6/15

Page 24: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Inherited Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Add1: E ⇒ E def Add2: (E, E) ⇒ E}

Equationse2 .left = truee3 .left = false

Algebraval Alg = new Sig[Bool] { def Add1 = e ⇒ true def Add2 = (e1, e2) ⇒ false}

6/15

Page 25: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Inherited Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Add1: E ⇒ E def Add2: (E, E) ⇒ E}

Equationse2 .left = truee3 .left = false

Algebraval Alg = new Sig[Bool] { def Add1 = e ⇒ true def Add2 = (e1, e2) ⇒ false}

6/15

Page 26: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Inherited Attributes

Grammare0 → n { Lit }e1 → e2 "+" e3 { Add }

Signaturetrait Sig[E] { def Add1: E ⇒ E def Add2: (E, E) ⇒ E}

Equationse2 .left = truee3 .left = false

Algebraval Alg = new Sig[Bool] { def Add1 = e ⇒ true def Add2 = (e1, e2) ⇒ false}

6/15

Page 27: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Composition

7/15

Page 28: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Composition

compose

7/15

Page 29: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Composition

compose

7/15

Page 30: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Composition

assemble

7/15

Page 31: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 32: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 33: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 34: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 35: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 36: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 37: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 38: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

current node

Page 39: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

current node

children

Page 40: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

current node

context fromparent

Page 41: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

current node

Page 42: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 43: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 44: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Extensible Recordstrait HasValue { def value: Int }trait HasLeft { def left: Bool }def mix[A, B]: (A, B) ⇒ A with B

Dependency Trackingtrait Sig[-E, -C, +O] { def Lit: Int ⇒ C ⇒ O def Add: (E, E) ⇒ C ⇒ O}

8/15

Page 45: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 46: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 47: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 48: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 49: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 50: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 51: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 52: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

compose( , ) =

Composing two algebrasdef compose [E1, C1, O1, E2, C2 >: C1 with O1, O2] (alg1: Sig[E1, C1, O1], alg2: Sig[E2, C2, O2]): Sig[E1 with E2, C1, O1 with O2]

9/15

Page 53: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Assembling a one-pass traversaldef assemble [C, O] (alg1: Sig1[C with O, C, O], alg2: Sig2[C with O, C, C]): Sig[C ⇒ C with O]

assemble( , ) =

10/15

Page 54: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Assembling a one-pass traversaldef assemble [C, O] (alg1: Sig1[C with O, C, O], alg2: Sig2[C with O, C, C]): Sig[C ⇒ C with O]

assemble( , ) =

10/15

Page 55: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Assembling a one-pass traversaldef assemble [C, O] (alg1: Sig1[C with O, C, O], alg2: Sig2[C with O, C, C]): Sig[C ⇒ C with O]

assemble( , ) =

10/15

Page 56: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Assembling a one-pass traversaldef assemble [C, O] (alg1: Sig1[C with O, C, O], alg2: Sig2[C with O, C, C]): Sig[C ⇒ C with O]

assemble( , ) =

10/15

Page 57: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Assembling a one-pass traversaldef assemble [C, O] (alg1: Sig1[C with O, C, O], alg2: Sig2[C with O, C, C]): Sig[C ⇒ C with O]

assemble( , ) =

10/15

Page 58: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Results

Object algebras correspondto synthesized attributes(bottom-up data-flow)

We extend object algebrasto support inherited attributes(top-down data flow)

We assemble multiple algebrasto support L-attributed grammars(arbitrary one-pass compiler)

11/15

Page 59: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Results

Object algebras correspondto synthesized attributes(bottom-up data-flow)

We extend object algebrasto support inherited attributes(top-down data flow)

We assemble multiple algebrasto support L-attributed grammars(arbitrary one-pass compiler)

11/15

Page 60: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Results

Object algebras correspondto synthesized attributes(bottom-up data-flow)

We extend object algebrasto support inherited attributes(top-down data flow)

We assemble multiple algebrasto support L-attributed grammars(arbitrary one-pass compiler)

11/15

Page 61: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

11/15

Results

Object algebras correspondto synthesized attributes(bottom-up data-flow)

We extend object algebrasto support inherited attributes(top-down data flow)

We assemble multiple algebrasto support L-attributed grammars(arbitrary one-pass compiler)

Page 62: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Modularizing a One-Pass Compiler

● existing one-pass compiler for a subset of C● 9 nonterminals● written for teaching at Aarhus university

(not by the authors of the present paper)

12/15

Page 63: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Monolithic compiler1 file807 lines of Java codeentangled

Modularized compilerca. 25 files1620 lines of Scala codemodular

13/15

Page 64: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Properties of the Encoding

ModularAttributes are defined and type-checked separately

ScalableScala code size is linear in AG specification size.

CompositionalEach AG artifact is represented as a Scala value.

14/15

Page 65: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Properties of the Encoding

ModularAttributes are defined and type-checked separately

ScalableScala code size is linear in AG specification size.

CompositionalEach AG artifact is represented as a Scala value.

14/15

Page 66: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Properties of the Encoding

ModularAttributes are defined and type-checked separately

ScalableScala code size is linear in AG specification size.

CompositionalEach AG artifact is represented as a Scala value.

14/15

Page 67: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Properties of the Encoding

ModularAttributes are defined and type-checked separately

ScalableScala code size is linear in AG specification size

CompositionalEach AG artifact is represented as a Scala value.

14/15

Page 68: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Conclusions

Object Algebrasin Scala

Attribute Grammarsfor compiler construction

Rendel et al. (2014)

15/15

Page 69: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Conclusions

Object Algebrasin Scala

Benefits for OA

● Support forinherited attributes

● Access toextensive AG research

● Future work:encode more AG features

Attribute Grammarsfor compiler construction

Rendel et al. (2014)

15/15

Page 70: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Conclusions

Object Algebrasin Scala

Benefits for OA

● Support forinherited attributes

● Access toextensive AG research

● Future work:encode more AG features

Attribute Grammarsfor compiler construction

Benefits for AG

● Modular, scalable, and compositional encoding

● Embedding enablesabstraction via meta language

● Future work:AG compiler to object algebras

Rendel et al. (2014)

15/15

Page 71: From Object Algebras to Attribute Grammarsps.informatik.uni-tuebingen.de/2014/10/23/... · 10/23/2014  · Presentation by Tillmann Rendel at the International Conference on Object-Oriented

Conclusions

Object Algebrasin Scala

Benefits for OA

● Support forinherited attributes

● Access toextensive AG research

● Future work:encode more AG features

Attribute Grammarsfor compiler construction

Benefits for AG

● Modular, scalable, and compositional encoding

● Embedding enablesabstraction via meta language

● Future work:AG compiler to object algebras

Rendel et al. (2014)

Thank You!