ANN: Introducing PLY-1.0 (Python Lex-Yacc)
David Beazley
beazley@cs.uchicago.edu
Mon, 18 Jun 2001 18:57:33 -0500 (CDT)
June 18, 2001
Announcing : PLY-1.0 (Python Lex-Yacc)
http://systems.cs.uchicago.edu/ply
Just when you thought it was safe, I'm pleased to announce the availability
of an entirely new Python parser construction tool.
PLY is a 100% Python implementation of the common parsing tools lex
and yacc. Although several other parsing tools are available for
Python, there are several reasons why you might want to consider PLY:
- The tools are very closely modeled after traditional lex/yacc.
If you know how to use these tools in C, you will find PLY
to be similar.
- PLY provides *very* extensive error reporting and diagnostic
information to assist in parser construction. The original
implementation was developed for instructional purposes. As
a result, the system tries to identify the most common types
of errors made by novice users.
- PLY provides full support for empty productions, error recovery,
precedence rules, and moderately ambiguous grammars.
- Parsing is based on LR-parsing which is fast, memory efficient,
better suited to large grammars, and which has a number of nice
properties when dealing with syntax errors and other parsing problems.
Currently, PLY builds its parsing tables using the SLR algorithm which
is slightly weaker than LALR(1) which is used in traditional yacc.
- Like John Aycock's excellent SPARK toolkit, PLY uses Python
reflection to build lexers and parsers. This greatly simplifies
the task of parser construction since it reduces the number of files
and eliminates the need to run a separate lex/yacc tool before
running your program.
- PLY can be used to build parsers for large programming languages.
Although it is not ultra-fast due to its Python implementation,
PLY can be used to parse grammars consisting of several hundred
rules (as might be found for a language like C). The lexer and LR
parser are also reasonably efficient when parsing normal
sized programs.
The original version of PLY was developed for an Introduction to
Compilers course where students used it to build a compiler for a
simple Pascal-like language. Their compiler had to include lexical
analysis, parsing, type checking, type inference, nested scoping, and
generation of assembly code for the SPARC processor. Because of this,
the current implementation has been extensively tested and debugged.
In addition, most of the API and error checking facilities have been
adapted to address common usability problems.
More information about PLY can be obtained on the PLY webpage at:
http://systems.cs.uchicago.edu/ply
PLY is freely available and is licensed under the terms of the Lesser
GNU Public License (LGPL).
Cheers,
David Beazley (beazley@cs.uchicago.edu)