[antlr-interest] CommonTree & Tree grammar versus DIY
Andy Tripp
antlr at jazillian.com
Mon Aug 18 07:16:04 PDT 2008
Szczepan Hołyszewski wrote:
> Andy Tripp wrote:
>
>> Right. Whoever writes the doSomething() method shown above is going to
>> have to know what the AST looks like, regardless of whether the
>> doSomething() call is embedded in a treewalker.g file or plain old code.
>
> That's exactly the problem. Whoever writes the doSomething() for a processing
> pass that is only interested in 3% of the language constructs, will have not
> only to know, but also to painstakingly express with tree rules, what the AST
> can possibly look like from the start symbol to wherever the relevant
> constructs can appear in the grammar. This essentially duplicates a large
> chunk of the parser grammar. There is no simple way to tell ANTLR to
> doSomething() e.g. for each type definition, regardless of whether it occurs
> at top level, in a class, in a function, in an anonymous code block buried
> deep in a lambda expression, or in that fifth possible place where the draft
> 0.0.2 specification will allow type definitions to occur.
>
> Szczepan Holyszewski
>
Exactly! So it's much better to just have doSomething() be part of
plain-old-Java code rather than a treewalker. Check for the
particular case you're looking for, and ignore everything else.
More information about the antlr-interest
mailing list