bison & C++

David Fletcher <frodo@fusionmm.com>
18 Jun 1998 11:18:26 -0400

          From comp.compilers

Related articles
bison & C++ frodo@fusionmm.com (David Fletcher) (1998-06-18)
| List of all articles for this month |
From: David Fletcher <frodo@fusionmm.com>
Newsgroups: comp.compilers
Date: 18 Jun 1998 11:18:26 -0400
Organization: Compilers Central
Keywords: yacc, C++, available

Hi all,


Synopsis
------------------------------------------------------------------------
I have augmented bison-1.25 so that it will produce an object-oriented
parser written in C++. This code is being submitted to the Free
Software Foundation, and until it is accepted, please consider this
code to be experimental. Until then, you may find the code at:


ftp://ftp.iecc.com/pub/file/bison-1.26exp.zip




More Details
------------------------------------------------------------------------
The README.cxx file describes how the system works in detail, but
here's a quick summary:


- The generic parsing machinery is provided by an abstract
base class called 'Parser.' The code for this class can be
found in the 'ClassStuff' directory. As of now, the normal
installation process for bison does NOT compile and install
this code; a developer is responsible for compiling this
code into the appropriate form (e.g., a static or shared
library) and installing this, and the Parser.h header file,
in a location appropriate for a given machine. The generic
parser is derived from the bison.simple file and is covered
by the same license as bison.simple.


The installation process for bison may be modified so that
this is handled automatically.


- Bison itself has been modified so that it will produce the
member functions for a class derived from the Parser base
class; these member functions specialise the generic parsing
machinery for a particular grammar. The format for the
input file (e.g., a .y file) has not changed.


Bison now has an additional command-line option
(--class-name or -c) that directs it to generate C++ code.
The name of the derived class must be provided with this
option. As an example, bison might be invoked like so:


bison --class-name=foo --defines --verbose foo.y


The changes to the bison source code are minimal, if that is
a concern.


- You can use whatever lexer you'd like, but I tend to use
flex, and I tend to have flex produce an object-oriented,
C++-based lexer. In order for lex to work well with the
C++-based parser, I've modified the class definition for the
lexer so that it has an additional member, which is a
pointer to its associated parser. This lets the lexer
'communicate' with the parser in order to set lookahead
values, increment line numbers, etc. The modifications to
flex consist of a few changes to the FlexLexer.h header
file, which is included in the example. I have NOT (yet)
submitted these changes to the maintainer(s) of flex.


If you have any questions or comments, please let me know. Thanks.


David Fletcher frodo@fusionmm.com
Fusion MicroMedia
Longmont, CO aequam serva mentem,
303.690.4309 or 303.651.1000 x362 comprime linguam
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.