Java Reference
In-Depth Information
The engine will return a
Double object as the result of the
expression
Operands in an expression may be passed to the engine using
global scope or engine scope bindings of the engine
It should allow executing scripts from a
String object and a
java.io.Reader object. However, a Reader should have only one
expression as its contents
Invocable and Compilable interfaces
Using these rules, some valid expressions for your script engine are as follows:
It will not implement the
10 + 90
10.7 + 89.0
+10 + +90
num1 + num2
num1 * num2
78.0 / 7.5
You need to provide implementation for the following two interfaces when you
implement a script engine:
javax.script.ScriptEngineFactory
javax.script.ScriptEngine
As part of your implementation for the JKScript script engine, you will develop
three classes as listed in Table 8-1 . In subsequent sections, you will develop these classes.
Table 8-1. The List of Classes to be Developed for the JKScript Script Engine
Class
Description
Expression The Expression class is the heart of your script engine. It
performs the work of parsing and evaluating an arithmetic
expression. It is used inside the eval() methods of the
JKScriptEngine class.
JKScriptEngine An implementation of the ScriptEngine interface. It extends
the AbstractScriptEngine class that implements the
ScriptEngine interface. The AbstractScriptEngine class
provides a standard implementation for several versions of the
eval() methods of the ScriptEngine interface. You need to
implement the following two versions of the eval() method:
Object eval(String, ScriptContext)
Object eval(Reader, ScriptContext)
JKScriptEngineFactory An implementation of the ScriptEngineFactory interface.
 
Search WWH ::




Custom Search