[antlr-interest] Enhancement request for identifyingimaginarytokens
Terence Parr
parrt at cs.usfca.edu
Fri Dec 14 13:30:30 PST 2007
Hi. Why not do what I do:
s : 'if' e 'then' s -> ^('if' e s)
| e ';' -> e
;
etc... no need for imaginary tokens. Remember imag is for nodes that
have no corresponding input token.
Ter
On Dec 14, 2007, at 1:19 PM, Hardy, Stephen wrote:
> You're right in that I have slightly overused ITs, however in cases
> where there is a logical choice (like the operator in expressions) I
> just pull that token to the root of the new sub-tree. It's when one
> gets to higher level constructs of the language where ITs become more
> useful, since there is often no reasonable token to use as the root.
> For example, one could use the ';' that terminates statements as the
> root node for all statement sub-trees, but I think it's nicer to have
> distinct ITs for expression statements, if statements, for statements
> etc. -- the theory is that this makes tree walkers more efficient, if
> not easier to understand. In many cases the actual ';' or other
> delimiting token is not actually part of the rule where one would like
> to ref it, since it would not be the most natural way to express the
> grammar.
More information about the antlr-interest
mailing list