[antlr-interest] [C target] [3.1.1] Deriving imaginary nodes from real tokens

Sven Van Echelpoel sven.van.echelpoel at empolis.com
Fri Dec 12 00:40:37 PST 2008


[...]
> > 
> I'll take a look - does that snippet of code above reproduce it? What
> options {} have you got set etc? If you have the time, then a small,
> but complete, grammar would be helpful :-)
> 
It does. I have attached the grammar and and the resulting C file. With
1 argument, this is the code that is generated from that template:

#if 1 == 2
(pANTLR3_BASE_TREE)ADAPTOR->createTypeTokenText(ADAPTOR, BAR,
TOKTEXT(b))
#else        	
(pANTLR3_BASE_TREE)ADAPTOR->createTypeText(ADAPTOR, BAR,
(pANTLR3_UINT8)b)
#endif

While, on the other hand, with 2 arguments you get this:

#if 2 == 2
(pANTLR3_BASE_TREE)ADAPTOR->createTypeTokenText(ADAPTOR, BAR, TOKTEXT(b,
""))
#else
(pANTLR3_BASE_TREE)ADAPTOR->createTypeText(ADAPTOR, BAR,
(pANTLR3_UINT8)b, "")
#endif

With one argument, you can see that a node is created from the text,
while with 2 arguments the token along with the text is passed.

Thanks for looking into this, even though there is an easy workaround.

Sven

-------------- next part --------------
grammar imgnodes;


options {
  language = C ; 
  output=AST ; 
  
  ASTLabelType = pANTLR3_BASE_TREE;  
}

tokens {
  BAR;
}

//foo : b='bar' -> ^( BAR[ $b, "" ] )
foo : b='bar' -> ^( BAR[ $b ] )
    ;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: imgnodesParser.c
Type: text/x-csrc
Size: 13635 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20081212/25c10de8/attachment.bin 


More information about the antlr-interest mailing list