linkchecker/PyLR/tests/SimpleParser.py
2000-02-27 20:45:44 +00:00

94 lines
2.5 KiB
Python

"""
tests/SimpleParser.py -- created Sun Feb 27 20:24:57 2000
This file was automatically generated by the PyLR parser generator.
It defines the tables 'actiontable', 'gototable', and 'prodinfo'. These
tables are used to give functionality to a parsing engine. It also defines
A Parser class called SimpleParser which will use this engine. It's usage
is indicated in SimpleParser's doc-string.
"""
#
# this section contains source code added by the user
# plus 'import PyLR'
#
import SimpleLexer
import PyLR
#
# the action table means
# ('s', -1) shift
# ('r', <n>) reduce with production n
# ('a', -1) accept
# ('', -1) error
# each row represents a state and each column a terminal lookahead symbol
# Lexer symbols are:
# ['EOF', 'c', 'd']
#
_actiontable = [
[('', -1), ('s', 3), ('s', 4)],
[('a', -1), ('', -1), ('', -1)],
[('', -1), ('s', 3), ('s', 4)],
[('', -1), ('s', 3), ('s', 4)],
[('r', 3), ('r', 3), ('r', 3)],
[('r', 1), ('', -1), ('', -1)],
[('r', 2), ('r', 2), ('r', 2)]
]
#
# the goto table, each row represents a state
# and each column the nonterminal that was on the lhs of the
# reduction
#
_gototable = [
[1, 2, 2],
[None, None, None],
[None, 5, 5],
[None, 6, 6],
[None, None, None],
[None, None, None],
[None, None, None]
]
#
# This is the prodinfo table. each row represents a production
# the entries are the length of the production, the name of a method
# in an instance of the SimpleParser class below that gets called
# when that production occurs, and the index of the lhs in the
# nonterminals (as in the gototable)
#
_prodinfo = [
(2, 'unspecified', 0), # S: C C (unspecified)
(2, 'unspecified', 1), # C: 1 C (unspecified)
(1, 'unspecified', 1), # C: 2 (unspecified)
]
class SimpleParser(PyLR.Parser):
"""
this class was produced automatically by the PyLR parser generator.
It is meant to be subclassed to produce a parser for the grammar
S: C C (unspecified);
C: c C (unspecified);
C: d (unspecified);
While parsing input, if one of the above productions is recognized,
a method of your sub-class (whose name is indicated in parens to the
right) will be invoked. Names marked 'unspecified' should be ignored.
usage:
class MySimpleParser(SimpleParser):
# ...define the methods for the productions...
p = MySimpleParser(); p.parse(text)
"""
def __init__(self):
lexer = SimpleLexer.SimpleLexer()
PyLR.Parser.__init__(self, lexer, _actiontable, _gototable, _prodinfo)