Java Reference
In-Depth Information
return
return stack . pop () + stack . pop ();
}
iif ( tok . equals ( "-" )) {
final
final Integer tos = stack . pop ();
return
return stack . pop () - tos ;
}
iif ( tok . equals ( "*" )) {
return
return stack . pop () * stack . pop ();
}
iif ( tok . equals ( "/" )) {
final
final Integer tos = stack . pop ();
return
return stack . pop () / tos ;
}
// else ... check for other operators
// If nothing else, must be a name. get and stack its value
stack . push (( Integer ) context . getAttribute ( tok ));
}
return
return 0 ;
}
@Override
public
public Object eval ( Reader reader , ScriptContext context )
throws
throws ScriptException {
System . out . println ( "CalcScriptEngine.eval()" );
// should read the file into a String, then
// return eval(scriptString, context);
throw
throw new
new IllegalStateException ( "eval(Reader) not written yet" );
}
@Override
public
public Bindings createBindings () {
Bindings ret = new
new SimpleBindings ();
return
return ret ;
}
@Override
public
public ScriptEngineFactory getFactory () {
return
return factory ;
}
}
A slightly longer file is the required ScriptEngineFactory implementation:
Search WWH ::




Custom Search