Package nltk :: Package draw :: Module srparser
[hide private]
[frames] | no frames]

Module srparser

source code

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:

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:

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:

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
Classes [hide private]
  ShiftReduceDemo
A graphical tool for exploring the shift/reduce parser.
Functions [hide private]
 
demo()
Create a shift reduce parser demo, using a simple grammar and text.
source code