Bolting a Bison/Flex parser into Python

Anthony J Wilkinson anthony at dstc.edu.au
Thu May 11 20:56:17 EDT 2000


Hi Clint,

The idl compiler, fnidl, that comes with Fnorb <http://www.fnorb.com> does
this. Full source is included with the distribution. Note that to build
changed grammar or lexer files you will need to do the following which is not
yet documented or in the makefile:

To build the bison and lex files:-

        % bison -o grammar.c -d grammar.y
        % flex -olexer.c lexer.l

Regards,
Anthony
_____________________________________________________________________
Anthony J Wilkinson                               anthony at dstc.edu.au
Software Engineer                                http://www.fnorb.com
DSTC Pty Ltd                                     Ph:  +61 7 3365 4310

On 11 May 2000, Clint Olsen wrote:

> 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
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list