9#include "MantidAPI/DllConfig.h"
18#include <unordered_set>
41 ParsingError(
const std::string &msg,
const std::string &expr,
size_t i);
48 Expression(
const std::vector<std::string> &ops);
50 Expression(
const std::vector<std::string> &binary,
const std::unordered_set<std::string> &unary);
59 void parse(
const std::string &str);
64 void logPrint(
const std::string &pads =
"")
const;
67 std::string str()
const;
69 bool isFunct()
const {
return !m_terms.empty(); }
71 std::string
name()
const {
return m_funct; }
77 const std::vector<Expression> &
terms()
const {
return m_terms; }
79 size_t size()
const {
return m_terms.size(); }
81 using iterator = std::vector<Expression>::const_iterator;
98 std::unordered_set<std::string> getVariables()
const;
104 void renameAll(
const std::string &oldName,
const std::string &newName);
109 void rename(
const std::string &newName);
117 void toList(
const std::string &sep =
",");
142 Token(
size_t i,
size_t j,
size_t k,
size_t p) : is(i), ie(j), is1(k), prec(p) {}
151 std::string GetToken(
size_t i);
153 std::string GetOp(
size_t i);
162 void setFunct(
const std::string &name);
167 static void trim(std::string &str);
181 std::unordered_set<std::string>
unary;
192 size_t op_prec(
const std::string &op)
const;
197 void add_operators(
const std::vector<std::string> &ops);
202 void add_unary(
const std::unordered_set<std::string> &ops);
208 bool is_unary(
const std::string &op)
const;
214 bool is_op_symbol(
const char c)
const;
Specialised exception for parsing errors.
This class represents an expression made up of names, binary operators and brackets.
std::string name() const
Returns the name of the expression which is a function or variable name.
std::string m_expr
Saved expression string.
const std::vector< Expression > & terms() const
Returns the top level terms of the expression (function arguments).
std::shared_ptr< Operators > m_operators
pointer ot the operators
std::string operator_name() const
Returns the the expression's binary operator on its left.
std::string m_op
Operator connecting this expression to its sibling on the left.
std::string m_funct
Function name.
iterator end() const
An iterator pointing to the end of the expressions.
Expression & operator=(const Expression &expr)
Assignment operator.
bool isFunct() const
Returns true if the expression is a function (i.e. has arguments)
const Expression & operator[](size_t i) const
Gets the Expression at the specified index.
std::vector< Token > Tokens
The container type.
iterator begin() const
An iterator pointing to the start of the expressions.
std::vector< Expression >::const_iterator iterator
Const Iterator tpyedef.
Tokens m_tokens
The container for the token markers.
size_t size() const
Returns the number of argumens.
std::vector< Expression > m_terms
Child expressions (function arguments)
static const std::vector< std::string > DEFAULT_OPS_STR
Helper class which provides the Collimation Length for SANS instruments.
Keeps operator that can be used in an expression.
std::map< std::string, size_t > precedence
Map of the operator precedence order.
std::vector< std::string > binary
Binary operators in reverse precedence order.
std::unordered_set< std::string > unary
Unary operators.
std::unordered_set< char > symbols
All the symbols that are used in the binary operators.
std::map< std::string, char > op_number
map of operators
This is a struct to mark a token in a string expression.
size_t prec
The precedence of the connecting operator.
size_t is1
The index of the first symbol of the next token.
size_t is
The index of the first symbol of the token.
size_t ie
The index of the last symbol of the token.
Token(size_t i, size_t j, size_t k, size_t p)
Constructor.