|
You can modify the original grammar to insert the implicit operator precedence. I will use BNF style below. Instead of defining a rule for an expression using all the operators, we could do:
level1expression: level2expression
| level2expression '+' level1expression
| level2expression '-' level1expression
level2expression: term
| term '*' level2expression
| term '/' level2expression
term: integerConstant | ......
Now, given the input "2 + 5 * 3", we would see that "2 + " matches the level1expression rule, but the right-hand side of the '+' is a level2expression "5 * 3". We would descend to the code to parse the level2expression "5 * 3" before we complete the parsing of the "2 + ...".
|