3 class LoopNode extends BlockStatementNode {
5 ExpressionNode condition;
9 public static int FORLOOP=1;
10 public static int WHILELOOP=2;
11 public static int DOWHILELOOP=3;
13 public LoopNode(BlockNode initializer,ExpressionNode condition, BlockNode update, BlockNode body) {
14 this.initializer=initializer;
15 this.condition=condition;
18 initializer.setStyle(BlockNode.EXPRLIST);
19 update.setStyle(BlockNode.EXPRLIST);
23 public LoopNode(ExpressionNode condition, BlockNode body, int type) {
24 this.condition=condition;
29 public String printNode(int indent) {
31 return "for("+initializer.printNode(0)+";"+condition.printNode(0)+
32 ";"+update.printNode(0)+") "+body.printNode(indent)+"\n";
33 } else if (type==WHILELOOP) {
34 return "while("+condition.printNode(0)+") "+body.printNode(indent+INDENT)+"\n";
35 } else if (type==DOWHILELOOP) {
36 return "do "+ body.printNode(indent+INDENT)+
37 "while("+condition.printNode(0)+")\n";
38 } else throw new Error();