A graphical tool for exploring the shift-reduce parser.
The shift-reduce parser maintains a stack, which records the structure of the portion of the text that has been parsed. The stack is initially empty. Its contents are shown on the left side of the main canvas.
On the right side of the main canvas is the remaining text. This is the portion of the text which has not yet been considered by the parser.
The parser builds up a tree structure for the text using two operations:
“shift” moves the first token from the remaining text to the top of the stack. In the demo, the top of the stack is its right-hand side.
“reduce” uses a grammar production to combine the rightmost stack elements into a single tree token.
You can control the parser’s operation by using the “shift” and “reduce” buttons; or you can use the “step” button to let the parser automatically decide which operation to apply. The parser uses the following rules to decide which operation to apply:
Only shift if no reductions are available.
If multiple reductions are available, then apply the reduction whose CFG production is listed earliest in the grammar.
The “reduce” button applies the reduction whose CFG production is listed earliest in the grammar. There are two ways to manually choose which reduction to apply:
Click on a CFG production from the list of available reductions, on the left side of the main window. The reduction based on that production will be applied to the top of the stack.
Click on one of the stack elements. A popup window will appear, containing all available reductions. Select one, and it will be applied to the top of the stack.
Note that reductions can only be applied to the top of the stack.
- Keyboard Shortcuts::
[Space] Perform the next shift or reduce operation [s] Perform a shift operation [r] Perform a reduction operation [Ctrl-z] Undo most recent operation [Delete] Reset the parser [g] Show/hide available production list [Ctrl-a] Toggle animations [h] Help [Ctrl-p] Print [q] Quit
Create a shift reduce parser app, using a simple grammar and text.