[antlr-interest] Combining into single token

Diehl, Matthew J matthew.j.diehl at intel.com
Wed Aug 1 13:05:39 PDT 2007


> root	:	'a'+ 'D' 'a'+ 'D';
> 
> If you input aaDaaD to this grammar, it will result in a tree of ^(nil
> a a D a a D). Each letter is a different node in the tree. How can I
> change this so that the above would result in ^(nil aaDaaD), with all
> the letters being just one token/node in the tree?

Isn't that what fragments do? (not quite sure as I just use them
blindly, lol)

root : aDaD_rule;

fragment
aDaD_rule : 'a'+ 'D' 'a'+ 'D';

Matt


More information about the antlr-interest mailing list