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

Class CFGrammar


Class for context-free grammars
Method Summary
  __init__(self, grammar)
  __str__(self)
Grammar rules
  DERIVE_NT(self)
For each nonterminal s determines the set of nonterminals a such that s ->* ar, for some r
  DERIVE_ONE_NT(self, s)
For nonterminal s determines the set of nonterminals a such that s -> ar, for some r
  DERIVE_T(self)
  FIRST(self, s)
FIRST(s) is the set of terminals that begin the strings derived from s
  FIRST_NT(self, s)
Recursivelly computes FIRST(X) for a nonterminal X
  FIRST_ONE(self)
Determines FIRST(s), for every symbol s, that is the set of terminals that begin the strings derived from s
  FIRST_TRA(self, s, d)
Transitiv closure of FIRST(X)
  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.
  makeFFN(self)
  makenonterminals(self)
Extracts nonterminals from grammar rules.
  maketerminals(self)
Extracts terminals from the rules.
  NULLABLE(self)
Determines which nonterminals X ->* []
  TransClose(self)
For each nonterminal s determines the set of nonterminals a such that s ->* ar, for some r
  TRAVERSE(self, s, d)

Instance Variable Summary
  nonterminals: nonterminals symbols
  ntr: dictionary of rules for each nonterminal
  rules: grammar rules
string start: start symbol
  terminals: terminals symbols

Method Details

__init__(self, grammar)
(Constructor)

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)

Grammar rules
Returns:
a string representing the grammar rules

DERIVE_NT(self)

For each nonterminal s determines the set of nonterminals a such that s ->* ar, for some r

DERIVE_ONE_NT(self, s)

For nonterminal s determines the set of nonterminals a such that s -> ar, for some r

FIRST(self, s)

FIRST(s) is the set of terminals that begin the strings derived from s

FIRST_NT(self, s)

Recursivelly computes FIRST(X) for a nonterminal X

FIRST_ONE(self)

Determines FIRST(s), for every symbol s, that is the set of terminals that begin the strings derived from s

FIRST_TRA(self, s, d)

Transitiv closure of FIRST(X)

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.

makenonterminals(self)

Extracts nonterminals from grammar rules.

maketerminals(self)

Extracts terminals from the rules. nonterminals must already exist

NULLABLE(self)

Determines which nonterminals X ->* []

TransClose(self)

For each nonterminal s determines the set of nonterminals a such that s ->* ar, for some r

Instance Variable Details

nonterminals

nonterminals symbols

ntr

dictionary of rules for each nonterminal

rules

grammar rules

start

start symbol
Type:
string

terminals

terminals symbols

Generated by Epydoc 2.1 on Wed Jul 19 10:36:00 2006 http://epydoc.sf.net