Java Reference
In-Depth Information
Chapter 8
Implementing a Script
Engine
In this chapter, you will learn:
•
The components of a script engine that need to be developed
when implementing a new script engine
•
How to implement the different components of a simple script
engine that will perform addition, subtraction, multiplication,
and division on two numbers
•
How to package the code of the script engine
•
How to deploy and test the script engine
Introduction
Implementing a full-blown script engine is no simple task and it is outside the scope
of this topic. This chapter is meant to give you a brief, but complete, overview of the
setup needed to implement a script engine. In this section, you will implement a simple
script engine called the
JKScript
engine. It will evaluate arithmetic expressions with the
following rules:
•
It will evaluate an arithmetic expression that consists of two
operands and one operator
•
The expression may have two number literals, two variables, or
one number literal and one variable as operands. The number
literals must be in decimal format. Hexadecimal, octal, and binary
number literals are not supported
•
The arithmetic operations in an expression are limited to add,
subtract, multiply, and divide
+
,
-
,
*
, and
/
as arithmetic operators
•
It will recognize
Search WWH ::
Custom Search