[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Using multiple grammars with a single lexer.
From: |
Keith Clifford |
Subject: |
Using multiple grammars with a single lexer. |
Date: |
Fri, 1 Aug 2003 07:16:42 -0700 |
User-agent: |
KMail/1.4.3 |
Hi,
I have a project which uses two grammars with a single lexer in the same
executable. In order to verify that the token types for each grammar are in
sync, I manually created a file with the token numbers in it that the lexer
knows about and then I include that file in each of the grammars. If the
multiply defined token types don't have the same value, the compiler will
complain. This worked well under bison 1.35 but doesn't under 1.85 because
the token numbers have been shifted up by 1. Under 1.35 the first token type
has a value of 257 but under 1.85 it has a value of 258.
For example:
in token.h:
#define NUMBER 257
in grammar1.y:
#include "token.h"
%token NUMBER
in grammar2.y
#include "token.h"
%token NUMBER
Each of the grammars will generate a .h file which is also included in the
generated .c file that looks like:
#define NUMBER 257
My question is can you suggest a way of doing what I'm trying to do that's
guaranteed to work with all yaccs or at least as many as possible? If it
wasn't for my manually generated verification file, it would probably work
but then I would run the risk of the token types getting out of sync and not
knowing about it until run time.
Also my scheme will break if under 1.85 the enum version of the token types
was being used instead of the #define version. Do you expect that the
#defines will always be the default way for defining the token types.
Thanks for any help.
--
Keith Clifford
- Using multiple grammars with a single lexer.,
Keith Clifford <=