Attribute Grammars for Modular Disambiguation Valentin David 1 Akim - - PowerPoint PPT Presentation

attribute grammars for modular disambiguation
SMART_READER_LITE
LIVE PREVIEW

Attribute Grammars for Modular Disambiguation Valentin David 1 Akim - - PowerPoint PPT Presentation

Attribute Grammars for Modular Disambiguation Valentin David 1 Akim Demaille 2 Olivier Gournet 2 1 Bergen University Norway 2 EPITA Research and Development Laboratory (LRDE) France International Conference on Intelligent Computer


slide-1
SLIDE 1

Attribute Grammars for Modular Disambiguation

Valentin David1 Akim Demaille2 Olivier Gournet2

1Bergen University — Norway 2EPITA Research and Development Laboratory (LRDE) — France

International Conference on Intelligent Computer Communication and Processing 2006

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 1 / 25

slide-2
SLIDE 2

Attribute Grammars for Modular Disambiguation

1

Modular Front-Ends

2

Attribute Grammars for Disambiguation

3

Conclusion

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 2 / 25

slide-3
SLIDE 3

Language Extensions

domain specific extensions [4] embedded SQL design by contract (pre-/post-conditions) [1] syntactic sugar [5, 7] language evolution prototyping etc. and composition of them!

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 3 / 25

slide-4
SLIDE 4

Language Extensions

domain specific extensions [4] embedded SQL design by contract (pre-/post-conditions) [1] syntactic sugar [5, 7] language evolution prototyping etc. and composition of them!

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 3 / 25

slide-5
SLIDE 5

Language Extensions

domain specific extensions [4] embedded SQL design by contract (pre-/post-conditions) [1] syntactic sugar [5, 7] language evolution prototyping etc. and composition of them!

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 3 / 25

slide-6
SLIDE 6

Language Extensions

domain specific extensions [4] embedded SQL design by contract (pre-/post-conditions) [1] syntactic sugar [5, 7] language evolution prototyping etc. and composition of them!

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 3 / 25

slide-7
SLIDE 7

C/C++ Have Bad Syntactic Properties

What’s this?

a * b;

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 4 / 25

slide-8
SLIDE 8

C/C++ Have Bad Syntactic Properties

What’s this?

a * b;

A value product

int a, b; a * b;

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 4 / 25

slide-9
SLIDE 9

C/C++ Have Bad Syntactic Properties

What’s this?

a * b;

A value product

int a, b; a * b;

A variable declaration

typedef int a; a * b;

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 4 / 25

slide-10
SLIDE 10

C/C++ Have Bad Syntactic Properties

What’s this?

(a) - (b);

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 5 / 25

slide-11
SLIDE 11

C/C++ Have Bad Syntactic Properties

What’s this?

(a) - (b);

A subtraction

int a, b; (a) - (b);

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 5 / 25

slide-12
SLIDE 12

C/C++ Have Bad Syntactic Properties

What’s this?

(a) - (b);

A subtraction

int a, b; (a) - (b);

A cast

typedef int a; (a) - (b);

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 5 / 25

slide-13
SLIDE 13

Modular Parser Generation

To overcome context sensitivity, use “lexical tie-ins” [6] Use LALR(1) generators Use LR(1) generators None of these techniques is closed under union! So use GLR [10, 11]

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 6 / 25

slide-14
SLIDE 14

Modular Parser Generation

To overcome context sensitivity, use “lexical tie-ins” [6] Use LALR(1) generators Use LR(1) generators None of these techniques is closed under union! So use GLR [10, 11]

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 6 / 25

slide-15
SLIDE 15

Modular Parser Generation

To overcome context sensitivity, use “lexical tie-ins” [6] Use LALR(1) generators Use LR(1) generators None of these techniques is closed under union! So use GLR [10, 11]

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 6 / 25

slide-16
SLIDE 16

Modular Parser Generation

To overcome context sensitivity, use “lexical tie-ins” [6] Use LALR(1) generators Use LR(1) generators None of these techniques is closed under union! So use GLR [10, 11]

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 6 / 25

slide-17
SLIDE 17

