A grammar object is initialised by a nonempty sequence of productions,
and a start symbol. The start symbol is required and must equal the LHS
of at least one production.
An optional argument with keyword 'verbosity' defaults to 0,
and may be used to control the amount of debugging information output
during the initialisation process.
The sequence of productions is copied,
but the productions objects are not.
The constructor builds some tables of auxilliary information
about the grammar. After construction the following
attributes are defined:
symbols
The set of symbols used in the client grammar, excluding "<EPS>".
These are called the client symbols.
nonterms
The set of symbols found on the LHS of some production.
terms
The set of client symbols of the grammar excluding those found on the
LHS of a production.
epslhs
The subset of client nonterminals which directly derive either
nothing or "<EPS>".
lhsdereps
The subset of client nonterminals which derive nothing.
This is a (possibly improper) superset of 'epslhs'.
lhsprods
A dictionary of keyed by client nonterminals, returning
the set of productions of the nonterminal.
productions
A list of productions in the same order as the sequence passed to the
constructor.
start
The nonterminal which the client denoted as the start symbol of the grammar.
firstmap
A dictionary keyed by grammar symbols, defining the FIRST set of that
symbol. The dictionary includes entried for "<EOF>", "<EPS>", and a special
entry for -1 (which is used internally as an error state).
The elements of the FIRST sets will be either client terminals or "<EOF>".
The FIRST set of a symbol is defined as follows: for a terminal, the singleton
set containing just that
terminal, for a nonterminal, the set of terminals which could be the
first symbol of a derivation of the nonterminal, and including "<EPS>"
if the nonterminal can derive nothing. See the Dragon book [4.4 p188].
followmap
A dictionary keyed by client nonterminals defining the FOLLOW set of that
nonterminal.
The FOLLOW set is defined as the set of terminals which can follow
the nonterminal in some sentential form of the grammar, and including
"<EOF>" if the nonterminal can appear at the right of a sentential form.
See the Dragon book [4.4 p189].
Start python section to interscript/parsers/lalr1.py[4]