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

Jim Idle jimi at temporal-wave.com
Fri Feb 18 08:54:17 PST 2011


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


More information about the antlr-interest mailing list