[antlr-interest] How to build tree for variable definition with array possible?

BAO freegly at gmail.com
Thu Dec 10 23:29:24 PST 2009


How can I solute this problem?

I am developping a compiler for a VB-like language, and I use ANTLR2.7.7
to generate my AST builder, but now I have a problem when create tree
node for this production:

varDecl
: "Dim" identList "As" type
;

identList
: IDENT (LPAREN INTLIT RPAREN)? (COMMA IDENT (LPAREN INTLIT RPAREN)? )*
;

I want to create respective tree node for a single variable and an array
variable,but the problem is both of their first set contain the token
IDENT which mean an identifier:

varDecl!
options {defaultErrorHandler = true;} // let ANTLR handle errors
: d:"Dim" idl:identList "As"! t:type
{
#varDecl = #(#[VARDEF,"VARDEF"], t, idl);
}
;

identList
: id:IDENT //a tree node has add to tree
(lb:LPAREN^ /*now I want to create a ARRAY_DEF note instand of a single
variable tree node*/ INTLIT RPAREN!)?
(COMMA! IDENT (lb:LPAREN INTLIT RPAREN)? )*
;

And how do I solute this problem?


More information about the antlr-interest mailing list