public class ExpressionFactory extends Object
Expressions
. For example:BinaryOperations
of the several types
'+', '-', '*', '/', '^' (power), e.g.: a+b, a-b, a*b, a/b, a^bUnaryOperations
of the several types
'+', '-', e.g.: +a, -aFunctionCalls
of Predefined-
and UserDefinedFunctions
, e.g.:
f(a), sin(a)Symbols
: variable identifiers or constant values, e.g.: a, 1.Parser
to create all needed
Expressions
to build an expression-tree-hirarchy.ExpressionConfiguration
Constructor and Description |
---|
ExpressionFactory(DefinitionModel defModel)
Creates a new
ExpressionFactory instance. |
Modifier and Type | Method and Description |
---|---|
Expression |
createBinaryOperation(Expression firstOp,
Expression secondOp,
int i)
Added for javacc generated parser.
|
Expression |
createBinaryOperation(int i)
Creates and returns a new
BinaryOperation with the type
i and a default priority. |
Expression |
createFunctionCall(String functionName)
Creates and returns a new
FunctionCall with the specified
String as the name of the Function which is calling
and a default priority. |
Expression |
createFunctionCall(String functionName,
List param)
Added for javacc generated parser.
|
Expression |
createImplicitMultOperation()
Creates and returns a new
BinaryOperation with the type '*' and a
default priority. |
Expression |
createImplicitOperation(Expression lastExp)
Either creates and returns a new
FunctionCall by calling
the method createFunctionCall(String)
or calls createImplicitMultOperation()
to return a new BinaryOperation with the type '*'. |
Expression |
createList()
Added for javacc generated parser (and only because of consistency).
|
Expression |
createSymbol(double d)
Creates and returns a new
Symbol representing a constant number
with the value d . |
Expression |
createSymbol(String s)
|
Expression |
createUnaryOperation(Expression operand,
int i)
Added for javacc generated parser.
|
Expression |
createUnaryOperation(int i)
Creates and returns a new
UnaryOperation with the type
i and a default priority. |
String |
getFunctionName(Expression expr)
Added for javacc generated parser.
|
public ExpressionFactory(DefinitionModel defModel)
ExpressionFactory
instance.
The specified DefinitionModel
is important for this
ExpressionFactory
to know
about all defined Functions
. That provides the ability to
decide if a certain parsed identifier is a Symbol
in an implicit
multiplication or a FunctionCall
, e.g.:FunctionCall
, if 'f' is
defined as a Function
in the DefintionModel
.
Otherwise it will be parsed to a BinaryOperation
'f*2'.defModel
- the DefinitionModel
holding all
Functions
comparing a certain parsed identifier against
to decide between a FunctionCall
or a
BinaryOperation
.ExpressionConfiguration.defineFunction(String,String[],String)
,
DefinitionModel.containsFunction(String)
,
createImplicitOperation(Expression)
public Expression createBinaryOperation(Expression firstOp, Expression secondOp, int i)
public Expression createBinaryOperation(int i)
BinaryOperation
with the type
i
and a default priority.i
- the ASCI-Code for the several BinaryOperation
types
('+', '-', '*', '/' or '^').BinaryOperation
with the type
i
and a default priority.UnsupportedOperationException
- if i
is no ASCII-Code
for '+', '-', '*' ,'/' or '^'.BinaryOperation.getType()
,
Expression.getPriority()
public Expression createFunctionCall(String functionName)
FunctionCall
with the specified
String
as the name of the Function
which is calling
and a default priority.functionName
- the name of the Function
which is
calling.FunctionCall
with a default priority.Expression.getPriority()
public Expression createFunctionCall(String functionName, List param)
public Expression createImplicitMultOperation()
BinaryOperation
with the type '*' and a
default priority.BinaryOperation
with the type '*' and a
default priority.BinaryOperation.getType()
,
Expression.getPriority()
public Expression createImplicitOperation(Expression lastExp)
FunctionCall
by calling
the method createFunctionCall(String)
or calls createImplicitMultOperation()
to return a new BinaryOperation
with the type '*'.
The DefinitionModel
will be searched for defined
Functions
to decide
between function call or implicit multiplication.lastExp
- the left operand of the implicit operation.FunctionCall
if lastExp
is a
Symbol
representing the name of a defined Function
,
otherwise it returns a new BinaryOperation
of type '*'.Symbol.toString()
,
DefinitionModel.containsFunction(String)
public Expression createList()
public Expression createSymbol(double d)
Symbol
representing a constant number
with the value d
.d
- the constant value the created
Symbol
will be representing.Symbol
representing a constant number
with the value d
.public Expression createSymbol(String s)
Symbol
representing a Variable
with the name s
. Note that this Symbol
will
maybe converted into a FunctionCall
if an implicit operation is
detected at the next step of parsing.s
- the name of the Variable
the created
Symbol
will be representing.Symbol
representing a Variable
with the name s
.createImplicitOperation(Expression)
public Expression createUnaryOperation(Expression operand, int i)
public Expression createUnaryOperation(int i)
UnaryOperation
with the type
i
and a default priority.i
- the ASCI-Code for the several UnaryOperation
types
('+' or '-').UnaryOperation
with the type
i
and a default priority.UnsupportedOperationException
- if i
is no ASCII-Code
for '+' or '-'.UnaryOperation.getType()
,
Expression.getPriority()
public String getFunctionName(Expression expr)