Module parser
[hide private]
[frames] | no frames]

Module parser

source code

This is part of Yappy

parser.py -- Yet another parser for python...

A LR parser generator, based on Aho and al. 1986, Compilers (aho86:_compil).

It currently builds SLR, LR(1) and LALR(1) parsing tables.

Copyright (C) 2000-2003 Rogério Reis & Nelma Moreira {rvr,nam}@ncc.up.pt Version: $Id: parser.py,v 1.18 2006-07-19 09:52:06 rvr Exp $

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


Author: Rogério Reis & Nelma Moreira {rvr,nam}@ncc.up.pt

Classes [hide private]
  Lexer
Class for lexical analyser to use with the parser
  YappyError
Class for all Yappy exceptions
  LexicalError
Class for all Yappy Lexical analyser exceptions
  LexicalRulesErrorRE
An error occured parsing the RE part of a lexical rule
  GrammarError
Class for input grammar errors
  SLRConflictError
Confliting actions in building SLR parsing table.
  LRConflictError
Conflicting actions in building LR parsing table.
  LRConflicts
Confliting actions in building LR parsing table.
  LRParserError
An error occured in LR parsing program
  SemanticError
An error occured in the application of a semantic action
  TableError
Mismatch table version
  CFGrammar
Class for context-free grammars
  LRtable
Class for construction of a LR table
  SLRtable
Class for construction of a SLR table
  LR1table
Class for construction of a LR1 table
  LALRtable1
Class for construction of LALR(1) tables
  LALRtable
Class for construction of LALR tables
  LogLR
Class for LR table construction report:
  LRparser
Class for LR parser
  LRBuildparser
Class for LR parser: without shelve and semantic rules(obsolete)
  Yappy
A basic class for parsing.
  Yappy_grammar
A parser for grammar rules.
  Stack
A simple class to implement stacks
Functions [hide private]
 
Dict(**entries)
Create a dict out of the argument=value arguments
source code
 
grules(rules_list, rulesym='->', rhssep=None)
Transforms a list of rules in a grammar description.
source code
 
expandSemRule(strargs, strfun) source code
 
Reduction(fun, sargs, context={})
Reduction function for semantic rules:
source code
 
DefaultSemRule(sargs, context={})
Default semantic rule
source code
 
EmptySemRule(sargs, context={}) source code
Variables [hide private]
integer _DEBUG = 0
if nonzero, display information during parser generation or parsing.
  _Version = 1.7
  NIL = ''
Function Details [hide private]

grules(rules_list, rulesym='->', rhssep=None)

source code 

Transforms a list of rules in a grammar description. If a rule has no semantic rules, DefaultSemRule is assumed.

Parameters:
  • rules_list - is a list of pairs (rule,sem) where rule is a string of the form:
    • Word rulesym Word1 ... Word2
    • Word rulesym []
  • rulesym - LHS and RHS rule separator
  • rhssep - RHS values separator (None for white chars)
Returns:
a grammar description

Reduction(fun, sargs, context={})

source code 

Reduction function for semantic rules:

  • fun can be: -- a function -- or a string with positional arguments $n that is expanded

and evaluated with eval