[antlr-interest] 2nd edition - Passing parameters to lexer grammars.
Johannes Luber
jaluber at gmx.de
Tue Oct 23 05:57:35 PDT 2007
Michael LeBlanc wrote:
>> Use
>>
>> @lexer::members {
>> myClass mine = new myClass();
>> }
>>
>> instead. BTW, please create a new email instead changing the subject of
>> a reply, as this messes the thread view up.
>
> Now it's visible ONLY in the lexer grammar. I need to create it in the
> parser grammar (or at some higher level) and use it in both parser and
> lexer grammars.
Oops, I thought, you wanted it only in the lexer. In your case you need both
@lexer::members {
myClass mine = new myClass();
public myClass getMyClass() {
return mine;
}
}
and
@members {
myClass mine;
public void setMyClass(myClass mine) {
this.mine = mine;
}
}
Use some glue code like
parser.setMyClass(lexer.getMyClass());
In any case, the parser doesn't influence the lexer, as the lexing phase
is completely separate from the parsing phase at this point.
> Sorry about the earlier message. Is this better?
Actually, the new email should be created only at the start of a new
thread, but let's now use this email thread.
Johannes
More information about the antlr-interest
mailing list