Signatures and grammars
- Why manual disambiguation in SDF?
y g
- Fully declarative definition of syntax
- Implicit disambiguation can be wrong
- More programming languages can be parsed
- More programming languages can be parsed
- Modularity
- Fewer non-terminals/sorts
- Separation of concerns: form of rules is independent of
disambiguation
- Costs?
- Intellectual effort
- False safety, grammar may still be ambiguous
/ Faculteit Wiskunde en Informatica
PAGE 0 20-9-2011
Signatures and grammars
- Associativity of binary operators
y y
- Priorities between binary operators
- Transitivity of priorities
- Prefix expressions and binary expressions
- Postfix expression with binary operator (slide 3+4)
- Overloaded comma’s in expression languages (slide
Overloaded comma s in expression languages (slide 5+6)
/ Faculteit Wiskunde en Informatica
PAGE 1 20-9-2011
Signatures and grammars
module Expressions exports sorts E lexical syntax [\ \t\n] -> LAYOUT context-free start-symbols E context-free syntax "e" -> E E "[" E "]" -> E E "+" E -> E {left} Input sentence: e + e [ e + e ]
/ Faculteit Wiskunde en Informatica
PAGE 2 20-9-2011
Signatures and grammars
module Expressions t
- The "< >" notation is used to
exports sorts E lexical syntax [\ \t\n] -> LAYOUT
restrict the filtering behavior
- f priorities to certain
arguments.
[\ \t\n] > LAYOUT context-free start-symbols E context-free syntax "e" -> E
- In this case, if a "+" is a direct
child of the first "E" in the "[ ]" production, it is filtered.
context-free priorities E "[" E "]" -> E <0> > E "+" E > E {l ft}
- No other direct children are
filtered but the ones listed between the angular brackets.
E "+" E -> E {left}
/ Faculteit Wiskunde en Informatica
PAGE 3 20-9-2011