Bolting a Bison/Flex parser into Python

Clint Olsen olsenc at kodiak.ee.washington.edu
Thu May 11 16:49:30 EDT 2000


Hello:

I have this desire to write a parser using GNU Bison and then allow people
to write Python code to use the objects built by the parser.  I'm not quite
sure how to design this, and I'm not sure if I'm approaching the problem in
the correct way.  I'm new to Python and thumbing through the "Learning
Python" book by Lutz.  I've also skimmed the Python docs on www.python.org.

My motivation for doing this is to create a rock solid parser using Bison
(I've had experience with this before), and using the Pyton/C API to allow
Python programmers to to write programs using lists and dictionaries I
create.

This allows me to accomplish two things: 

1) I have a C interface to write programs to hook up to my parser should I
   need the speed of C.
2) People who don't want to get bogged down by C++/C can use a higher-level
   interpreted language to get work done much quicker using the same
   parser.  I don't have to maintain two parsers.

The reason why I considered Python is that I was looking for a
well-designed language with a clean API.  Referring to Perl's perlguts and
some advanced programming texts indicates that doing this in Perl seems a
daunting task.  I have been programming Perl in a limited capacity for the
last couple of years: no big projects, mostly file manipulations.
Although, Perl's "tie" capability seems to be what I want to do: Be able to
override the methods for handling hash and array objects.

So, my question is this: Is my objective reasonable, and can you point me
in a general direction in the Python documentation for accomplishing this
task?  I don't think embedding the Python interpreter into my C program is
necessarily what I want, but perhaps someone here has had some experience
with this type of application.  This will keep me from making poor
decisions from the beginning that could make the task more complicated.

Thanks,

-Clint



More information about the Python-list mailing list