Generalized LR Parsing

accepts the full class of context-free languages including ambiguous grammars so accept a superset of context-sensitive languages and filter the resulting “parse-forest”

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 7 / 25

slide-18
SLIDE 18

Generalized LR Parsing

accepts the full class of context-free languages including ambiguous grammars so accept a superset of context-sensitive languages and filter the resulting “parse-forest”

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 7 / 25

slide-19
SLIDE 19

Generalized LR Parsing

accepts the full class of context-free languages including ambiguous grammars so accept a superset of context-sensitive languages and filter the resulting “parse-forest”

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 7 / 25

slide-20
SLIDE 20

The Big Picture

SGLR parser C source Parse forest Parse tree AST Transformations AST Pretty printer C source Standard C compiler Concrete syntax to abstract syntax Disambiguation

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 8 / 25

slide-21
SLIDE 21

The Big Picture

SGLR parser C source Parse forest Parse tree AST Transformations AST Pretty printer C source Standard C compiler Concrete syntax to abstract syntax Disambiguation

Need for modular disambiguation.

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 8 / 25

slide-22
SLIDE 22

Attribute Grammars for Modular Disambiguation

1

Modular Front-Ends

2

Attribute Grammars for Disambiguation

3

Conclusion

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 9 / 25

slide-23
SLIDE 23

A Simple Ambiguous Grammar

context -free syntax "true"

  • > Bool

"false"

  • > Bool

Bool "|" Bool

  • > Bool

Figure: Boolean Expressions (Ambiguous) [3]

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 10 / 25

slide-24
SLIDE 24

Parse Forest for true | true | true

Bool Bool | Bool Bool | true true true Bool Bool Bool | Bool Bool | true true true Bool

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 11 / 25

slide-25
SLIDE 25

Techniques for Disambiguation

Dedicated Code Poor modularity, more imperative, less declarative Algebraic Specification [2] Modular, declarative, too hard to use Attribute Grammars (AGs) [9] Modular, declarative, easy to use

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 12 / 25

slide-26
SLIDE 26

Techniques for Disambiguation

Dedicated Code Poor modularity, more imperative, less declarative Algebraic Specification [2] Modular, declarative, too hard to use Attribute Grammars (AGs) [9] Modular, declarative, easy to use

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 12 / 25

slide-27
SLIDE 27

Techniques for Disambiguation

Dedicated Code Poor modularity, more imperative, less declarative Algebraic Specification [2] Modular, declarative, too hard to use Attribute Grammars (AGs) [9] Modular, declarative, easy to use

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 12 / 25

slide-28
SLIDE 28

A Simple AG Example

context -free syntax "true" | "false"

  • > Bool

{attributes (assoc: root.is_atomic := true )} lhs:Bool "|" rhs:Bool -> Bool {attributes (assoc: root.is_atomic := false root.ok := rhs.is_atomic )}

Figure: Boolean Expressions Disambiguated

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 13 / 25

slide-29
SLIDE 29

Disambiguated Parse Forest

Bool Bool | Bool Bool | true true true Bool Bool Bool | Bool Bool | true true true Bool

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 14 / 25

slide-30
SLIDE 30

Application to ISO C99 [8]

126 symbols 356 rules 53 modules 10 attribute kinds 190 attribute rules completed to 1183 rules

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 15 / 25

slide-31
SLIDE 31

Application to ISO C99 [8]

126 symbols 356 rules 53 modules 10 attribute kinds 190 attribute rules completed to 1183 rules

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 15 / 25

slide-32
SLIDE 32

Application to ISO C99 [8]

126 symbols 356 rules 53 modules 10 attribute kinds 190 attribute rules completed to 1183 rules

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 15 / 25

slide-33
SLIDE 33

C Disambiguation

HelloW Lemon Eval Lines of code 448 4 135 28 392 Ambiguities 103 6 410 68 195 Duration (s) 3.8 28.0 322.5

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 16 / 25

slide-34
SLIDE 34

Attribute Grammars for Modular Disambiguation

1

Modular Front-Ends

2

Attribute Grammars for Disambiguation

3

Conclusion

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 17 / 25

