3.4 pyggy.glr - The PyGgy parsing engine

This module implements the Generalized-LR parsing engine and provides the supporting data structures and helper functions.

Parse trees are composed of alternating levels of symnode and rulenode instances. The root of the parse tree is a symnode for the start symbol of the grammar.

class pyggy.glr.symnode( sym, possibilities, cover)
The symnode class is used to represent terminals and non-terminals in the parse tree while parsing. It's sym field is either a tuple of the token name and value for terminals or a non-terminal symbol. The possibilities field holds a list of all possible derivations of the current symbol. Each element in possibilities is a rulenode instance.

class pyggy.glr.rulenode( rule, elements, cover)
The rulenode class is used to represent a production used in the derivation. It's rule member specifies which production in the grammar the rulenode represents. It is a tuple of the left hand side symbol, a count of right hand side elements and the production number in the grammar. The elements member is a list of symnodes for the right hand side of the production.

pyggy.glr.dottree( tree, printcover=0)
This is a helper for visualizing a parse tree. It uses the dotty program to show a graphical representation of the parse tree tree. If printcover is true, the token positions each tree node covers is also displayed.

class pyggy.glr.GLR( gram)
The GLR class implements the GLR parsing engine. It takes in a single argument which is a pyggy.srgram.SRGram instance.

setlexer( lex)
Sets input to come from the lexer lex. This must be called before parsing is started.

parse( )
Parses the stream of tokens from the designated lexer and return a parse tree.

This method may raise pyggy.PaseError or pyggy.InternalError.

See the PyGgy Home Page.