Syntax analysis
Shift-Reduce Parsing
Parse a token string bottom-up with the LR(1) table of a grammar: the shift-reduce trace with its divider, the parse tree growing over the tokens, and the handle of every reduction.
- Lecture reference: Bottom-Up Parsing
- Lecture reference: Bottom-up Parsing II
Terminals of the grammar, separated by spaces. The $ at the end may be left out.
Open in LR(1) Parser Builder, LL(1) Parsing Table or Conflicts & Precedence
Lecture reference: Bottom-up Parsing II
The shift-reduce example: E → E + ( E ) | int on int + (int) + (int)$. Each row is a configuration, the stack left of the divider and the input right of it, with the action taken on it; consecutive shifts are on one row.
Accepted: 9 tokens, 12 LR(1) states.
Row 11 of 11
State 2 is labeled “accept on $”, and the token after the divider is $: accept.
| Configuration | Action |
|---|---|
| divider to shift: int, end of shift + (int) + (int)$ | shift |
| handle: int, end of handle divider + (int) + (int)$ | red. E → int |
| E divider to shift: + (int, end of shift) + (int)$ | shift 3 times |
| E + (handle: int, end of handle divider ) + (int)$ | red. E → int |
| E + (E divider to shift: ), end of shift + (int)$ | shift |
| handle: E + (E), end of handle divider + (int)$ | red. E → E + (E) |
| E divider to shift: + (int, end of shift)$ | shift 3 times |
| E + (handle: int, end of handle divider )$ | red. E → int |
| E + (E divider to shift: ), end of shift$ | shift |
| handle: E + (E), end of handle divider $ | red. E → E + (E) |
| E divider $ | accept |