SLIDE 4 Interpreting the javacup.dump file cont …
Transitions in the lalr_state transition table in javacup.dump
– (A alpha . X beta, z) – When X is a terminal, then will shift X and transition to another state. – When X is a non-terminal, then will goto another state once that non- terminal has been parsed via a reduction. – An item with the parsing dot at the end of the production – ( A gamma ., w) – Causes a reduction to the production A gamma when the next token in the input is w.
See how this works with the single nest parentheses example
CS453 Shift-reduce Parsing 13
Back to the Expression Grammar
Show the shift-reduce errors for this and what those errors look like in
the state transitions.
How can we use precedence to fix it?
CS453 Shift-reduce Parsing 14
Back to the Dangling Else Grammar
Try various approaches for fixing this.
CS453 Shift-reduce Parsing 15
Summary on Precedence and Associativity in JavaCUP
Tokens and productions are given precedence.
– Tokens are given precedence level in precedence declarations. – Productions are given precedence level of last operator on right-hand side,
When in shift-reduce conflict,
– shift if look ahead token has higher precedence than reduce production – reduce if reduce production has higher precedence than the look ahead token
Within the same precedence level associativity determines whether to shift
– left associativity results in a reduce – right associativity results in a shift
CS453 Shift-reduce Parsing 16