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

Yves Weißig weissig at rbg.informatik.tu-darmstadt.de
Tue Oct 25 09:37:17 PDT 2011


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


More information about the antlr-interest mailing list