[antlr-interest] Source positions for imaginary tokens
Jim Idle
jimi at temporal-wave.com
Fri Sep 14 09:41:37 PDT 2012
keyword:
keyword_sp
(
| t=ASCII_SYMBOL
| t=BACKUP_SYMBOL
...
| t=UPGRADE_SYMBOL
) { $t->type = IDENTIFIER; }
;
(double check with you grammar). It works fine, you just have to find the
right combination.
Even though I wrote the C target, I find that a good way to remind myself
of what I have available in what scope is to generate the code and look at
the type assigned to $t or $whatever - that will often give you a "oh
yeah, I remember/see why it is like that now" moment. Choose the simplest
path grasshopper.
In the lexer, the context is production of a token, so you can just say
$type = XXX; - but in the parser, it could be any token as the context is
either producing nothing, or some part of a tree.
Jim
> -----Original Message-----
> From: Mike Lischke [mailto:mike at lischke-online.de]
> Sent: Friday, September 14, 2012 12:30 AM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Source positions for imaginary tokens
>
> > Just use $token->type = ID;
> >
> > That's all I do - the type field will never change.
>
>
> error(114): MySQL.g:2400:4: attribute is not a token, parameter, or
> return value: token
>
> The rule is like this:
>
> keyword:
> keyword_sp
> (
> | ASCII_SYMBOL
> | BACKUP_SYMBOL
> ...
> | UPGRADE_SYMBOL
> ) { $token->type = IDENTIFIER; }
> ;
>
> Been there, done that. This seems only to work for lexer rules.
>
> Mike
> --
> www.soft-gems.net
>
More information about the antlr-interest
mailing list