slide-35
SLIDE 35

Attribute Grammars for Modular Disambiguation

Pros

Declarativity Modularity Simplicity

Cons

Slow Hard to debug Poor genericity External data

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 18 / 25

slide-36
SLIDE 36

Attribute Grammars for Modular Disambiguation

Pros

Declarativity Modularity Simplicity

Cons

Slow Hard to debug Poor genericity External data

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 18 / 25

slide-37
SLIDE 37

Future Work

Completion of C++ tool-chain Various C++ syntactic sugar Parse time disambiguation

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 19 / 25

slide-38
SLIDE 38

Future Work

Completion of C++ tool-chain Various C++ syntactic sugar Parse time disambiguation

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 19 / 25

slide-39
SLIDE 39

Future Work

Completion of C++ tool-chain Various C++ syntactic sugar Parse time disambiguation

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 19 / 25

slide-40
SLIDE 40

Attribute Grammars for Modular Disambiguation

Questions?

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 20 / 25

slide-41
SLIDE 41

Bibliography I

Alexandre Borghi, Valentin David, and Akim Demaille. C-transformers - a framework to write C program transformations. ACM Crossroads, 12(3), Spring 2006. http://www.acm.org/crossroads/xrds12-3/contractc.html. Mark van den Brand, A. van Deursen, J. Heering, H. de Jonge, M. de Jonge, T. Kuipers, P. Klint, L. Moonen, P. Olivier, J. Scheerder,

  • J. Vinju, E. Visser, and J. Visser.

The ASF+SDF Meta-Environment: a component-based language development environment. In R. Wilhelm, editor, Compiler Construction 2001 (CC’2001), volume 2027 of LNCS, pages 365 – 370. Springer-Verlag, 2001.

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 21 / 25

slide-42
SLIDE 42

Bibliography II

Mark van den Brand, Steven Klusener, Leon Moonen, and Jurgen J. Vinju. Generalized parsing and term rewriting: Semantics driven disambiguation. volume 82 of Electronic Notes in Theoretical Computer Science. Elsevier Science Publishers, 2003. Martin Bravenboer, Ren´ e de Groot, and Eelco Visser. Metaborg in action: Examples of domain-specific language embedding and assimilation using Stratego/XT. In Proceedings of the Summer School on Generative and Transformational Techniques in Software Engineering (GTTSE’05), Braga, Portugal, July 2005.

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 22 / 25

slide-43
SLIDE 43

Bibliography III

Nicolas Burrus, Alexandre Duret-Lutz, Thierry G´ eraud, David Lesage, and Rapha¨ el Poss. A static C++ object-oriented programming (SCOOP) paradigm mixing benefits of traditional OOP and generic programming. In Proceedings of the Workshop on Multiple Paradigm with OO Languages (MPOOL), Anaheim, CA, USA, October 2003. Robert Corbett, Richard Stallman, and Paul Hilfinger. Bison: GNU LALR(1) and GLR parser generator, 2003. http://www.gnu.org/software/bison/bison.html.

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 23 / 25

slide-44
SLIDE 44

Bibliography IV

Akim Demaille, Sylvain Peyronnet, and Benoˆ ıt Sigoure. Modeling of sensor networks using XRM. In Proceedings of the 2nd International Symposium on Leveraging Applications of Formal Methods, Verification and Validation (ISOLA’06), Coral Beach Resort, Paphos, Cyprus, November 2006. Accepted. ISO/IEC. ISO/IEC 14882:2003 (E). Programming languages - C++, 2003. Donald E. Knuth. Semantics of context-free languages. Journal of Mathematical System Theory, pages 127–145, 1968.

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 24 / 25

slide-45
SLIDE 45

Bibliography V

Masaru Tomita. Efficient Parsing for Natural Language: A Fast Algorithm for Practical Systems. Kluwer Academic Publishers, 1985. Eelco Visser. Scannerless generalized-LR parsing. Technical Report P9707, Programming Research Group, University of Amsterdam, July 1997.

  • V. David et al. (Bergen U. & LRDE)

AGs for Disambiguation ICCP’06 25 / 25