3.1 pyggy

The pyggy module is the container for the entire PyGgy and PyLly package. Importing this module loads in the ``simple'' API. This API consists of a number of utility functions and exception classes.

pyggy.generate( fname, targ, debug=0, forcgen=0)
This function takes in filenames specifying a specification file and an output file name. If the output file does not exist or is older than the specification file, it processes the specification file and generates tables into the target file. The input specification must be a .pyl or .pyg file. If the debug argument is specified, increased debugging information is emitted while processing the spec file. For a description of the debug levels see the documentation on the pyggy.pyggy and pyggy.pylly modules. If forcegen is true, the specification file is processed whether or not it is newer than the target file.

If an invalid specification file is specified, pyggy.ApiError is raised. Any exception raised by pyggy.pyggy.parsespec or pyggy.pylly.parsespec may also be raised.

pyggy.getlexer( specfname, debug=0, forcegen=0)
This function generates a lexer table module from a lexer spec file, imports the module and returns a pyggy.lexer.lexer instance and the module. The arguments debug and forcegen have the same meaning as in the generate function.

This function can raise any of the exceptions raised by generate.

pyggy.getparser( specfname, debug=0, forcegen=0)
This function generates a parser table module from a parser spec file, imports the module and returns a pyggy.glr.GLR instance and the module. The arguments debug and forcegen have the same meaning as in the generate function.

This function can raise any of the exceptions raised by generate.

pyggy.proctree( t, gram, allowambig=0)
This function post-processes a parse tree previously returned from a call to a parse method. It takes as arguments the parse tree and the module containing the parse tables. The optional argument allowambig is used to specify that ambiguous parses are allowed, otherwise a pyggy.AmbigParseError is raised if any ambiguities are encountered in the parse tree.

The function walks the parse tree in a bottom-up fashion executing the semantic action code for each production used in the derivation. For each action executed, the list of the values from the right hand side of the production are passed in. These values are either from the value fields of tokens, or the values previously returned by other action code functions. If ambiguous parses are disallowed, each right hand side element is represented by the element's unique value. In the case that ambiguous parses are allowed and an ambiguity is found in the parse tree, the ambiguous right hand side element will be represented with a pyggy.glr.symnode instance whose possibilities field is a list of the alternate values.

The proctree function returns the value associated with the start symbol which is at the root of the parse tree.

This function may raise pyggy.AmbigParseError if an ambiguous parse is detected or pyggy.ApiError if an invalid tree is passed in. This function alters the parse tree as it operates on it.

exception pyggy.Error
A superclass of all PyGgy generated exceptions.

exception pyggy.InternalError
An error in the inner workings of PyGgy or PyLly. This is a type of pyggy.Error.

exception pyggy.ApiError
This error specifies that there is an error in the way that PyGgy or PyLly is being used. This is a type of pyggy.Error.

exception pyggy.LexError
This error specifies that there was an error while lexing an input source. This exception is not currently used since the lexer currently returns an error token on errors. This exception is a type of pyggy.Error.

exception pyggy.ParseError( str, tok)
This error specifies that an error occured during the parsing of a token stream. It stores a description of the error in str and the token that caused the error in tok. This exception is a type of pyggy.Error.

exception pyggy.AmbigParseError
This error specifies that an ambiguity was present in a parse tree when ambiguities are disallowed. It is a type of pyggy.ApiError.

See the PyGgy Home Page.