1 #ifndef _UNIVAREXPRTREESTRINGFACTORY_H_
2 #define _UNIVAREXPRTREESTRINGFACTORY_H_
5 #include <adt/exprtree/UnivarExprTreeNode.h>
6 #include <adt/exprtree/IExprTreeNodeStringFactory.h>
7 #include <util/HeliosException.h>
61 template <
typename NumericType>
128 std::vector<UnivarExprTreeNode<NumericType> *>
nodes;
154 std::string
const &expr
165 std::string
const &expr
221 if(symbol.
str ==
"+" || symbol.
str ==
"-")
223 else if(symbol.
str ==
"*" || symbol.
str ==
"/")
225 else if(symbol.
str ==
"^")
231 "UnivarExprTreeStringFactory::calcOpPriority received an "
232 "unexpected operator as input"
304 std::streamsize
const precision=16
329 return opStr ==
"+" || opStr ==
"-" || opStr ==
"*" ||
330 opStr ==
"/" || opStr ==
"^" || opStr ==
"(" ||
331 opStr ==
")" || opStr ==
"atan2"
342 return funStr ==
"exp" || funStr ==
"ln" ||
343 funStr ==
"sqrt" || funStr ==
"abs" ||
344 funStr ==
"cos" || funStr ==
"sin" ||
345 funStr ==
"tan" || funStr ==
"acos" ||
346 funStr ==
"asin" || funStr ==
"atan" ||
347 funStr ==
"cosh" || funStr ==
"sinh" ||
352 #include <adt/exprtree/UnivarExprTreeStringFactory.tpp>
Base class for Helios exceptions.
Definition: HeliosException.h:12
Interface defining the functions that must be provided by any concrete implementation of a factory th...
Definition: IExprTreeNodeStringFactory.h:19
Class implementing a Univariate Expression Tree Node.
Definition: UnivarExprTreeNode.h:27
SymbolType
The different types of element (symbols) supported by the univariate expression tree node.
Definition: UnivarExprTreeNode.h:35
Class implementing a factory that makes univariate expression trees from expressions given as strings...
Definition: UnivarExprTreeStringFactory.h:63
std::string prepareExpressionString(std::string const &expr)
Prepare the expression string so it can be digested by an iterative make process.
UnivarExprTreeStringFactory()
Default constructor for univariate expression tree string factory.
Definition: UnivarExprTreeStringFactory.h:140
std::string cleanExpressionString(std::string const &expr)
Clean the expression string from unnecessary characters.
static std::string const FUNCTION_NAMES[]
Supported functions by name.
Definition: UnivarExprTreeStringFactory.h:94
bool lastReadIsOpenPriorityOrSeparator
True when the last read has been a priority operator or a separator, false otherwise.
Definition: UnivarExprTreeStringFactory.h:124
unsigned int calcFunPriority()
Calculate the corresponding priority considering current base priority and a function.
Definition: UnivarExprTreeStringFactory.h:242
virtual void flush()
Flush the current state of the factory.
static char const EXPRESSION_CHARS[]
Expected characters in expressions.
Definition: UnivarExprTreeStringFactory.h:90
unsigned int calcCloseBracketPriority()
Calculate the corresponding bracket priority considering current base priority and the pop of an open...
Definition: UnivarExprTreeStringFactory.h:261
static unsigned int const OP_ADD_BASE_PRIORITY
The base priority for addition and subtraction operators.
Definition: UnivarExprTreeStringFactory.h:70
Symbol nextSymbol(std::string const &expr)
Obtain the first symbol (token) parsed starting at the character.
void doIPowOptimization(UnivarExprTreeNode< NumericType > *node)
Transform all POW nodes that are either the given node or a child of it into IPOW nodes.
static unsigned int const BRACKET_BASE_PRIORITY
The base priority for brackets.
Definition: UnivarExprTreeStringFactory.h:86
std::vector< UnivarExprTreeNode< NumericType > * > nodes
The nodes at current state (must be used as a stack)
Definition: UnivarExprTreeStringFactory.h:128
unsigned int calcOpenBracketPriority()
Calculate the corresponding priority considering current base priority and the push of an opening bra...
Definition: UnivarExprTreeStringFactory.h:251
virtual void handleFun(Symbol const &symbol)
Handle parsed function.
bool isValidOpString(std::string const &opStr)
Check whether the given string is representing a valid operator (true) or not (false).
Definition: UnivarExprTreeStringFactory.h:328
std::vector< Symbol > ops
The operators at current state (must be used as a stack)
Definition: UnivarExprTreeStringFactory.h:132
static unsigned int const FUN_BASE_PRIORITY
The base priority for functions.
Definition: UnivarExprTreeStringFactory.h:82
static unsigned int const OP_POW_BASE_PRIORITY
The base priority for power operators.
Definition: UnivarExprTreeStringFactory.h:78
IExprTreeNode< NumericType, NumericType > * make(std::string const &expr) override
Make an expression tree from given expression as string.
std::string stringFromNumber(NumericType const x, std::streamsize const precision=16)
Represent the given number as a string.
unsigned int basePriority
The base priority at current state.
Definition: UnivarExprTreeStringFactory.h:119
bool isValidFunString(std::string const &funStr)
Check whether the given string is representing a valid function (true) or not (false).
Definition: UnivarExprTreeStringFactory.h:341
unsigned int calcOpPriority(Symbol const &symbol)
Calculate the corresponding priority considering current base priority and given operator.
Definition: UnivarExprTreeStringFactory.h:218
Symbol craftFunSymbol(std::string const &symstr)
Craft a function symbol from given string.
Symbol craftNumSymbol(std::string const &expr)
Craft the NON-NEGATIVE numeric symbol represented by an arbitrary size string for which the first cha...
static unsigned int const OP_MUL_BASE_PRIORITY
The base priority for product and division operators.
Definition: UnivarExprTreeStringFactory.h:74
virtual void handleOp(Symbol const &symbol)
Handle parsed operator.
virtual IExprTreeNode< NumericType, NumericType > * makeIterative(std::string const &expr)
Iteratively built the corresponding expression tree node from given expression.
UnivarExprTreeStringFactory sub-class used to represent symbols during recursive building.
Definition: UnivarExprTreeStringFactory.h:102
UnivarExprTreeNode< NumericType >::SymbolType type
The symbol type.
Definition: UnivarExprTreeStringFactory.h:106
std::string str
The symbol as a string.
Definition: UnivarExprTreeStringFactory.h:110