[antlr-interest] FOR LOOP

Henry Butowsky henryb at ntlworld.com
Thu Jun 14 07:29:40 PDT 2007


Hi Guys,
Im using C++ ,antlr 2.7.6.
Am having trouble implementing for loops in the parser

This is whats in the parser

for_stmt:
     FOR^ LPAREN! (e1:expr)? SEMI! (e2:expr)? SEMI! (e3:expr)? RPAREN! 
st:statement
         { if(#e1==NULL)  #e1 = #([ NULL_NODE, "null_stmt"]);
           if(#e2==NULL)  #e2 = #([ NULL_NODE, "null_stmt"]);
           if(#e3==NULL)  #e3 = #([ NULL_NODE, "null_stmt"]);
           #for_stmt=#(#[FOR,"for"],e1,e2,e3,st);
         }
     ;

Antlr parses the code , but when I compile I get problems 

The code of the last line is:

for_stmt_AST=ANTLR_USE_NAMESPACE(antlr)RefAST(astFactory->make((new 
ANTLR_USE_NAMESPACE(antlr)ASTArray(5))->add(astFactory->create(tmp20_AST,"for"))->add(e1_AST)->add(e2_AST)->add(e3_AST)->add(st_AST)));
   
The problem it seems that create is expecting tmp20_AST to be an int 
Token when in fact tmp20_AST is an AST node

Has anyone experienced any thing like this ? Am I just being dense ?

Many Thx
Henry


More information about the antlr-interest mailing list