Package org.vedantatree.expressionoasis
Class Compiler
- java.lang.Object
-
- org.vedantatree.expressionoasis.Compiler
-
public class Compiler extends Object
This class performs the compilation operation in expression evaluation process.
It parses the expression using Parser, which returns it list of expression tokens as per rules specified with DefaultXMLGrammar. Compiler restructure these tokens in Reverse Polish Notation and then create the Expression Object's tree for all the tokens. TODO Precedence can be stored with Token itself during parsing process - probably not much benefit as precedence is not used repeatedly can we set operator, function etc values to token itself from parsing process? Give example of expression compilation and expression tree- Since:
- 3.1
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Expression
compile(String expression, ExpressionContext expressionContext, boolean validate)
Builds a tree of Expression objects representing the expression.protected Stack<ExpressionToken>
getTokensInRPN(String expression)
Retrieves a Stack of tokens in RPN that represents the expression
-
-
-
Constructor Detail
-
Compiler
public Compiler()
Constructs the Compiler with default DefaultXMLGrammar Instance
-
Compiler
public Compiler(Grammar grammar)
Constructs the Compiler with specified DefaultXMLGrammar instance.- Parameters:
grammar
- the grammar using which compiler will parse the expression- Throws:
IllegalArgumentException
- if the grammar object is null
-
-
Method Detail
-
getTokensInRPN
protected Stack<ExpressionToken> getTokensInRPN(String expression) throws ExpressionEngineException
Retrieves a Stack of tokens in RPN that represents the expression- Parameters:
expression
- the expression to parse- Returns:
- the stack of restructured Expression Tokens in 'RPN'
- Throws:
ExpressionEngineException
-
compile
public Expression compile(String expression, ExpressionContext expressionContext, boolean validate) throws ExpressionEngineException
Builds a tree of Expression objects representing the expression.- Parameters:
expression
- the string representing the expression to buildexpressionContext
- the object which may contain contextual information for expressions- Returns:
- the tree of expression objects
- Throws:
ExpressionEngineException
-
-