Validation, support for empty productions, error tokens, and ambiguity Like its Unix counterpart, yacc.py provides most of theįeatures you expect including extensive error checking, grammar If desired, yacc.py can also be used to implement yacc.py calls this repeatedly to retrieve Token() function that returns the next valid token on the Lex.py provides an external interface in the form of a The two tools are meant to work together. yacc.py is used to recognize language syntax that hasīeen specified in the form of a context free grammar. The lex.py module is used to break input text into aĬollection of tokens specified by a collection of regular expression Yacc.py, both of which are found in a Python packageĬalled ply. PLY consists of two separate modules lex.py and Used as a reference for PLY as the concepts are virtually identical. O'Reilly's "LexĪnd Yacc" by John Levine may also be handy. Techniques, and Tools", by Aho, Sethi, and Ullman. Want to consult an introductory text such as "Compilers: Principles, If you are unfamiliar with these topics, you will probably Parsing theory, syntax directed translation, and the use of compilerĬonstruction tools such as lex and yacc in other programming The rest of this document assumes that you are somewhat familiar with Instead, you will find a bare-bones, yetįully capable lex/yacc implementation written entirely in Python. The way of bells and whistles (e.g., automatic construction ofĪbstract syntax trees, tree traversal, etc.). It should also be noted that PLY does not provide much in However, advanced users will also find such features toīe useful when building complicated grammars for real programming Since PLY was primarily developed as an instructional tool, you willįind it to be fairly picky about token and grammar ruleĪdded formality is meant to catch common programming mistakes made by If you've used yacc in another programming language, it should beĮarly versions of PLY were developed to support an Introduction toĬompilers Course I taught in 2001 at the University of Chicago. This includes supporting LALR(1) parsing as well as providingĮxtensive input validation, error reporting, and diagnostics. The main goal of PLY is to stayįairly faithful to the way in which traditional lex/yacc tools work. PLY is a pure-Python implementation of the popular compilerĬonstruction tools lex and yacc. Python 2, you have to use Python 2.6 or newer. PLY-3.5 is compatible with both Python 2 and Python 3. That you read (or at least skim) this entire document before jumping Given the intrinsic complexity of parsing, I would strongly advise This document provides an overview of lexing and parsing with PLY. Debugging the lex() and yacc() commands.Recovery and resynchronization with error rules.Conditional lexing and start conditions.Line numbers and positional information.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |