ANN: Pyacc 0.1 -- Python Yacc Parser

Brian Sabbey
Thu, 30 Jan 2003 22:34:29 -0800 (PST)

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=""></a>