31 std::vector<std::shared_ptr<Symbolic>>
symbols;
46 const std::vector<std::shared_ptr<Symbolic>>& a,
const std::vector<std::shared_ptr<Symbolic>>& b) {
47 std::vector<std::shared_ptr<Symbolic>> out = a;
48 auto testIsInContainer = [&out](
const std::shared_ptr<Symbolic>& sym) {
49 for(
const auto& elem : out) {
50 if(
bool(strcmp(elem->value, sym->value) == 0) && elem->isNegative == sym->isNegative)
return true;
55 size_t numElements = out.size();
56 for(
const auto& i : b) {
57 if(!testIsInContainer(i)) {
80 static std::shared_ptr<Operator>
GetOperator(
const std::string& valString) {
81 if(valString.empty()) {
return {}; }
82 if(valString.size() > 1) {
return GetFunction(valString); }
83 switch(
int(
strip(valString).c_str()[0])) {
84 case int(OperatorValue::VALUE_MULTIPLICATION):
return GenerateOperator(OperatorType::TYPE_MULTIPLICATION);
85 case int(OperatorValue::VALUE_DIVISION):
return GenerateOperator(OperatorType::TYPE_DIVISION);
86 case int(OperatorValue::VALUE_ADDITION):
return GenerateOperator(OperatorType::TYPE_ADDITION);
87 case int(OperatorValue::VALUE_SUBTRACTION):
return GenerateOperator(OperatorType::TYPE_SUBTRACTION);
88 case int(OperatorValue::VALUE_POWER):
return GenerateOperator(OperatorType::TYPE_POWER);
89 case int(OperatorValue::VALUE_PARENTHESES_OPEN):
return GenerateOperator(OperatorType::TYPE_PARENTHESES_OPEN);
90 case int(OperatorValue::VALUE_PARENTHESES_CLOSE):
return GenerateOperator(OperatorType::TYPE_PARENTHESES_CLOSE);
102 std::string copy = c;
104 auto sym = std::make_shared<Number>(copy);
114 auto symbol = std::make_shared<Symbolic>(copy);
126 if(currentOp->value[0] ==
'-') {
136 }
else if(
isAny(copy)) {
140 std::cerr <<
"Error detecting character " << copy << std::endl;
152 static std::shared_ptr<Function>
GetFunction(
const std::string& valString) {
163 std::vector<std::string> out;
166 std::vector<std::string> functionNames;
168 for(
const auto& elem :
DefaultFunctions) { functionNames.push_back(elem.first); }
170 out.insert(out.end(), res.begin(), res.end());
172 std::vector<std::string> constantNames;
174 for(
const auto& elem :
DefaultSymbols) { constantNames.push_back(elem.first); }
176 out.insert(out.end(), res.begin(), res.end());
180 out.insert(out.end(), remainingPart.begin(), remainingPart.end());
199 static auto numberRegex =
GetRegex(MathNodeType::NodeType_Numeric);
201 return std::regex_match(in.c_str(), m, numberRegex);
209 static auto symbolRegex =
GetRegex(MathNodeType::NodeType_Symbolic);
211 return std::regex_match(in.c_str(), m, symbolRegex);
219 static auto operatorRegex =
GetRegex(MathNodeType::NodeType_Operator);
221 return std::regex_match(in.c_str(), m, operatorRegex);
228 static bool isAny(
const std::string& in) {
229 static auto anyRegex =
GetRegex(MathNodeType::NodeType_Any);
231 return std::regex_match(in.c_str(), m, anyRegex);
238 static bool isParenthesesOpen(
const std::string& in) {
return in.find(
'(') != std::string::npos; };
253 const std::shared_ptr<Operator>& currentOp,
272 std::vector<std::string>
extractObjects(std::string& eq,
const std::vector<std::string>& container);
std::regex GetRegex(MathNodeType type)
static std::map< std::string, std::shared_ptr< Symbolic > > DefaultSymbols
Definition: Operand.h:66
bool isConstant(const std::string &in)
bool hasSymbol(const std::vector< std::shared_ptr< Symbolic > > &container, const std::shared_ptr< Symbolic > &sym)
std::shared_ptr< Operator > GenerateOperator(OperatorType type)
const std::map< std::string, std::shared_ptr< Function > > DefaultFunctions
Definition: Operator.h:161
bool isFunction(const std::string &in)
Definition: EquationParser.h:15
bool prevWasOperator
flag for parsing process
Definition: EquationParser.h:21
std::shared_ptr< MathNode > createAST()
EquationParser(std::string in)
Definition: EquationParser.h:36
static bool isParenthesesClose(const std::string &in)
Definition: EquationParser.h:244
std::vector< std::shared_ptr< Symbolic > > symbols
storage for symbols, gets cleared on EquationParser::createAST
Definition: EquationParser.h:31
static bool isAny(const std::string &in)
Definition: EquationParser.h:228
bool nextIsNegative
flag for parsing process to detect whether a node is negated
Definition: EquationParser.h:23
std::vector< std::string > splitEquation(const std::string &eqString)
std::vector< std::string > splitFunctionsOrElementwise(const std::string &in)
Definition: EquationParser.h:162
std::vector< std::string > extractObjects(std::string &eq, const std::vector< std::string > &container)
std::vector< std::string > operatorStack
operator stack object, used during parsing
Definition: EquationParser.h:25
std::string processString
equation string to parse
Definition: EquationParser.h:17
static bool isNumber(const std::string &in)
Definition: EquationParser.h:198
static std::shared_ptr< Operator > GetOperator(const std::string &valString)
Definition: EquationParser.h:80
static void rearrangeStack(std::vector< std::string > &operatorStack, std::vector< std::shared_ptr< MathNode > > &operandStack)
static std::vector< std::shared_ptr< Symbolic > > buildSymbolSuperSet(const std::vector< std::shared_ptr< Symbolic > > &a, const std::vector< std::shared_ptr< Symbolic > > &b)
Definition: EquationParser.h:45
static bool isParenthesesOpen(const std::string &in)
Definition: EquationParser.h:238
static void processCurrentOP(const std::shared_ptr< Operator > ¤tOp, std::vector< std::string > &operatorStack, std::vector< std::shared_ptr< MathNode > > &operandStack)
bool parseSequence(const std::string &c)
Definition: EquationParser.h:101
static bool isOperator(const std::string &in)
Definition: EquationParser.h:218
static std::shared_ptr< Function > GetFunction(const std::string &valString)
Definition: EquationParser.h:152
static bool isSymbol(const std::string &in)
Definition: EquationParser.h:208
std::vector< std::shared_ptr< MathNode > > operandStack
operand stack object, used during parsing
Definition: EquationParser.h:27