The following rule does not construct a node in the abstract syntax tree:
<factor> ::= <unary> ; <unary>
but only passes along the result of subsequent instantiation
of the non-terminal
For example, production rules that treat all EXP operators at the same ``level:''
<exp> ::= <exp> "+" <exp> ; plus (<exp>.1, <exp>.2) <exp> ::= <exp> "-" <exp> ; minus (<exp>.1, <exp>.2) <exp> ::= <exp> "*" <exp> ; prod (<exp>.1, <exp>.2)
not only ignore conventional priorities, but render parsing ambiguous for equations such as:
1 - 2 - 3
which, unrestricted by the above equations, may be left associative:
- 3
or right associative:
1 -
To remove this ambiguity, we create a trivial non-terminal
named
We will examine other priority issues, including the
treatment of parentheses, in the section on pretty printing.
...
<exp> ::= <exp> "+" <factor> ;
plus (<exp>, <factor>)
<exp> ::= <exp> "-" <factor> ;
minus (<exp>, <factor>)
<exp> ::= <factor> ;
<factor>
<factor> ::= <factor> "*" <unary> ;
prod (<factor>, <unary>)
...