1
#!/usr/local/bin/python
4
# Author: David Beazley (dave@dabeaz.com)
5
# Date : October 2, 2006
7
# Converts a UNIX-yacc specification file into a PLY-compatible
8
# specification. To use, simply do this:
10
# % python yply.py [-nocode] inputfile.y >myparser.py
12
# The output of this program is Python code. In the output,
13
# any C code in the original file is included, but is commented.
14
# If you use the -nocode option, then all of the C code in the
15
# original file is discarded.
17
# Disclaimer: This just an example I threw together in an afternoon.
18
# It might have some bugs. However, it worked when I tried it on
19
# a yacc-specified C++ parser containing 442 rules and 855 parsing
24
sys.path.insert(0,"../..")
31
if len(sys.argv) == 1:
32
print "usage : yply.py [-nocode] inputfile"
35
if len(sys.argv) == 3:
36
if sys.argv[1] == '-nocode':
39
print "Unknown option '%s'" % sys.argv[1]
41
filename = sys.argv[2]
43
filename = sys.argv[1]
45
yacc.parse(open(filename).read())
48
if __name__ == '__main__':