Associativity and Precedence

  • Productions that are left-recursive force evaluation in left-to-right order (left associativity)
  • Productions that are right-recursive for evaluation in right-to-left order (right associativity)
  • Precedence is introduced by adding new non-terminal symbols. Cascade symbols with lowest precedence closest to the start symbol.

Example:

  • Precedence: (), - (unary), $\uparrow$, *, /, +-
  • Associativity: left: */+-, right: $\uparrow$
expr ::= term | expr + term | expr - term
term ::= factor | term * factor | term / factor
factor ::= primary $\uparrow$ factor | primary
primary ::= - primary | element
element ::= x | y | z | ( expr )

Syntax Errors in Recursive Descent Parsing

Read Scott section 2.3.5 (in the online supplement) through Exception based errors. There are several approaches:

  • Halting - when an error is detected, just stop and print message
  • Syntax error recovery
    • Panic mode recovery
    • Phrase level recovery
    • Context specific
    • Exception based

We will use exception based error handling for our project. This seems to be the most common approach.