[antlr-interest] Predicate Question...

Hill, Robert rhill03 at eds.com
Mon Nov 6 23:36:29 PST 2006


Cheers Loring.


>For v2, syntactic predicates in tree grammars are common--or 
>rather, most large grammars seem to have one and sometimes 
>two--just because getting to k=1 was not easy.  v3 should do better.

ISTR using them in V2 but since I'd only ever done small things I didn't
really think how all this stuff would scale up to something larger.
Writing an 'if' statement to skip some logic is fine when you have a
single grammar, but I now make 7 passes over the same tree, if I have a
branch to skip in on I have to duplicate the code 7 times, it's a bit of
a maintainence headache!, still, I've learned some new tricks along the
way so its not wasted experience.

>Outputting a full tree is not a mistake--unless you are 
>building tree grammars by hand.  Tree grammars should be built 
>automatically--they are determined by the annotated input 
>(parser or tree walker) grammar--and then refactored.  I have 
>also found that skipping over branches is much less attractive 
>with automatic tree grammar generation.

I see the immense value in generating the tree, and also having a
grammar that matches to walk it too. I think that's a fantastic way of
looking at the tree's description and seeing exactly where to add code
as we come across each node. Pretty cool. My issue was I failed to
annotate the parser to build the correct tree in the first place. It
just blindly outputs everything from the first grammar - literally there
are no actions in the first grammer! Then from that point on I work with
tree parsers only. What I should have done is concentrate on building a
*correct* tree earlier, well at least the tree that more closely
represents what I wanted to work with. That was the big mistake, it
would have saved me quite a bit of work if the tree was in a better
state by the time I start to use it. Still, its caused me to think
deeply about how to structure this kind of tool, now I have a lot of the
pre-requisite knowledge. Reading the books & examples is fine, you
'know' how it works, actually putting it into practice is another thing
entirely! I read how the space shuttle works. Doesn't mean I can launch
one ;) hehe 

Anyway, you know what they say, "the plan is useless, the planning is
essential!" lol

Thanks for all your help Loring!*

Rob


(*) don't run off too far, I'll be starting something new to annoy you
with shortly ;) hehe



More information about the antlr-interest mailing list