Jasmine  1.1
Super fast expression and algorithm evaluator
 All Classes Functions
org.quark.jasmine.CompileAlgorithm Class Reference
Inheritance diagram for org.quark.jasmine.CompileAlgorithm:

Package Functions

Algorithm getAlgorithm (String[] lines, boolean profileMe) throws JasmineException
 

Static Package Functions

static CompileAlgorithm getInstance ()
 

Static Package Attributes

static final int COMMENT = 0
 
static final int WHITESPACE = 1
 
static final int FLOAT1 = 2
 
static final int FLOAT2 = 3
 
static final int INT = 4
 
static final int VARIABLE = 5
 
static final int OPERATOR = 6
 

Private Member Functions

 CompileAlgorithm ()
 
List< Expparse (int lineNo, String line, HashMap< String, Double > vars) throws JasmineException
 
Exp getExp (OperatorSet exprs, int type, String sequence, HashMap< String, Double > vars)
 
Deque< ExpconvertToAST (List< Exp > infix) throws JasmineException
 
void addNode (Deque< Exp > operandStack, Exp operator) throws JasmineException
 

Private Attributes

OperatorSet operatorSet = null
 
Pattern[] patterns
 

Static Private Attributes

static CompileAlgorithm instance = null
 

Additional Inherited Members

- Public Attributes inherited from org.quark.jasmine.CompileConstants
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 Public Attributes inherited from org.quark.jasmine.CompileConstants
static String ALGORITHM_CLASS = Type.getInternalName(Algorithm.class)
 
static String ALGORITHM_CLASS_ID = Type.getDescriptor(Algorithm.class)
 

Detailed Description

This is a singleton class used to compile Algorithms.

To evaluate an algorithm there are a number of steps

  1. Initialise the algorithm compiler
  2. 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
  3. 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

Constructor & Destructor Documentation

org.quark.jasmine.CompileAlgorithm.CompileAlgorithm ( )
private

This private constructor gets the operator set to be used and creates the regular expressions used during parsing.

Member Function Documentation

void org.quark.jasmine.CompileAlgorithm.addNode ( Deque< Exp operandStack,
Exp  operator 
) throws JasmineException
private

Add a token to the AST

Deque<Exp> org.quark.jasmine.CompileAlgorithm.convertToAST ( List< Exp infix) throws JasmineException
private

Convert the infix list to AST (abstract syntax tree)

Algorithm org.quark.jasmine.CompileAlgorithm.getAlgorithm ( String[]  lines,
boolean  profileMe 
) throws JasmineException
package

Create and return the Algorithm.

Parameters
linesthe Algorithm to compile
profileMeif true record the evaluation time
Returns
the Algorithm object or null
Exceptions
JasmineException
Exp org.quark.jasmine.CompileAlgorithm.getExp ( OperatorSet  exprs,
int  type,
String  sequence,
HashMap< String, Double >  vars 
)
private

Create a token from a matched sequence of characters. If the characters are 'spaces' then return null.

static CompileAlgorithm org.quark.jasmine.CompileAlgorithm.getInstance ( )
staticpackage

Get the singleton instance.

List<Exp> org.quark.jasmine.CompileAlgorithm.parse ( int  lineNo,
String  line,
HashMap< String, Double >  vars 
) throws JasmineException
private

Parse an expression and return a list of tokens in infix order


The documentation for this class was generated from the following file: