Class implementing a factory that makes univariate expression trees from expressions given as strings.
More...
|
| UnivarExprTreeStringFactory () |
| Default constructor for univariate expression tree string factory.
|
|
IExprTreeNode< NumericType, NumericType > * | make (std::string const &expr) override |
| Make an expression tree from given expression as string. More...
|
|
virtual IExprTreeNode< NumericType, NumericType > * | makeIterative (std::string const &expr) |
| Iteratively built the corresponding expression tree node from given expression. More...
|
|
virtual void | flush () |
| Flush the current state of the factory. More...
|
|
void | doIPowOptimization (UnivarExprTreeNode< NumericType > *node) |
| Transform all POW nodes that are either the given node or a child of it into IPOW nodes. More...
|
|
virtual void | handleOp (Symbol const &symbol) |
| Handle parsed operator. More...
|
|
virtual void | handleFun (Symbol const &symbol) |
| Handle parsed function. More...
|
|
unsigned int | calcOpPriority (Symbol const &symbol) |
| Calculate the corresponding priority considering current base priority and given operator. More...
|
|
unsigned int | calcFunPriority () |
| Calculate the corresponding priority considering current base priority and a function. More...
|
|
unsigned int | calcOpenBracketPriority () |
| Calculate the corresponding priority considering current base priority and the push of an opening bracket. More...
|
|
unsigned int | calcCloseBracketPriority () |
| Calculate the corresponding bracket priority considering current base priority and the pop of an opening bracket (which happens because a close bracket has been read) More...
|
|
Symbol | nextSymbol (std::string const &expr) |
| Obtain the first symbol (token) parsed starting at the \(0\) character. More...
|
|
std::string | prepareExpressionString (std::string const &expr) |
| Prepare the expression string so it can be digested by an iterative make process. More...
|
|
std::string | cleanExpressionString (std::string const &expr) |
| Clean the expression string from unnecessary characters. More...
|
|
std::string | stringFromNumber (NumericType const x, std::streamsize const precision=16) |
| Represent the given number as a string. More...
|
|
Symbol | craftFunSymbol (std::string const &symstr) |
| Craft a function symbol from given string. More...
|
|
Symbol | craftNumSymbol (std::string const &expr) |
| Craft the NON-NEGATIVE numeric symbol represented by an arbitrary size string for which the first character is guaranteed to be the start of the represented number. More...
|
|
bool | isValidOpString (std::string const &opStr) |
| Check whether the given string is representing a valid operator (true) or not (false). More...
|
|
bool | isValidFunString (std::string const &funStr) |
| Check whether the given string is representing a valid function (true) or not (false). More...
|
|
std::shared_ptr< IExprTreeNode< NumericType, NumericType > > | makeShared (std::string const &expr) |
| Like IExprTreeNodeStringFactory::make but returning a shared pointer instead of a raw pointer. More...
|
|
template<typename NumericType>
class UnivarExprTreeStringFactory< NumericType >
Class implementing a factory that makes univariate expression trees from expressions given as strings.
- Author
- Alberto M. Esmoris Pena
- Version
- 1.0
The expression strings are expected as infix expressions (infix notation).
Infix expression example: \(a + b\)
Prefix expression example: \(+ a b\)
Postfix expression example: \(a b +\)
The core implementation of the expression tree is based on two sets of logical rules that specify how push and pop operations must be handled.
First, when one of the the following logical rules is satisfied, the algorithm must stop reading and do the corresponding operations to push new trees built from popped operators and trees.
-
Reading a closing priority operator (e.g., ')')
-
Reading an operator whose priority is less than or equal to the priority of the operator at the top of the stack of operators
-
End of reading
Second, when push and pop operations are triggered, they must stop depending on why they have been triggered.
-
If ')' has been read, then all the elements in the stack of operators must be pop until the corresponding '(' has been reached (inclusive).
-
If an operator with priority less than or equal to the priority of the operator in the top of the stack has been read, then all the operators in the stack with a priority greater than or equal to read operator must be popped.
-
If reading has finished, then all the operators in the stack must be consumed and consequently there must be a single tree in the stack of nodes/trees (otherwise the generated expression try will be inconsistent).
- Template Parameters
-
NumericType | The numeric type of expression trees to be built by the factory |
- See also
- UnivarExprTreeNode
-
IExprTreeNodeStringFactory