[antlr-interest] Force nodes for grammar rules
Bryan Ewbank
ewbank at gmail.com
Mon Dec 5 14:30:28 PST 2005
There's no automatic way to do it. You would have to make sure that
every production has an action of the form
{ ## = #( #PRODUCTION_ID,"production_name"], ## ); }
Of course, the leaf nodes, such as identifier, etc, might need
different processing...
hope this helps,
- Bryan
On 12/5/05, Maik Merten <maikmerten at gmx.net> wrote:
> Hello,
>
> I know that ANTLR generates abstract syntax trees and doesn't include
> nodes for every grammar-rule applied. This is discussed in the FAQ (
> http://www.jguru.com/faq/view.jsp?EID=814505 ) and this behaviour is a
> Good Thing(tm).
>
> However, for the project i am involved with it is considered extremely
> handy to have the actual parse tree (there may be cases where the exact
> sequence of productions gives information about the "context" - which we
> could exploit instead of doing more extensive analysis).
>
> I may be cursed with blindness but I am not aware of a way to force the
> parse tree into the "AST" tree. Is there any? Can we modify the grammar
> in a way that ensures that every rule applied gets a node?
>
>
> Thank you,
>
> Maik
>
More information about the antlr-interest
mailing list