I have a simple grammar
options {
language = Java;
output = AST;
ASTLabelType=CommonTree;
}
tokens {
DEF;
}
root
: ID '=' NUM (',' ID '=' NUM)* -> ^(DEF ID NUM)+
;
and the corresponding tree grammar:
options {
tokenVocab=SimpleGrammar;
ASTLabelType=CommonTree;
}
root
: ^(DEF ID NUM)+
;
However antlr (v3.3) cannot compile this tree grammar I’m getting:
syntax error: antlr: unexpected token: +
|---> : ^(DEF ID NUM)+
Also it don’t works if I want to create it as ^(ROOT ^(DEF ID NUM)+)
I want a tree that is corresponds to this (as parse creates it as well) :
(ROOT (DEF aa 11) (DEF bb 22) (DEF cc 33))
Thus antlr is capable to generate the tree in parser but not capable to parse it with tree grammar?!
Why this happens?
In order to get
(ROOT (DEF aa 11) (DEF bb 22) (DEF cc 33))you can define the following parser rules:and then your tree grammar would contain: