[antlr-interest] Q: how to incorporate a preprocessor in the flow?

Martin d'Anjou point14 at magma.ca
Sun Apr 3 19:51:31 PDT 2011


Hello,

I am trying to find a way to incorporate a preprocessor in the ANTLR 
flow. I thought of doing this before the lexer, but I need to tokenize 
the incoming char stream for macro substitution to be easy. I thought of 
doing it between the lexer and the parser, and replace the preprocessor 
tokens with their expansion before feeding the token stream to the 
parser, so I guess I would end up using something like the 
TokenRewriteStream??? Can someone steer me in the right direction 
please? Or should I be using lexer rule actions? In which case, any 
example on how to access the token stream of the replacement token list 
of an identifier? Too many questions sorry.

The language I am hoping to tokenize is SystemVerilog and has C-like 
preprocessor macros (`include, `ifdef, `define NAME(params,...), token 
concatenation, etc.).

Regards,
Martin



More information about the antlr-interest mailing list