ANN: Pyacc 0.1 -- Python Yacc Parser

Pyacc is a Python interface/extension to the Berkeley Yacc parser generator. Pyacc reads a grammar, specified with Python documentation strings (similar to SPARK and PLY), and uses Yacc to produce the LALR(1) parsing tables. Unlike Yacc, Pyacc does not generate C code for a parser. Instead, the parser is built into the Pyacc Python module, and no C compilation is required to create a parser for a new grammar.
I created Pyacc because I wanted a Python parser that:
* can efficiently parse LALR(1) grammars. * allows strings and regular expressions to be embedded directly into the grammar rules. * uses function documentation strings to specify grammar rules. * is (I imagine) very fast, since most of it is just yacc. * does not produce code that needs to be run or compiled.
A simple example:
from pyacc import Parser
def add(t): 'exp : exp "+" exp' # literals are put directly into grammar rules return t[0] + t[2]
def number(t): r'exp : re"\d+" ' # regular expressions are preceded by 're' return int(t[0])
print Parser().parse("2+3+4")
==> 9
Pyacc can be obtained from <a href="http://staff.washington.edu/sabbey/pyacc">http://staff.washington.edu/sabbey/pyacc</a>
participants (1)
-
Brian Sabbey