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

Module rdparser

source code

A graphical tool for exploring the recursive descent parser.

The recursive descent parser maintains a tree, which records the structure of the portion of the text that has been parsed. It uses CFG productions to expand the fringe of the tree, and matches its leaves against the text. Initially, the tree contains the start symbol ("S"). It is shown in the main canvas, to the right of the list of available expansions.

The parser builds up a tree structure for the text using three operations:

The parser maintains a list of tree locations called a "frontier" to remember which nodes have not yet been expanded and which leaves have not yet been matched against the text. The leftmost frontier node is shown in green, and the other frontier nodes are shown in blue. The parser always performs expand and match operations on the leftmost element of the frontier.

You can control the parser's operation by using the "expand," "match," and "backtrack" 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 "expand" button applies the untried expansion whose CFG production is listed earliest in the grammar. To manually choose which expansion to apply, click on a CFG production from the list of available expansions, on the left side of the main window.

The "autostep" button will let the parser continue applying applications to the tree until it reaches a complete parse. You can cancel an autostep in progress at any time by clicking on the "autostep" button again.

Keyboard Shortcuts:

     [Space]    Perform the next expand, match, or backtrack operation
     [a]        Step through operations until the next complete parse
     [e]        Perform an expand operation
     [m]        Perform a match operation
     [b]        Perform a backtrack operation
     [Delete]   Reset the parser
     [g]        Show/hide available expansions list
     [h]        Help
     [Ctrl-p]   Print
     [q]        Quit
Classes [hide private]
  RecursiveDescentDemo
A graphical tool for exploring the recursive descent parser.
Functions [hide private]
 
demo()
Create a recursive descent parser demo, using a simple grammar and text.
source code