1 33 34 35 package bsh; 36 37 class BSHPrimaryExpression extends SimpleNode 38 { 39 BSHPrimaryExpression(int id) { super(id); } 40 41 44 public Object eval( CallStack callstack, Interpreter interpreter) 45 throws EvalError 46 { 47 return eval( false, callstack, interpreter ); 48 } 49 50 53 public LHS toLHS( CallStack callstack, Interpreter interpreter) 54 throws EvalError 55 { 56 Object obj = eval( true, callstack, interpreter ); 57 58 if ( ! (obj instanceof LHS) ) 59 throw new EvalError("Can't assign to:", this, callstack ); 60 else 61 return (LHS)obj; 62 } 63 64 72 private Object eval( boolean toLHS, 73 CallStack callstack, Interpreter interpreter) 74 throws EvalError 75 { 76 Object obj = jjtGetChild(0); 77 int numChildren = jjtGetNumChildren(); 78 79 for(int i=1; i<numChildren; i++) 80 obj = ((BSHPrimarySuffix)jjtGetChild(i)).doSuffix( 81 obj, toLHS, callstack, interpreter); 82 83 87 if ( obj instanceof SimpleNode ) 88 if ( obj instanceof BSHAmbiguousName ) 89 if ( toLHS ) 90 obj = ((BSHAmbiguousName)obj).toLHS( 91 callstack, interpreter); 92 else 93 obj = ((BSHAmbiguousName)obj).toObject( 94 callstack, interpreter); 95 else 96 if ( toLHS ) 98 throw new EvalError("Can't assign to prefix.", 100 this, callstack ); 101 else 102 obj = ((SimpleNode)obj).eval(callstack, interpreter); 103 104 if ( obj instanceof LHS ) 106 if ( toLHS ) 107 return obj; 108 else 109 try { 110 return ((LHS)obj).getValue(); 111 } catch ( UtilEvalError e ) { 112 throw e.toEvalError( this, callstack ); 113 } 114 else 115 return obj; 116 } 117 } 118 119 | Popular Tags |