[antlr-interest] How much semantic info should I attach to an imaginary token

Felix Dorner felix_do at web.de
Sun Apr 6 05:33:58 PDT 2008


Hey,

I do object oriented stuff based on an uml class input model + some 
operation specification given as text. During validation I have to 
resolve types that are defined in the UML model. Either the class type 
is given by a simple ID string, or by a qualified name which is 
something like abc::def::MyClass

Currently I am working on Object creation expressions:

primary : NEW ID ('::' ID)*
              ; 

I ask myself whether I should include all the ID tokens in the tree, or 
simply store their text in an imaginary QNAME token:

primary : NEW^ qname
qname: s=ID ('::' ID)* -> QNAME[s  $text];

The resolver would later handle something like resolveType(String id), 
and check if it's a local or a qualified type reference.

Another question: In the imaginary token constructor, I need to omit the 
comma between s and $text, otherwise I get an additional one in the 
generated parser. The book says there _has_ to be a comma. Is this a 
bug, an error in the book?

Felix



More information about the antlr-interest mailing list