|
ADS
Algorithms and Data Structures
|
The tree of an arithmetic expression (the parse tree), beyond the book: a binary tree [see BinaryTree.h] whose leaves are the operands, numbers or names of variables, and whose internal nodes are the binary operators +, -, *, / and ^ (the power), the left subtree being the left operand. More...
#include "ADS/Contract.h"#include "ADS/stack/ArrayStack.h"#include "ADS/tree/BinaryTree.h"#include <cmath>#include <map>#include <string>#include <string_view>#include <utility>#include <vector>#include "ADS/tree/impl/ExpressionTree.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| BinaryTree< std::string > * | ADS::expressionTree (std::string_view e) |
| the expression tree of the postfix expression \( e \), whose tokens are separated by spaces; the caller owns it | |
| double | ADS::evaluate (const BinaryTree< std::string > *t, const std::map< std::string, double > &env={}) |
| the value of the expression \( t \), with the variables valued by env; a leaf is a number, possibly signed (e.g., -3, +2.5, .5), or a variable | |
| std::string | ADS::prefixForm (const BinaryTree< std::string > *t) |
| the prefix form of \( t \), each subtree in parentheses, by a previsit (section 5.6) | |
| std::string | ADS::infixForm (const BinaryTree< std::string > *t) |
| the infix form of \( t \), fully parenthesized, by an invisit (section 5.6) | |
The tree of an arithmetic expression (the parse tree), beyond the book: a binary tree [see BinaryTree.h] whose leaves are the operands, numbers or names of variables, and whose internal nodes are the binary operators +, -, *, / and ^ (the power), the left subtree being the left operand.
The contracts [see Contract.h]: the postfix expression is well formed, i.e., each operator finds two subtrees and one tree is left; evaluate() needs a value for each variable, and no division by 0. The functions are defined in ExpressionTree.tpp.