|
String | GENERATED_ALGORITHM_CLASS = "QuarkAlgorithm" |
|
String | GENERATED_EXPRESSION_CLASS = "QuarkExpression" |
|
String | EXPRESSION_CLASS = Type.getInternalName(Expression.class) |
|
String | EXPRESSION_CLASS_ID = Type.getDescriptor(Expression.class) |
|
String | ANSWER_CLASS = Type.getInternalName(Answer.class) |
|
String | ANSWER_CLASS_ID = Type.getDescriptor(Answer.class) |
|
static String | ALGORITHM_CLASS = Type.getInternalName(Algorithm.class) |
|
static String | ALGORITHM_CLASS_ID = Type.getDescriptor(Algorithm.class) |
|
This is a singleton class used to compile Algorithms.
To evaluate an algorithm there are a number of steps
-
Initialise the algorithm compiler
-
Compile the algorithm
-
Parse the algorithm string to infix order
-
Create the Abstract Syntax Tree (AST)
-
Create the Java byte code for the Algorithm object to evaluate the algorithm
-
Evaluate the algorithm.
Initialising the compiler takes a long time compared to the other steps but fortunately it only done once on the first compilation. Alternatively you can force this step with
Compile.init();
when the application is starting up.
The compilation of the algorithm is faster but the use of variables means it can be done once and evaluated many times with different starting values.
The evaluation is blisteringly fast because it is executing Java byte code
- Author
- Peter Lager