[antlr-interest] Combining into single token

Joel Shellman jshellman at gmail.com
Wed Aug 1 13:52:57 PDT 2007


On 8/1/07, Diehl, Matthew J <matthew.j.diehl at intel.com> wrote:
> > 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';


No, that's not what fragments do--they make rules non-global--only
accessible from other rules (a very handy thing). That said, I found I
did need fragments for the full grammar I was doing--so thanks for the
tip!

Terrence's post did exactly what I wanted.

Thanks!


More information about the antlr-interest mailing list