Parser project

paul at prescod.net.bbs paul at prescod.net.bbs
Mon Jul 17 15:40:06 EDT 2000


Here is a project for a parser hacker:

Write a Python module that can read a grammar in the syntax that Python
uses (see Grammar/Grammar in the source distribution) and generate a
parser object without any special compilation stage:

from newparser import Parser

parser=Parser( grammar="/python/src/Grammar/Grammar" )
parsetree=parser.parse( sys.argv[1] )
code=compileast( parsetree )
eval( code )

With this tool, people could easily write Python-like languages in
Python by making changes to the grammar. This would be great for those
who want to experiment with new language features without building (and
distributing) a special version of Python. Let's say you invented a
Python-like language for matrices. You would tell people to install
Python and then invoke your code like this:

python matrixLang.py helloworld.mtrx

You could imagine the same for a Python-like language for XML
processing, or static type checking, ...or just to try out a new feature
that you would like to be in some future version of Python. It's not
that doing this is impossible today, it just isn't as easy as it would
be if there were a module that could parse things at runtime and was
compatible with Python's grammar syntax. (or maybe there is and I just
don't know it!!)

Once your feature was "worked out" you might want to use a compiler
compiler or even a C-based parser to speed it up, of course.
--
 Paul Prescod - Not encumbered by corporate consensus
It's difficult to extract sense from strings, but they're the only
communication coin we can count on.
	- http://www.cs.yale.edu/~perlis-alan/quotes.html



More information about the Python-list mailing list