[antlr-interest] Skipping or ignoring whole subtrees in a tree grammar
Frank Smith
fasmith718 at gmail.com
Mon Aug 13 10:36:52 PDT 2007
The wildcard is an interesting beast.
Only use it on the bare minimum amount of stuff in your grammar (e.g. only
the rule you need skipped!), because I had some seemingly unrelated errors
crop up in my grammar that I ended up tracing back to overusing the wildcard
in some rules.
in my case it was:
^('fun' TYPE ID param* block)
worked perfectly with:
^('fun' TYPE ID param* .)
and caused all kinds of heartache with:
^('fun' TYPE ID . .)
so even though i didn't use param in the action that followed i left it in
there for the sake of it actually working :)
good luck with yours
On 8/13/07, Hardy, Stephen <Stephen_Hardy at rabbit.com> wrote:
>
> Frank,
>
> thanks for the response! It seems that '.' is a bit more magic than I
> thought. That is, the semantics seem to be that '.' matches the token
> plus any subtree that it may have, not just the 'root' token itself
> (although I stand open to correction on this interpretation).
>
> Regards,
> SJH
>
>
> > -----Original Message-----
> > From: Frank Smith [mailto:fasmith718 at gmail.com]
> > Sent: Monday, August 13, 2007 8:44 AM
> > To: Hardy, Stephen
> > Cc: antlr-interest at antlr.org
> > Subject: Re: [antlr-interest] Skipping or ignoring whole
> > subtrees in a tree grammar
> >
> > my mistake: you can access bar by doing foo.start.getChild(0);
> >
> > Sorry for the mixup
> >
> > --Frank
> >
> >
> > On 8/13/07, Frank Smith <fasmith718 at gmail.com> wrote:
> >
> > Use the wild card. That causes a tree grammar to skip
> > a token e.g.:
> >
> > ...
> > | ^(DELETED_FOO .)
> > ...
> >
> > you can still access bar if you want by using
> > DELETED_FOO.start.getChild(0); if you want to use it in an
> > action somehow, but not be stepped through automatically by
> > the walker. I used this a lot- works great.
> >
> > Best regards,
> > Frank
> >
> >
> >
> > On 8/13/07, Hardy, Stephen < Stephen_Hardy at rabbit.com
> > <mailto:Stephen_Hardy at rabbit.com> > wrote:
> >
> > Hi all,
> >
> > supposing I have a tree grammar which includes
> > something like
> >
> > foo
> > : ^(FOO bar { some action... } )
> > | ^(DELETED_FOO bar)
> > ;
> >
> > Suppose bar is a complex, deeply recursive,
> > subtree; and I wish to avoid
> > as much as possible the overhead of parsing it
> > in the DELETED_FOO case.
> > (Imagine that DELETED_FOO was once a FOO, but
> > the parser or application
> > decided after the fact that it was an
> > irrelevant part of the input, and
> > changed the token to mark it as deleted, but
> > without actually removing
> > the subtree. Why not delete the tree? Well, a
> > different tree grammar
> > may still want to see the contents, just not this one.)
> >
> > Is there a way of telling ANTLR to basically
> > 'skip' any analysis of the
> > subtree under DELETED_FOO? For example, a
> > routine which simply consumes
> > tokens from the DOWN which immediately follows
> > DELETED_FOO until the
> > matching (balanced) UP token is seen?
> >
> > I seem to recall a mention of something like
> > this in TDAR, but darned if
> > I can locate it.
> >
> > Regards,
> > SJH
> >
> >
> >
> >
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070813/f864bd55/attachment-0001.html
More information about the antlr-interest
mailing list