14479Sbinkertn@umich.eduyply.py
24479Sbinkertn@umich.edu
34479Sbinkertn@umich.eduThis example implements a program yply.py that converts a UNIX-yacc
44479Sbinkertn@umich.eduspecification file into a PLY-compatible program.  To use, simply
54479Sbinkertn@umich.edurun it like this:
64479Sbinkertn@umich.edu
74479Sbinkertn@umich.edu   % python yply.py [-nocode] inputfile.y >myparser.py
84479Sbinkertn@umich.edu
94479Sbinkertn@umich.eduThe output of this program is Python code. In the output,
104479Sbinkertn@umich.eduany C code in the original file is included, but is commented out.
114479Sbinkertn@umich.eduIf you use the -nocode option, then all of the C code in the
124479Sbinkertn@umich.eduoriginal file is just discarded.
134479Sbinkertn@umich.edu
144479Sbinkertn@umich.eduTo use the resulting grammer with PLY, you'll need to edit the
154479Sbinkertn@umich.edumyparser.py file. Within this file, some stub code is included that
164479Sbinkertn@umich.educan be used to test the construction of the parsing tables. However,
174479Sbinkertn@umich.eduyou'll need to do more editing to make a workable parser.
184479Sbinkertn@umich.edu
194479Sbinkertn@umich.eduDisclaimer:  This just an example I threw together in an afternoon.
204479Sbinkertn@umich.eduIt might have some bugs.  However, it worked when I tried it on
214479Sbinkertn@umich.edua yacc-specified C++ parser containing 442 rules and 855 parsing
224479Sbinkertn@umich.edustates.
234479Sbinkertn@umich.edu
244479Sbinkertn@umich.eduComments:
254479Sbinkertn@umich.edu
264479Sbinkertn@umich.edu1. This example does not parse specification files meant for lex/flex.
274479Sbinkertn@umich.edu   You'll need to specify the tokenizer on your own.
284479Sbinkertn@umich.edu
294479Sbinkertn@umich.edu2. This example shows a number of interesting PLY features including
304479Sbinkertn@umich.edu    
314479Sbinkertn@umich.edu     - Parsing of literal text delimited by nested parentheses
324479Sbinkertn@umich.edu     - Some interaction between the parser and the lexer.
334479Sbinkertn@umich.edu     - Use of literals in the grammar specification
344479Sbinkertn@umich.edu     - One pass compilation.  The program just emits the result,
354479Sbinkertn@umich.edu       there is no intermediate parse tree.
364479Sbinkertn@umich.edu
374479Sbinkertn@umich.edu3. This program could probably be cleaned up and enhanced a lot.
384479Sbinkertn@umich.edu   It would be great if someone wanted to work on this (hint).
394479Sbinkertn@umich.edu
404479Sbinkertn@umich.edu-Dave
414479Sbinkertn@umich.edu       
42