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

Class Yappy

source code

LRparser --+
           |
          Yappy
Known Subclasses:

A basic class for parsing.

Instance Methods [hide private]
 
__init__(self, tokenize, grammar, table='YappyTab', no_table=1, tabletype=<class parser.LALRtable at 0x15c9b90>, noconflicts=1, expect=0, **args)
@param tokenize: same as for L{Lexer} @param grammar: if a string C{parse_grammar} is called
source code
 
input(self, str=None, context={}, lexer=0)
Reads from stdin or string and retuns parsed result
source code
 
inputfile(self, FileName, context={})
Reads input from file
source code
 
parse_tree(self)
To be defined using output
source code
 
test(self)
A test for each class
source code

Inherited from LRparser: __str__, gsrules, parse_grammar, parsing

Instance Variables [hide private]
  lex
a Lexer object

Inherited from LRparser: ACTION, GOTO, cfgr, context, nonterminals, output, rules, stack, table, terminals, tokens

Method Details [hide private]

__init__(self, tokenize, grammar, table='YappyTab', no_table=1, tabletype=<class parser.LALRtable at 0x15c9b90>, noconflicts=1, expect=0, **args)
(Constructor)

source code 

      @param tokenize: same as for L{Lexer}
      @param grammar: if a string C{parse_grammar} is called

      @param table: and no_table, tabletype same as for L{LRparser}

      @param **args: dictionary where:
      - key C{tmpdir} is the directory
where the parse table used by the Yappy Grammar is stored;
  -  key  C{usrdir} is the directory where the user tables are stored
  -  key  C{nosemrules} if 1 semantic actions are not applied
      

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

  • table_shelve - file where parser is saved
  • tabletype - type of LR table: SLR, LR1, LALR
  • no_table - if 0 table_shelve is created anyway
  • operators - precedence and associativity for operators
  • noconflicts - if 0 LRtable conflicts are not resolved, unless spcecial operator rules
  • expect - exact number of expected LR shift/reduce conflicts
  • args - extra arguments; key nosemrules if 1 no semantic rules are applied
Overrides: LRparser.__init__

input(self, str=None, context={}, lexer=0)

source code 

Reads from stdin or string and retuns parsed result

Parameters:
  • str - String to be parsed. If not given, reads from stdin.
  • context - some initial computational context
  • lexer - if 1 only lexical analisys is performed
Returns:
a tuple (parsed result,context) or only the parsed result