Rahul Sharma (Editor)

PLY (Python Lex Yacc)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Original author(s)
  
David Beazley

Website
  
www.dabeaz.com/ply/

Written in
  
Python

PLY is a parsing tool written purely in Python. It is basically a re-implementation of Lex and Yacc originally in C-language. It was written by David Beazley. Unlike Lex and Yacc in C which uses LALR parsing technique, PLY uses LR parsing which can incorporate large grammars easily. PLY also has extensive debugging and error reporting facilities.

Contents

History

David Beazley originally wrote PLY in 2001 for an introductory course on compilers. He created it to aid the students in creating compilers for simple Pascal-like languages. Since then it has seen many improvements and has come out as one of the popular parsing tools.

Features

Implemented in Python, it has almost all the features provided by Lex and Yacc. It includes support for empty productions, precedence rules, error recovery, and ambiguous grammars.

PLY-3.0 includes support for Python 3.0 and some other features.

Structure of a PLY file

PLY has the following two Python modules which are part of the ply package.

  • ply.lex - This deals with the lexical analysis part.
  • ply.yacc - This module is for creating a parser.
  • These files contain the necessary modules.

    References

    PLY (Python Lex-Yacc) Wikipedia