help-bison
[Top][All Lists]
Advanced

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

Re: Shift reduce errors due to embedded actions


From: Axel Kittenberger
Subject: Re: Shift reduce errors due to embedded actions
Date: Tue, 16 Oct 2001 21:56:54 +0200

> For instance,
>   I wrote a C preprocessor.  After a "#define" token is parsed, I want
> to turn on a flag that tells the lexer NOT to expand the following IDENT
> if it's a macro:
>    for example:
>       #define AAA 1 2 3
>       ...
>       #define AAA 4 5 6
>
> If while parsing the second definition of AAA, the lexer were to expand
> the previous definition for AAA (which is usually does: if an IDENT is
> lex-ed that is a defined macro, then the definition should be ouput by
> the lexer in place of the macro name) we wouldn't be able to detect that
> AAA was trying to be redefined in error.
>       It would simply become:
>          #define AAA 1 2 3
>          ...
>          #define 1 2 3 4 5 6
>

I once wrote a C-preprocessor, do you mix the C syntax with the preprocessor 
syntax? Preprocessing is much simpler if you do it as a seperate step. A 
statemachine that gets tokens from the lexer and put token into the actual C 
compiler. If this statemachine sees a #define it will automatically stop 
macro translation. At least this was how I implemented it, there are of 
course 100ooo... other (and maybe better) ways. I did use a bison parse to 
calculate the #if rules, but hand-programmed it oldfashioned.



reply via email to

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