Ruleset class, used to compute NFA and then DFA for
parsing based on a list of rules.
Methods
|
|
|
|
CompDFA
|
CompDFA ( self )
compute DFA for ruleset by computing the E-closure of the
NFA
|
|
CompFirst
|
CompFirst ( self )
method to compute prefixes and First sets for nonterminals
|
|
CompFollow
|
CompFollow ( self )
computing the Follow set for the ruleset
the good news: I think it's correct.
the bad news: It's slower than it needs to be for epsilon cases.
|
|
CompSLRNFA
|
CompSLRNFA ( self )
compute an SLR NFA for the ruleset with states for each SLR "item"
and transitions, eg:
X > .AB
on A maps to X > A.B
on epsilon maps to A > .ZC
and A > .WK
an item is a pair (rulenumber, bodyposition)
where body position 0 is interpreted to point before the
beginning of the body.
SLR = "simple LR" in Aho+Ullman terminology
|
|
DoSLRGeneration
|
DoSLRGeneration ( self )
do complete SLR DFA creation starting after initialization
|
|
DumpDFAsets
|
DumpDFAsets ( self )
|
|
DumpFirstFollow
|
DumpFirstFollow ( self )
|
|
DumpItemSet
|
DumpItemSet ( self, State )
|
|
DumpSLRNFA
|
DumpSLRNFA ( self )
dump the NFA
|
|
FirstOfTail
|
FirstOfTail (
self,
Rule,
TailIndex,
Token=None,
)
computing the "first" of the tail of a rule followed by an
optional terminal
doesn't include NULLTOKEN
requires self.First to be computed
|
|
ItemDump
|
ItemDump ( self, item )
dump an item
|
|
SLRFixDFA
|
SLRFixDFA ( self )
this function completes the computation of an SLR DFA
by adding reduction states for each DFA state S containing
item H > B.
which reduces rule H > B
for each token T in Follow of H.
if S already has a transition for T then there is a conflict!
assumes DFA and SLRNFA and Follow have been computed.
|
|
SLRItemIsFinal
|
SLRItemIsFinal ( self, item )
- utility function
returns true if an item is a final item
|
|
__init__
|
__init__ (
self,
StartNonterm,
Rulelist,
)
|