[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using Standard C++ library with Bison .y files (or defining tokens w
From: |
Hans Aberg |
Subject: |
Re: Using Standard C++ library with Bison .y files (or defining tokens with #define)... |
Date: |
Wed, 27 Mar 2002 00:52:06 +0100 |
Reply-to: address@hidden
At 20:30 +0100 2002/03/26, Michael Suodenjoki wrote:
>Hi,
Hi.
>I'm one of those C++ developers that's trying to use Bison to integrate
>a parser into a C++ project.
Akim will probably suggest you to try the CVS version and its C++ skeleton
file (I'm not a Bison developer).
> %token eq
>This will in my version of the Standard C++ library FAIL because the
>'eq' is used inside the library (in my case in <iosfwd>, which have been
>included through <sstream>).
>1. Don't define token symbols that Standard C++ or any other include
>file may use. This may be a huge amount,
>and it is nearly impossible to know on beforehand. I know that the
>normal convention is to use uppercase
>tokens like EQ, however in principle these may be used elsewhere too.
Unless you find it difficult to type, have a computer really low on memory
or something, one can use longer names, for example:
%token equal_sign "="
%%
boolean_expression: lhs "=" rhs {...}
Bison error messages will then print "=", not "equal_sign".
>2. Change Bison so that it doesn't produces #defines but uses constants,
>e.g. like "const int eq = 257;"
I think that Bison's future C++ feature will do that, hopefully within a
custom namespace at need.
While waiting for that, you can emulate macro namespaces by adding a
prefix, for example
%token my_equal_sign "="
Apart from this change, provided you use "=", it does not change the
grammar code itself!
Hans Aberg