help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How safe was my conversion?


From: tyrecius
Subject: How safe was my conversion?
Date: Fri, 22 Nov 2002 14:50:36 -0700 (MST)

I've been working on a parser using bison. The context of this parser was
a C++ program and so I therefore endeavored to make bison as friendly to
the rest of the program as possible. Below I outline the actions I took to
integrate the bison output. So far it works marvelously. However, there
may be some subtle bugs that I've missed or introduced. So my question is
whether the actions below are sufficient to integrate bison into a C++
program.

1) In my grammar, I chose to only have one data type, a class of my own
design. It has the requisite default constructor, copy constructor, and
assignment operator. This data type manages the data for all of the tokens
in the grammar.

2) Using the prologue and epilogue portions of the grammar file, I've
wrapped a class definition around the bison output. This is to localize
all of the variables and the yyparse function inside the scope of the
class. The final C++ compiler will see the yyparse as an inlined function
in the class definition. A number of grammar rule actions access data
members inside this class. yylex and yyerror are also defined as members
of this class. This represents the .h file of the class.

3) Since the entire output of the file is wrapped inside of a class, the
static const tables at the top of the file are now static data members and
as such must be defined and initialized outside of the class. I
copy-and-pasted them to the .cpp file of the class for initialization.
Inside of the class I deleted the tables leaving them as normal
declarations.

4) The #define's for token representation were also changed. I moved them
inside of the class and morphed them into an 'enum' declaration.

As I said before, this is currently working great. However, I wish to
forestall any subtle problems from popping up as my grammar evolves and
becomes more complex.

Thanks for any help on this matter.

-D






reply via email to

[Prev in Thread] Current Thread [Next in Thread]