Hi, All.
I’m using Antlr4, C# version, under Visual Studio. It works nicely.
AFAIK (but I may be wrong), Listeners and Visitor can be used in similar tasks. I’ve already done projects using both.
So, my question is: how to decide between them? Or can I use both on the same project? Note that all samples I’ve found uses Listener OR Visitor, but not both at the same time. It can be done?
Is there some “best practice” about this?
TIA,
Nilo - Brazil
| Este e-mail foi enviado por um computador sem vírus e protegido pelo Avast. www.avast.com |
That said, I still don't get the lexer's semantics. If I had
KEYWORD_AS_IDENT: PRIOR | LAST ;
PRIOR :'prior';
LAST :'last';
then this can only mean anything if antlr ultimately inlines the rules leaf defs to get
KEYWORD_AS_IDENT: 'prior' | 'last' ;
PRIOR :'prior';
LAST :'last';
now I get it.
For posterity, could you post your answer on stackoverflow and I'll accept it, or would you prefer I copy it over?
thank you
jan
On Friday, 12 February 2016 11:59:07 UTC, Eric Vergnaud wrote:LAST is declared before KEYWORD_AS_IDENT so when the lexer encounters 'last', it generates a LAST token, not a KEYWORD_AS_IDENT.
Your start rule does not accept LAST ten as a valid input, hence the shouting.Your grammar will actually NEVER produce a KEYWORD_AS_IDENT token, because another valid token will match before.It seems you are trying to get the lexer do the job of the parser i.e. handle multiple semantic alternatives, but at the time the token reaches the parser it's too late...Have you tried making KEYWORD_AS_IDENT a parser rule (lowercase) rather than a lever rule?