[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Flex & Bison under C++
From: |
Hans Aberg |
Subject: |
Flex & Bison under C++ |
Date: |
Tue, 29 Oct 2002 13:03:32 +0100 |
I have made a working C++ essentially class pure Flex lexer/Bison parser
combination. The problem is that the current setup in current Flex/Bison
C++ outputs is accommodated for that.
The problem is that C++ is more finicky than C with respects to types, and
if the size of a type is needed, forward declarations do not suffice.
So, for the Bison token_type, I used the its enum definition alone. Then,
if that token_type should be used in the Flex lexer interface, it must
appear before the latter. The same applies to the semantic type.
Thus I need the header info to be read in the following order:
Bison enum token_type.
User semantic_type definition.
Flex lexer class.
Bison parser class.
This order should then be same when read from both the lexer and parser
sources.
The reason that the semantic_type should be inserted at the place above is
that one can avoid it by a forward declaration, say:
class semantic_type;
followed by the Flex lexer class
class lexer {
public:
token_type lex(semantic_type&);
...
};
But if one then would want to define the semantic type by say a typedef, at
least my compiler will complain.
Currently, the Flex lexer sources will input <FlexLexer.h> in way that the
above setup is not possible. I was able to make a setup by not using the
Bison token_type, thus having the lexer::lex function returning an "int",
and by disabling the FlexLexer.h read more than once feature. -- The latter
will otherwise cause the FlexLexer.h class to be inserted twice.
In addition, I would want to be able to wrap the Flex lexer in a C++ namespace.
Hans Aberg
- Flex & Bison under C++,
Hans Aberg <=