1 33 34 35 package bsh; 36 37 40 class BSHWhileStatement extends SimpleNode implements ParserConstants 41 { 42 public boolean isDoStatement; 43 44 BSHWhileStatement(int id) { super(id); } 45 46 public Object eval( CallStack callstack, Interpreter interpreter) 47 throws EvalError 48 { 49 int numChild = jjtGetNumChildren(); 50 51 SimpleNode condExp, body = null; 53 54 if ( isDoStatement ) { 55 condExp = (SimpleNode)jjtGetChild(1); 56 body =(SimpleNode)jjtGetChild(0); 57 } else { 58 condExp = (SimpleNode)jjtGetChild(0); 59 if ( numChild > 1 ) body =(SimpleNode)jjtGetChild(1); 61 } 62 63 boolean doOnceFlag = isDoStatement; 64 while( 65 doOnceFlag || 66 BSHIfStatement.evaluateCondition(condExp, callstack, interpreter ) 67 ) 68 { 69 if ( body == null ) continue; 71 72 Object ret = body.eval(callstack, interpreter); 73 74 boolean breakout = false; 75 if(ret instanceof ReturnControl) 76 { 77 switch(((ReturnControl)ret).kind ) 78 { 79 case RETURN: 80 return ret; 81 82 case CONTINUE: 83 continue; 84 85 case BREAK: 86 breakout = true; 87 break; 88 } 89 } 90 if(breakout) 91 break; 92 93 doOnceFlag = false; 94 } 95 96 return Primitive.VOID; 97 } 98 99 } 100 | Popular Tags |