3 public 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 BlockNode getInitializer() {
33 public ExpressionNode getCondition() {
37 public BlockNode getUpdate() {
41 public BlockNode getBody() {
45 public String printNode(int indent) {
47 return "for("+initializer.printNode(0)+";"+condition.printNode(0)+
48 ";"+update.printNode(0)+") "+body.printNode(indent)+"\n";
49 } else if (type==WHILELOOP) {
50 return "while("+condition.printNode(0)+") "+body.printNode(indent+INDENT)+"\n";
51 } else if (type==DOWHILELOOP) {
52 return "do "+ body.printNode(indent+INDENT)+
53 "while("+condition.printNode(0)+")\n";
54 } else throw new Error();
57 public int getType() {