Package td_parser :: Module td_parser :: Class Grammar
[hide private]
[frames] | no frames]

Class Grammar

source code

Class for Context free grammars

Grammar rules stored in self.productions Start Cat stored in self.start_cat Provided: a method for computing the terminals of the grammar. Unchecked assumption: terminals never use upper case (built into parser)

Instance Methods [hide private]
  __init__(self, start_cat, trace=False)
self.productions: a dictionary whose keys are categories and whose values are lists of productions
  __str__(self)
If g1 is a grammar object run 'print g1' to trigger this code, which builds the string representation of the grammar that is printed
  add_production(self, cat, production)
  compute_terminals(self)
Place a set of grammar terminals in self.terminals

Method Details [hide private]

__init__(self, start_cat, trace=False)
(Constructor)

source code 
self.productions: a dictionary whose keys are categories and whose values are lists of productions

__str__(self)
(Informal representation operator)

source code 
If g1 is a grammar object run 'print g1' to trigger this code, which builds the string representation of the grammar that is printed

add_production(self, cat, production)

source code 
None

compute_terminals(self)

source code 

Place a set of grammar terminals in self.terminals

Assumption: No symbol that ever occurs in the LHS of a production ever needs to occur in an input string.

Counterexample: If 's' is the start symbol of the grammar it is also the possession-marking 'word' in English.