[antlr-interest] Accessing HIDDEN tokens in the C target.

Robin Green rgreen at google.com
Thu Aug 28 17:01:55 PDT 2008


On Thu, Aug 28, 2008 at 4:38 PM, Jim Idle <jimi at temporal-wave.com> wrote:

>  On Thu, 2008-08-28 at 16:33 -0700, Jim Idle wrote:
>
> When you want to do this in one rule, just use get it directly starting
> from the current index. Say you want to look back from a particular token in
> a rule to see if there was a comment on channel 2 (please note that I have
> not compiled this, just typed it in from memory). Basically though you can
> do anything you can do in Java (more in fact), just by looking a ta Java
> example and realizing that the C methods are all the same names (just about)
> but instead of  x.y(z), you use x->y(x, z).
>
> rule
> : f=FUNCTION x y z
>     {
>         int sIndex;
>        pANTLR3_COMMON_TOKEN tok;
>
>        sIndex = $f->getTokenIndex($f) - 1;   // Index for first token
>
>       // Now look back up looking for tokens
>      tok = INPUT->get(INPUT, sIndex);
>
>
> Actually, this should be:
>
> tok = (pANTLR3_COMMON_TOKEN)(INPUT->get(INPUT, sIndex)->super);
>
> Jim
>
>
Are you sure? "super" is not a member of ANTLR3_COMMON_TOKEN_struct. Which
object are you "super"ing here, the Token or the TokenStream?

The code for "get()" in antlr3tokenstream.c takes the result of the INPUT
macro, follows the super pointer to reach a pANTLR3_COMMON_TOKEN_STREAM,
then directly accesses the pANTLR3_VECTOR "tokens" to get the next symbol.
What are you suggesting that is different from that?

Mixing these macros with structure fields is making my head spin.

- Robin Green
  Google, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080828/ed7bbe53/attachment.html 


More information about the antlr-interest mailing list