Is there a mechanism to pass a value to a lexer? (I'm working with C target in ANTLR 3)
Some other search results had suggested putting a function and var into the member area:
@members
{
bool read_flag;
void set_flag(bool b) {read_flag = b;}
}
however, that does not seem to work. The set_flag() is a global for the lexer, but not able to be called from outside
I want to be able to do something like this in the calling code:
//some input stream
pANTLR3_INPUT_STREAM input =
antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8)buf, len, NULL);
pmyLexer lxr = myLexerNew(input);
lxr->set_flag(true);
You can use the user pointer for that, which has been added exactly for this purpose:
In my lexer I use this to store a reference to my RecognitionContext structure, which I then access via macros in my grammar:
The structure is defined like this: