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

Package Functions

Expression getExpression (String line, boolean profileMe) throws JasmineException
 

Static Package Functions

static CompileExpression getInstance ()
 

Static Package Attributes

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

Private Member Functions

 CompileExpression ()
 
List< Expparse (String line) throws JasmineException
 
Exp getExp (OperatorSet exprs, int type, String sequence, HashMap< String, Integer > indices)
 
Exp convertToAST (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 CompileExpression 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 Expressions.

To evaluate an algorithm there are a number of steps

  1. Initialise the expression compiler
  2. Compile the expression
    • Parse the expression string to infix order
    • Create the Abstract Syntax Tree (AST)
    • Create the Java byte code for the Expression object to evaluate the expression
  3. Evaluate the expression.

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 expression 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.CompileExpression.CompileExpression ( )
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.CompileExpression.addNode ( Deque< Exp operandStack,
Exp  operator 
) throws JasmineException
private

Add a token to the AST

Exp org.quark.jasmine.CompileExpression.convertToAST ( List< Exp infix) throws JasmineException
private

Convert the infix list to AST (abstract syntax tree)

Exp org.quark.jasmine.CompileExpression.getExp ( OperatorSet  exprs,
int  type,
String  sequence,
HashMap< String, Integer >  indices 
)
private

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

Expression org.quark.jasmine.CompileExpression.getExpression ( String  line,
boolean  profileMe 
) throws JasmineException
package

Create and return the Expression.

Parameters
linesthe Expression to compile
profileMeif true record the evaluation time
Returns
the Expression object or null
Exceptions
JasmineException
static CompileExpression org.quark.jasmine.CompileExpression.getInstance ( )
staticpackage

Get the singleton instance.

List<Exp> org.quark.jasmine.CompileExpression.parse ( String  line) 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: