25#ifndef MU_PARSER_BASE_H
26#define MU_PARSER_BASE_H
104 void SetIndex(
unsigned int _nLoopElement);
116 int IsValidByteCode(
unsigned int _nthLoopElement = -1,
unsigned int _nthPartEquation = 0);
165 bool optimizeAway =
true);
186 const std::map<std::string, std::vector<mu::value_type> >&
GetVectors()
const;
202 int a_iPos = (
int)mu::string_type::npos,
206 int a_iPos = (
int)mu::string_type::npos,
210 void SetVectorVar(
const std::string& sVarName,
const std::vector<mu::value_type>& vVar,
bool bAddVectorType =
false);
211 std::vector<mu::value_type>*
GetVectorVar(
const std::string& sVarName);
233 template<
class TChar>
239 : std::numpunct<TChar>()
279 std::vector<mu::value_type>& vResults);
303 int iArgCount)
const;
306 const std::vector<token_type>& a_vArg)
const;
This class is a mutable version of a string view. It can be used to replace single characters or enti...
This class is the immutable (const) version of a string view. It can be constructed from a MutableStr...
A facet class used to change decimal and thousands separator.
virtual char_type do_thousands_sep() const
virtual std::string do_grouping() const
change_dec_sep(char_type cDecSep, char_type cThousandsSep=0, int nGroup=3)
char_type m_cThousandsSep
virtual char_type do_decimal_point() const
Mathematical expressions parser (base parser engine).
varmap_type m_VarDef
user defind variables.
ParserTokenReader token_reader_type
Typedef for the token reader.
const string_type & GetExpr() const
Retrieve the formula.
const char_type * ValidInfixOprtChars() const
Virtual function that defines the characters allowed in infix operator definitions.
bool checkDelimiter(StringView sLine)
This member function checks, whether the passed string is delimited on both sides.
void CacheCurrentAccess(const CachedDataAccess &_access)
Store the passed data access for this position internally.
void StackDump(const ParserStack< token_type > &a_stVal, const ParserStack< token_type > &a_stOprt) const
Dump stack content.
void Assign(const ParserBase &a_Parser)
Copy state of a parser object to this.
void AddValIdent(identfun_type a_pCallback)
Add a value parsing function.
static const char_type * c_DefaultOprt[]
Identifiers for built in binary operators.
void CheckOprt(const string_type &a_sName, const ParserCallback &a_Callback, const string_type &a_szCharSet) const
Check if a name contains invalid characters.
ParseFunction m_pParseFormula
Pointer to the parser function.
void SetDecSep(char_type cDecSep)
Set the decimal separator.
size_t FindMultiArgFunc(StringView sExpr, size_t nPos, std::string &sMultArgFunc)
This function searches for the first multi-argument function found in the passed expression.
unsigned int nthLoopPartEquation
void ApplyBinOprt(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
Performs the necessary steps to write code for the execution of binary operators into the bytecode.
MutableStringView compileVectors(MutableStringView sExpr)
This function pre-evaluates all vectors, which are contained in the expression passed through sExpr.
void SetExpr(StringView a_sExpr)
Set the expression. Triggers first time calculation thus the creation of the bytecode and scanning of...
value_type Eval()
Single-value wrapper around the vectorized overload of this member function.
void CheckName(const string_type &a_strName, const string_type &a_CharSet) const
Check if a name contains invalid characters.
const varmap_type & GetVar() const
Return a map containing the used variables only.
void CacheCurrentTarget(const std::string &sEquation)
Caches the passed target equation for this position.
void Init()
Initialize user defined functions.
stringbuf_type m_vStringBuf
String buffer, used for storing string function arguments.
void AddCallback(const string_type &a_strName, const ParserCallback &a_Callback, funmap_type &a_Storage, const char_type *a_szCharSet)
Add a function or operator callback to the parser.
void ApplyIfElse(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
const CachedDataAccess & GetCachedAccess(size_t nthAccess)
Returns the cached data access for the passed position.
int IsValidByteCode(unsigned int _nthLoopElement=-1, unsigned int _nthPartEquation=0)
This member function returns, whether the current equation is already parsed and there's a valid byte...
static bool g_DbgDumpStack
bool HasBuiltInOprt() const
Query status of built in variables.
void ResetLocale()
Resets the locale.
const std::string & GetCachedEquation() const
Returns the stored equation for this position.
const char_type ** GetOprtDef() const
Get the default symbols used for the built in operators.
void SetIndex(unsigned int _nLoopElement)
Activates the selected position in the internally stored bytecode.
void ParseCmdCodeBulkParallel(size_t nVectorLength)
OpenMP optimized parallel bytecode executor.
StateStacks m_stateStacks
string_type GetVersion(EParserVersionInfo eInfo=pviFULL) const
Returns the version of muparser.
void PauseLoopMode(bool _bPause=true)
This member function pauses the loop mode, so that the new assigned equation does not invalidate alre...
virtual void InitCharSets()=0
bool IsLockedPause() const
Check, whether the pause mode is locked.
void Error(EErrorCodes a_iErrc, int a_iPos=(int) mu::string_type::npos, const string_type &a_strTok=string_type()) const
Create an error containing the parse error position.
void EnableOptimizer(bool a_bIsOn=true)
Enable or disable the formula optimization feature.
vectormap_type mVectorVars
Maximum number of threads spawned by OpenMP when using the bulk mode.
funmap_type m_InfixOprtDef
unary infix operator.
void ApplyFunc(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal, int iArgCount) const
Apply a function token.
const std::string & GetCachedTarget() const
Returns the stored target equation for this position.
unsigned int nCurrVectorIndex
virtual void InitOprt()=0
const valmap_type & GetConst() const
Return a map containing all parser constants.
void DeactivateLoopMode()
Deactivates the loop mode and resets the internal arrays.
void ClearVectorVars(bool bIgnoreProcedureVects=false)
This member function cleares the internal vector storage.
ParserToken< value_type, string_type > token_type
Type used for parser tokens.
const std::map< std::string, std::vector< mu::value_type > > & GetVectors() const
int m_nIfElseCounter
Internal counter for keeping track of nested if-then-else clauses.
const varmap_type & GetUsedVar()
Return a map containing the used variables only.
void DefineStrConst(const string_type &a_sName, const string_type &a_strVal)
Define a new string constant.
valmap_type m_ConstDef
user constants.
bool compileVectorsInMultiArgFunc(MutableStringView &sExpr, size_t &nPos)
This private function will try to find a surrounding multi-argument function, resolve the arguments,...
bool ActiveLoopMode() const
Check, whether the loop mode is active. This function returns true even if the loop mode is paused.
void SetVarFactory(facfun_type a_pFactory, void *pUserData=NULL)
Set a function that can create variable pointer for unknown expression variables.
const funmap_type & GetFunDef() const
Return prototypes of all parser functions.
void ClearInfixOprt()
Clear the user defined Prefix operators.
std::vector< mu::value_type > * GetVectorVar(const std::string &sVarName)
This member function returns a pointer to the vector stored internally.
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
void ParseString()
One of the two main parse functions.
void DefineVar(const string_type &a_sName, value_type *a_fVar)
Add a user defined variable.
void evaluateTemporaryVectors(const VectorEvaluation &vectEval, int nStackSize)
This member function evaluates the temporary vector expressions and assigns their results to their co...
void DefineConst(const string_type &a_sName, value_type a_fVal)
Add a user defined constant.
void RemoveVar(const string_type &a_strVarName)
Remove a variable from internal storage.
funmap_type m_FunDef
Map of function names and pointers.
void DefinePostfixOprt(const string_type &a_strFun, fun_type1 a_pOprt, bool optimizeAway=true)
Add a user defined operator.
funmap_type m_PostOprtDef
Postfix operator callbacks.
bool CanCacheAccess()
Check, whether the current position can cache any data accesses.
funmap_type m_OprtDef
Binary operator callbacks.
void ApplyRemainingOprt(ParserStack< token_type > &a_stOpt, ParserStack< token_type > &a_stVal) const
Apply a binary operator.
bool IsAlreadyParsed(StringView sNewEquation)
This member function checks, whether the passed expression is already parsed, so that the parsing ste...
void ClearOprt()
Clear all user defined binary operators.
int GetOprtPrecedence(const token_type &a_Tok) const
Get operator priority.
virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd)
void replaceLocalVars(std::string &sLine)
This member function replaces var occurences with the names of local variables.
void compileVectorExpansion(MutableStringView sSubExpr, const std::string &sVectorVarName)
This function evaluates the vector expansion, e.g. "{1:4}" = {1, 2, 3, 4}.
bool IsCompiling()
Returns true, if the parser is currently in compiling step.
bool IsNotLastStackItem() const
Check, whether there are more elements on the parsing stack remaining.
virtual void InitConst()=0
string_type m_sInfixOprtChars
Charset for infix operator tokens.
void DefineOprtChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of binary operators and postfix operators.
void LockPause(bool _bLock=true)
This member function locks the pause mode so that it cannot be accidentally activated.
void ActivateLoopMode(unsigned int _nLoopLength)
Activates the loop mode and prepares the internal arrays for storing the necessary data.
ExpressionTarget m_compilingTarget
void DefineInfixOprt(const string_type &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX, bool optimizeAway=true)
Add a user defined operator.
ParserError exception_type
Type of the error class.
void SetThousandsSep(char_type cThousandsSep=0)
Sets the thousands operator.
EOprtAssociativity GetOprtAssociativity(const token_type &a_Tok) const
Get operator priority.
string_type CreateTempVectorVar(const std::vector< mu::value_type > &vVar)
This member function copies the passed vector into the internal storage referencing it with a auto-ge...
void ClearPostfixOprt()
Clear all user defined postfix operators.
void CacheCurrentEquation(const std::string &sEquation)
Caches the passed equation for this position.
void(ParserBase::* ParseFunction)()
Typedef for the parse functions.
void ClearFun()
Clear all functions.
void ParseCmdCode()
Parse the command code.
token_type ApplyStrFunc(const token_type &a_FunTok, const std::vector< token_type > &a_vArg) const
Execute a function that takes a single string argument.
static bool g_DbgDumpCmdCode
void ReInit()
Reset parser to string parsing mode and clear internal buffers.
void DefineInfixOprtChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of infix operators.
ParserBase & operator=(const ParserBase &a_Parser)
Assignement operator.
void UpdateVectorVar(const std::string &sVarName)
This member function updates the corresponding variable of a vector with the previously newly assigne...
size_t HasCachedAccess()
Evaluate, whether there are any cached data accesses for this position.
std::map< std::string, std::string > * mVarMapPntr
void ParseCmdCodeBulk(int nOffset, int nThreadID)
Evaluate the RPN.
void DisableAccessCaching()
Disable the data access caching for this position.
static std::locale s_locale
The locale used by the parser.
std::vector< string_type > stringbuf_type
Type for a vector of strings.
const std::string EMPTYSTRING
bool ContainsVectorVars(StringView sExpr, bool ignoreSingletons)
This member function checks, whether the passed expression contains a vector.
unsigned int nthLoopElement
void ClearConst()
Clear all user defined constants.
const char_type * ValidOprtChars() const
Virtual function that defines the characters allowed in operator definitions.
void DefineFun(const string_type &a_strName, T a_pFun, bool optimizeAway=true)
Define a parser function without arguments.
void ClearVar()
Clear all user defined variables.
void expandVector(mu::value_type dFirst, const mu::value_type &dLast, const mu::value_type &dIncrement, std::vector< mu::value_type > &vResults)
This function expands the vector. Private member used by ParserBase::compileVectorExpansion().
void SetArgSep(char_type cArgSep)
Set argument separator.
std::unique_ptr< token_reader_type > m_pTokenReader
Managed pointer to the token reader object.
void DefineNameChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of functions, variables, constants.
void EnableBuiltInOprt(bool a_bIsOn=true)
Enable or disable the built in binary operators.
void SetCompiling(bool _bCompiling=true)
Activate the compiling step for the parser.
strmap_type m_StrVarDef
user defined string constants
static void EnableDebugDump(bool bDumpCmd, bool bDumpStack)
Enable the dumping of bytecode amd stack content on the console.
string_type getNextVectorVarIndex()
This member function returns the next free vector index, which can be used to create a new temporary ...
void InitTokenReader()
Initialize the token reader.
char_type GetArgSep() const
Get the argument separator character.
ExpressionTarget & getTarget() const
Simple state-considering wrapper around the ExpressionTarget structure.
string_type m_sNameChars
Charset for names.
bool m_bBuiltInOp
Flag that can be used for switching built in operators on and off.
string_type getNextVarObject(std::string &sArgList, bool bCut)
This member function returns the next comma-separated expression object from the passed argument list...
string_type m_sOprtChars
Charset for postfix/ binary operator tokens.
stringbuf_type m_vStringVarBuf
std::list< mu::value_type * > m_lDataStorage
void SetVectorVar(const std::string &sVarName, const std::vector< mu::value_type > &vVar, bool bAddVectorType=false)
This member function copies the passed vector into the internal storage referencing it with the passe...
void DefineOprt(const string_type &a_strName, fun_type2 a_pFun, unsigned a_iPri=0, EOprtAssociativity a_eAssociativity=oaLEFT, bool optimizeAway=true)
Define a binary operator.
Encapsulation of prototypes for a numerical parser function.
Error class of the parser.
Parser stack implementation.
Token reader for the ParserBase class.
Definition of the parser bytecode class.
This file contains standard definitions used by the parser.
This file defines the error class used by the parser.
This file defines the stack used by muparser.
This file contains the parser token reader definition.
Namespace for mathematical applications.
int(* identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal)
Callback used for functions that identify values in a string.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
value_type *(* facfun_type)(const char_type *, void *)
Callback used for variable creation factory functions.
std::map< string_type, value_type > valmap_type
Type used for storing constants.
value_type(* fun_type2)(const value_type &, const value_type &)
Callback type used for functions with two arguments.
string_type::value_type char_type
The character type used by the parser.
std::vector< value_type > valbuf_type
Type used for storing an array of values.
std::map< string_type, ParserCallback > funmap_type
Container for Callback objects.
value_type(* fun_type1)(const value_type &)
Callback type used for functions with a single arguments.
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
std::map< std::string, std::vector< value_type > > vectormap_type
std::string string_type
The stringtype used by the parser.
std::map< string_type, std::size_t > strmap_type
Type for assigning a string name to an index in the internal string table.
@ prINFIX
Signs have a higher priority than ADD_SUB, but lower than power operator.
EOprtAssociativity
Parser operator precedence values.
Describes an already evaluated data access, which can be reconstructed from the current parser state.
This structure defines the overall expression target, if it is composed out of a temporary vector lik...
Defines a single parser state, which contains all necessary information for evaluating a single expre...
This is a stack of all parser line state stacks. Can be used to gather a bunch of already parsed comm...
This structure contains the necessary data to resolve all preevaluated vectors.