the grammar class:
a grammar consists of
- a LexDict lexical dictionary;
- a deterministic FSMachine;
- a Rulelist
and optionally a dictionary that maps Rulenames
to Rulelist indices (used for dumping and externally)
Methods
|
|
AddNameDict
Addterm
Bind
CleanUp
DoParse
DoParse1
PrintDefaults
SetCaseSensitivity
__init__
|
|
AddNameDict
|
AddNameDict ( self, RuleNameDict )
this method associates rules to names using a
RuleNameDict dictionary which maps names to rule indices.
after invocation
self.RuleNameToIndex[ name ] gives the index
in self.RuleL for the rule associated with name, and
self.RuleL[index].Name gives the name associated
with the rule self.RuleL[index]
|
|
Addterm
|
Addterm (
self,
termname,
regexpstr,
funct,
)
bind a terminal to a regular expression and interp function
in the lexical dictionary (convenience)
|
|
Bind
|
Bind (
self,
Rulename,
NewFunction,
)
if the Name dictionary has been initialized
this method will (re)bind a reduction function to
a rule associated with Rulename
|
|
CleanUp
|
CleanUp ( self )
this may be silly, but to save some space in construction
a token dictionary may be used that facilitates sharing of
token representations. This method either initializes
the dictionary or disposes of it if it exists
|
|
DoParse
|
DoParse (
self,
String,
Context=None,
DoReductions=1,
)
parse a string using the grammar, return result and context
|
|
DoParse1
|
DoParse1 (
self,
String,
Context=None,
DoReductions=1,
)
parse a string using the grammar, but only return
the result of the last reduction, without the context
|
|
PrintDefaults
|
PrintDefaults ( self )
look for default bindings
|
|
SetCaseSensitivity
|
SetCaseSensitivity ( self, Boolean )
setting case sensitivity: must happen before keyword installation
in LexD.
|
|
__init__
|
__init__ (
self,
LexD,
DFA,
RuleL,
RuleNameDict=None,
)
Evaluate determines whether rules should be evaluated
after reductions. Context is an argument passed to the
list reduction function
|
|