[antlr-interest] Tree Grammar (Beginner doubt/problem)

Vinicius Durelli vinicius.durelli at gmail.com
Fri Feb 18 09:23:48 PST 2011


Jim, thank you.
Indeed, I stared at this rule for almost an hour and didn't see anything
wrong. You're right, I modified my grammar as you suggested and it did the
trick.
BTW, I was using AW but even using it I was not able to spot my stupid
mistake.

All the best,
~Vinicius Durelli

2011/2/18 Jim Idle <jimi at temporal-wave.com>

> Your construct will fail if the mutant rule is empty as it will not be a
> node. You want:
>
> body : ^(MUTANTSNODE mutant+)
>     | MUTANTSNODE // No children
>     ;
>
> That's a guess without looking at your tree though. If you debug the
> parser grammar in AntlrWorks, you can see the tree that you are actually
> building. This will help. You can also produce a dot spec for the tree
> (search the list) and produce an image of it.
>
> Jim
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Vinicius Durelli
> > Sent: Friday, February 18, 2011 7:35 AM
> > To: antlr-interest at antlr.org
> > Subject: [antlr-interest] Tree Grammar (Beginner doubt/problem)
> >
> > Hi, I have created a lexer and a parser for a rather simple DSL. A
> > snippet of this DSL that I am using for testing my lexer/parser is
> > attached (snippet.txt).
> > However, when it comes to evaluating the AST generated by my parser, my
> > tree grammar does not work properly. To be more specific, it stops
> > parsing at
> > rule:
> >
> > body : ^(MUTANTSNODE mutant*)
> > ;
> >
> > I have created grammars for lexers and parsers before, but tree
> > grammars are pretty new to my. Thus, any help on how to fix this
> > problem (I am sure it must be something quite simple, I do not have a
> > clue though) would be appreciated.
> > Attached you will find both grammars and the foregoing snippet that I
> > am using for testing purposes.
> >
> > I can provide more details if needed.
> > For your time, thanks.
> >
> > Regards,
> > Vinicius Durelli
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list