philsupertramp/game-math
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
EquationParser Class Reference

#include <EquationParser.h>

Public Member Functions

 EquationParser (std::string in)
 
std::shared_ptr< MathNodecreateAST ()
 

Static Public Member Functions

static std::vector< std::shared_ptr< Symbolic > > buildSymbolSuperSet (const std::vector< std::shared_ptr< Symbolic > > &a, const std::vector< std::shared_ptr< Symbolic > > &b)
 
static std::shared_ptr< OperatorGetOperator (const std::string &valString)
 

Public Attributes

std::vector< std::shared_ptr< Symbolic > > symbols
 storage for symbols, gets cleared on EquationParser::createAST More...
 

Private Member Functions

bool parseSequence (const std::string &c)
 
std::vector< std::string > splitFunctionsOrElementwise (const std::string &in)
 
std::vector< std::string > splitEquation (const std::string &eqString)
 
std::vector< std::string > extractObjects (std::string &eq, const std::vector< std::string > &container)
 

Static Private Member Functions

static std::shared_ptr< FunctionGetFunction (const std::string &valString)
 
static bool isNumber (const std::string &in)
 
static bool isSymbol (const std::string &in)
 
static bool isOperator (const std::string &in)
 
static bool isAny (const std::string &in)
 
static bool isParenthesesOpen (const std::string &in)
 
static bool isParenthesesClose (const std::string &in)
 
static void processCurrentOP (const std::shared_ptr< Operator > &currentOp, std::vector< std::string > &operatorStack, std::vector< std::shared_ptr< MathNode > > &operandStack)
 
static void rearrangeStack (std::vector< std::string > &operatorStack, std::vector< std::shared_ptr< MathNode > > &operandStack)
 

Private Attributes

std::string processString
 equation string to parse More...
 
bool prevWasOperator = true
 flag for parsing process More...
 
bool nextIsNegative = false
 flag for parsing process to detect whether a node is negated More...
 
std::vector< std::string > operatorStack
 operator stack object, used during parsing More...
 
std::vector< std::shared_ptr< MathNode > > operandStack
 operand stack object, used during parsing More...
 

Detailed Description

Parses a given string representation of an equation generates an AST using EquationParser::createAST

Constructor & Destructor Documentation

◆ EquationParser()

EquationParser::EquationParser ( std::string  in)
inlineexplicit

Default constructor

Member Function Documentation

◆ buildSymbolSuperSet()

static std::vector< std::shared_ptr< Symbolic > > EquationParser::buildSymbolSuperSet ( const std::vector< std::shared_ptr< Symbolic > > &  a,
const std::vector< std::shared_ptr< Symbolic > > &  b 
)
inlinestatic

helper method to generate superset of given vectors

Parameters
aset of symbols
bother set of symbols
Returns
merged unique set of symbols

◆ createAST()

std::shared_ptr< MathNode > EquationParser::createAST ( )

Creates A(bstract)S(yntax)T(ree) using shunting-yard algorithm, thanks Mr. Dijkstra :) https://en.wikipedia.org/wiki/Shunting-yard_algorithm

Parameters
processString
Returns

◆ extractObjects()

std::vector< std::string > EquationParser::extractObjects ( std::string &  eq,
const std::vector< std::string > &  container 
)
private

extracts given objects from given equation string

Parameters
eqequation string
containercontainer containing objects to search for
Returns
extracted objects

◆ GetFunction()

static std::shared_ptr< Function > EquationParser::GetFunction ( const std::string &  valString)
inlinestaticprivate

Lexer function to detect a Function node.

Parameters
valStringelement of DefaultFunctions vector
Returns

◆ GetOperator()

static std::shared_ptr< Operator > EquationParser::GetOperator ( const std::string &  valString)
inlinestatic

Lexer function to determine first connecting operator

Parameters
valString
Returns

◆ isAny()

static bool EquationParser::isAny ( const std::string &  in)
inlinestaticprivate

test if value is anything processable

Parameters
in
Returns

◆ isNumber()

static bool EquationParser::isNumber ( const std::string &  in)
inlinestaticprivate

tests if value is number

Parameters
in
Returns

◆ isOperator()

static bool EquationParser::isOperator ( const std::string &  in)
inlinestaticprivate

test if value is operator

Parameters
in
Returns

◆ isParenthesesClose()

static bool EquationParser::isParenthesesClose ( const std::string &  in)
inlinestaticprivate

test if value is parentheses close

Parameters
in
Returns

◆ isParenthesesOpen()

static bool EquationParser::isParenthesesOpen ( const std::string &  in)
inlinestaticprivate

test if value is parentheses open

Parameters
in
Returns

◆ isSymbol()

static bool EquationParser::isSymbol ( const std::string &  in)
inlinestaticprivate

tests if value is symbol

Parameters
in
Returns

◆ parseSequence()

bool EquationParser::parseSequence ( const std::string &  c)
inlineprivate

parses a sequence, can be a Function, Operator, Number, Symbol or ANY

Parameters
csequence to parse
Returns
success

◆ processCurrentOP()

static void EquationParser::processCurrentOP ( const std::shared_ptr< Operator > &  currentOp,
std::vector< std::string > &  operatorStack,
std::vector< std::shared_ptr< MathNode > > &  operandStack 
)
staticprivate

process current operator until end of equation, next operator with higher priority or closing parentheses

Parameters
operatorStackcurrent operator stack object
operandStackcurrent operand stack
currentOpthe operator to process

◆ rearrangeStack()

static void EquationParser::rearrangeStack ( std::vector< std::string > &  operatorStack,
std::vector< std::shared_ptr< MathNode > > &  operandStack 
)
staticprivate

rearranges stack until end of equation of opening parentheses

Parameters
operatorStackoperator stack object
operandStackoperand stack object

◆ splitEquation()

std::vector< std::string > EquationParser::splitEquation ( const std::string &  eqString)
private

Splits an equation string into a vector of strings

Parameters
eqStringequation string to split
Returns
vector with equation elements

◆ splitFunctionsOrElementwise()

std::vector< std::string > EquationParser::splitFunctionsOrElementwise ( const std::string &  in)
inlineprivate

Recursively split of input string into function/symbol/operator/numerical substrings.

Parameters
processString
Returns

Member Data Documentation

◆ nextIsNegative

bool EquationParser::nextIsNegative = false
private

flag for parsing process to detect whether a node is negated

◆ operandStack

std::vector<std::shared_ptr<MathNode> > EquationParser::operandStack
private

operand stack object, used during parsing

◆ operatorStack

std::vector<std::string> EquationParser::operatorStack
private

operator stack object, used during parsing

◆ prevWasOperator

bool EquationParser::prevWasOperator = true
private

flag for parsing process

◆ processString

std::string EquationParser::processString
private

equation string to parse

◆ symbols

std::vector<std::shared_ptr<Symbolic> > EquationParser::symbols

storage for symbols, gets cleared on EquationParser::createAST


The documentation for this class was generated from the following file: