[antlr-interest] need example for executing an if statement

Scott Fortmann-Roe sfortma1 at swarthmore.edu
Sat Mar 31 16:12:50 PDT 2007


ifStmt
@after{
   CommonTree stmtNode;
   if ($v.value==1){
       stmtNode = (CommonTree)$ifStmt.start.getChild(1);
   }else{
       stmtNode = (CommonTree)$ifStmt.start.getChild(2);
   }
       stream.push(stream.getNodeIndex(stmtNode));
       stmt();
       stream.pop();
}
   :    ^(IF ^(EXPR v=expr) . .)
   ;

expr returns 1 if true. the second child of the if node is the first
if clause, the third node is the else clause. both are stmt's.

-scott

On 3/31/07, Dave Cramer <davec at postgresintl.com> wrote:
> Are there any examples around for a treewalker implementation of an
> if statement ?
>
> Dave
>
>


-- 
Scott Fortmann-Roe
500 College Ave
Swarthmore, Pa 19081
(510) 866-5296


More information about the antlr-interest mailing list