[antlr-interest] wildcard in tree grammar
antlr at mirality.co.nz
Mon Dec 1 11:51:14 PST 2008
At 05:43 2/12/2008, Terence Parr wrote:
>'.' is great to avoid a subtree or any random operand node
>you don't care about. As a root, it can only be a node so
>it's pretty easy to give the set of valid roots if necessary.
"Easy" is a relative term, depending on how many of them there are
>Remember that AST construction is all about identifying the
>ops and pseudo-ops in your program, then making them roots.
>Why would you ever want to ingore what operation your looking
That's not the only use for them. They can be used to indicate
types or categories as well -- and in some contexts you care,
while in others you might not. This is especially true when you
have multiple tree parsers reading a single AST input, since
different walkers might care about different things.
>Oh, I just found one. You want to find all ID refs...well,
>actually that is just:
>id : ID ;
>If you don't care about the root, just don't give it, right?
>x : ^(. ID) ;
>is identical to ID except it won't match ID as a root but
>plain ID would.
If ID on its own can match a tree of ^(FOO ID), then that's a bug.
>If you don't care about structure, one could argue why you're
>a grammar to do that ;)
You might not care *sometimes*, in *some contexts*. But you care
a lot about other contexts.
More information about the antlr-interest