Module parser :: Class CFGrammar
[hide private]
[frames] | no frames]

Class CFGrammar

source code

Class for context-free grammars

Instance Methods [hide private]
 
__init__(self, grammar) source code
 
__str__(self)
Grammar rules
source code
 
makeFFN(self) source code
 
maketerminals(self)
Extracts terminals from the rules.
source code
 
makenonterminals(self)
Extracts nonterminals from grammar rules.
source code
 
NULLABLE(self)
Determines which nonterminals X ->* []
source code
 
FIRST(self, s)
FIRST(s) is the set of terminals that begin the strings derived from s
source code
 
FIRST_ONE(self)
Determines FIRST(s), for every symbol s, that is the set of terminals that begin the strings derived from s
source code
 
FIRST_TRA(self, s, d)
Transitiv closure of FIRST(X)
source code
 
FIRST_NT(self, s)
Recursivelly computes FIRST(X) for a nonterminal X
source code
 
FOLLOW(self)
computes FOLLOW(A) for all nonterminals: the set of terminals a that can appear immediately to the right of A in some sentential form.
source code
 
TransClose(self)
For each nonterminal s determines the set of nonterminals a such that s ->* ar, for some r
source code
 
TRAVERSE(self, s, d) source code
 
DERIVE_NT(self)
For each nonterminal s determines the set of nonterminals a such that s ->* ar, for some r
source code
 
DERIVE_ONE_NT(self, s)
For nonterminal s determines the set of nonterminals a such that s -> ar, for some r
source code
 
DERIVE_T(self) source code
Instance Variables [hide private]
  ritems
ntr[A] is the set of rules which has A as left side
  nonterminals
nonterminals symbols
  ntr
dictionary of rules for each nonterminal
  rules
grammar rules
string start
start symbol
  terminals
terminals symbols
Method Details [hide private]

__init__(self, grammar)
(Constructor)

source code 
Parameters:
  • grammar - is a list for productions; each production is a tuple (LeftHandside,RightHandside,SemFunc,Prec?) with LeftHandside nonterminal, RightHandside list of symbols, SemFunc syntax-direct semantics, if present Prec (PRECEDENCE,ASSOC) for ambiguous rules

    First production is for start symbol

    Special symbols: @S, $, #

__str__(self)
(Informal representation operator)

source code 

Grammar rules

Returns:
a string representing the grammar rules

maketerminals(self)

source code 

Extracts terminals from the rules. nonterminals must already exist