[antlr-interest] Tree grammar, can't find the error

Jim Idle jimi at temporal-wave.com
Tue Oct 25 11:54:32 PDT 2011


You are just typing the tree syntax like a parser syntax and that will not
work. Walk the tree and produce the dot spec, produce the .png
representation and you will see the point. This is all recursive...

Think of how an expression tree is written:

expr : ^(PLUS expr expr)
	| ^(MINUS expr expr)
	| NUMBER
	;

You might need to start with the simple examples before trying to detangle
the parser that you have, but definitely start looking at the tree
graphically.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Yves Weißig
> Sent: Tuesday, October 25, 2011 9:37 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Tree grammar, can't find the error
>
> Hi list,
>
> I trying to write a tree grammar for this tree:
>
> (PROG (WSN   ) (GROUP (COMMAND pard) ) ... )
>
> So, a PROG node is parent of multiple WSN, GROUP, etc. nodes.
>
> My rules look like:
> prog      : ^('PROG' (v+=space | v+=group)+) -> emit(v={$v}) ;
> space     : ^('WSN' v=.*) -> emit(v={$v}) |
>             ^('TABN' v=.*) -> emit(v={$v}) |
>             ^('NEWLINEN' v=.*) -> emit(v={$v}) ;
> group     : ^('GROUP' v+=space*
>               (v+=group v+=space* |
>               v+=plaintext v+=space* |
>               (v+=command | v+=escape)
>               (v+=delimiter v+=space+ | v+=delimiter | ))+) ->
> grp(v={$v}) ; ...
>
> This throws "can't look backwards more than one token in this stream",
> so I assume I have an error in my tree grammar... I just managed to
> write:
>
> prog      : ^('PROG' v+=.*) -> emit(v={$v}) ;
>
> which gives me:
>
> WSNGROUP
>
> But I want to output the subtrees, so I need the first approach. Can
> anybody tell me what I'm doing wrong?
>
> Best regards, Yves
>
> 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