[antlr-interest] Tree Duplicate
Buciuc Victor
victor.buciuc at gmail.com
Mon Mar 17 14:45:43 PDT 2008
Hello,
i have the following grammar for accepting pascal-type variable
declarations:
grammar PSC;
options {
output=AST;
ASTLabelType=CommonTree;
}
tokens {
ARRAY;
}
var_decl
: ID (',' ID)* ':' type -> ^(ID type)+
;
type
:TYPE
|array_type
;
array_type :
KW_ARRAY'['INTNO'..'INTNO']' KW_OF TYPE -> ^(ARRAY INTNO INTNO TYPE)
;
TYPE :KW_INT | KW_CHAR | KW_REAL | KW_BOOL;
KW_INT : 'integer' ;
KW_CHAR : 'char';
KW_REAL : 'real';
KW_BOOL : 'boolean';
KW_ARRAY : 'array';
KW_OF : 'of';
INTNO
:'0'|(('1'..'9') ('0'..'9')*)
;
ID
:(('a'..'z')|('A'..'Z')) (('a'..'z')|('A'..'Z')|('0'..'9')|'_')*
;
It appears that antlr duplicates only leaves.
EX: for the input "x,y : array[1..10] of integer" i want to get: ^(NIL ^(x
(ARRAY 1 10 integer)) ^(y (ARRAY 1 10 integer))) but i get: ^(NIL ^(x (ARRAY
1 10 integer)) ^(y))
Any help will be appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080317/e903b3a3/attachment.html
More information about the antlr-interest
mailing list