67 if (&a_Reader !=
this)
112 : m_pParser(a_pParent)
116 , m_bIgnoreUndefVar(false)
118 , m_pPostOprtDef(NULL)
119 , m_pInfixOprtDef(NULL)
125 , m_pFactoryData(NULL)
149 ptr->SetParent(a_pParent);
150 return ptr.release();
258 std::stack<int> FunArgs;
264 while (szFormula[
m_iPos] > 0 && szFormula[
m_iPos] <= 0x20)
339 int iEnd = (int)
m_strFormula.find_first_not_of(a_szCharSet, a_iPos);
341 if (iEnd == (
int)string_type::npos)
363 if (iEnd == (
int)string_type::npos)
392 for (
int i = 0; pOprtDef[i]; i++)
394 std::size_t len( std::char_traits<char_type>::length(pOprtDef[i]) );
560 if (sTok.find(it->first) != 0)
563 a_Tok.
Set(it->second, it->first);
564 m_iPos += (int)it->first.length();
601 funmap_type::const_iterator item =
m_pFunDef->find(strTok);
607 if (szFormula[iEnd] !=
'(')
610 a_Tok.
Set(item->second, strTok);
648 funmap_type::const_reverse_iterator it =
m_pOprtDef->rbegin();
654 a_Tok.
Set(it->second, strTok);
674 m_iPos += (int)sID.length();
713 funmap_type::const_reverse_iterator it =
m_pPostOprtDef->rbegin();
716 if (sTok.find(it->first) != 0)
719 a_Tok.
Set(it->second, sTok);
720 m_iPos += (int)it->first.length();
751 valmap_type::const_iterator item =
m_pConstDef->find(strTok);
755 a_Tok.
SetVal(item->second, strTok);
767 std::list<identfun_type>::const_iterator item =
m_vIdentFun.begin();
777 a_Tok.
SetVal(fVal, strTok);
801 varmap_type::const_iterator item =
m_pVarDef->find(strTok);
816 a_Tok.
SetVar(item->second, strTok);
837 strmap_type::const_iterator item =
m_pStrVarDef->find(strTok);
882 a_Tok.
SetVar(fVar, strTok );
890 (*m_pVarDef)[strTok] = fVar;
920 std::size_t iEnd(0), iSkip(0);
923 for (iEnd = (
int)strBuf.find(
_nrT(
"\"") ); iEnd != 0 && iEnd != string_type::npos; iEnd = (int)strBuf.find(
_nrT(
"\""), iEnd))
925 if (strBuf[iEnd - 1] !=
'\\')
927 strBuf.replace(iEnd - 1, 2,
_nrT(
"\"") );
931 if (iEnd == string_type::npos)
934 string_type strTok(strBuf.begin(), strBuf.begin() + iEnd);
942 m_iPos += (int)strTok.length() + 2 + (int)iSkip;
Mathematical expressions parser (base parser engine).
varmap_type m_VarDef
user defind variables.
const char_type * ValidInfixOprtChars() const
Virtual function that defines the characters allowed in infix operator definitions.
stringbuf_type m_vStringBuf
String buffer, used for storing string function arguments.
bool HasBuiltInOprt() const
Query status of built in variables.
const char_type ** GetOprtDef() const
Get the default symbols used for the built in operators.
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.
funmap_type m_InfixOprtDef
unary infix operator.
valmap_type m_ConstDef
user constants.
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
funmap_type m_FunDef
Map of function names and pointers.
funmap_type m_PostOprtDef
Postfix operator callbacks.
funmap_type m_OprtDef
Binary operator callbacks.
virtual void OnDetectVar(string_type *pExpr, int &nStart, int &nEnd)
const char_type * ValidOprtChars() const
Virtual function that defines the characters allowed in operator definitions.
strmap_type m_StrVarDef
user defined string constants
stringbuf_type m_vStringVarBuf
ECmdCode GetCode() const
Return the token type.
ParserToken & SetString(const TString &a_strTok, std::size_t a_iSize)
Make this token a variable token.
ParserToken & SetVar(TBase *a_pVar, const TString &a_strTok)
make this token a variable token.
ParserToken & SetVal(TBase a_fVal, const TString &a_strTok=TString())
Make this token a value token.
ParserToken & Set(ECmdCode a_iType, const TString &a_strTok=TString())
Assign a token type.
const TString & GetAsString() const
Return the token identifier.
Token reader for the ParserBase class.
bool IsArgSep(token_type &a_Tok)
bool IsPostOpTok(token_type &a_Tok)
Check if a string position contains a unary post value operator.
const funmap_type * m_pPostOprtDef
const funmap_type * m_pInfixOprtDef
std::list< identfun_type > m_vIdentFun
Value token identification function.
ParserTokenReader(ParserBase *a_pParent)
Constructor.
bool IsFunTok(token_type &a_Tok)
Check whether the token at a given position is a function token.
bool IsValTok(token_type &a_Tok)
Check whether the token at a given position is a value token.
token_type ReadNextToken()
Read the next token from the string.
@ noASSIGN
to block assignement to constant i.e. "4=7"
@ noEND
to avoid unexpected end of formula
@ noSTR
to block numeric arguments on string functions
@ noINFIXOP
to avoid i.e. "++4" "!!4"
@ noVAR
to avoid i.e. "sin a" or "sin(8)a"
@ noBO
to avoid i.e. "cos(7)("
@ noOPT
to avoid i.e. "(+)"
@ noANY
All of he above flags set.
@ noVAL
to avoid i.e. "tan 2" or "sin(8)3.14"
@ noPOSTOP
to avoid i.e. "(5!!)" "sin!"
@ noARG_SEP
to avoid i.e. ",," or "+," ...
@ noBC
to avoid i.e. "sin)" or "()"
@ noFUN
to avoid i.e. "sqrt cos" or "(1)sin"
void SetParent(ParserBase *a_pParent)
char_type m_cArgSep
The character used for separating function arguments.
void Assign(const ParserTokenReader &a_Reader)
Assign state of a token reader to this token reader.
bool IsOprt(token_type &a_Tok)
Check if a string position contains a binary operator.
int ExtractToken(const char_type *a_szCharSet, string_type &a_strTok, int a_iPos) const
Extract all characters that belong to a certain charset.
value_type m_fZero
Dummy value of zero, referenced by undefined variables.
void SetArgSep(char_type cArgSep)
const funmap_type * m_pFunDef
ParserTokenReader & operator=(const ParserTokenReader &a_Reader)
Assignement operator.
void Error(EErrorCodes a_iErrc, int a_iPos=-1, const string_type &a_sTok=string_type()) const
Create an error containing the parse error position.
void SetVarCreator(facfun_type a_pFactory, void *pUserData)
void IgnoreUndefVar(bool bIgnore)
Set Flag that contronls behaviour in case of undefined variables beeing found.
const funmap_type * m_pOprtDef
ParserTokenReader * Clone(ParserBase *a_pParent) const
Create instance of a ParserTokenReader identical with this and return its pointer.
bool IsVarTok(token_type &a_Tok)
Check wheter a token at a given position is a variable token.
void SetFormula(const string_type &a_strFormula)
Initialize the token Reader.
bool IsString(token_type &a_Tok)
Check wheter a token at a given position is a string.
int GetPos() const
Return the current position of the token reader in the formula string.
char_type GetArgSep() const
bool IsInfixOpTok(token_type &a_Tok)
Check if a string position contains a unary infix operator.
ParserToken< value_type, string_type > token_type
int ExtractOperatorToken(string_type &a_sTok, int a_iPos) const
Check Expression for the presence of a binary operator token.
varmap_type * m_pVarDef
The only non const pointer to parser internals.
const strmap_type * m_pStrVarDef
bool IsEOF(token_type &a_Tok)
Check for End of Formula.
bool IsBuiltIn(token_type &a_Tok)
Check if a built in operator or other token can be found.
void ReInit()
Reset the token reader to the start of the formula.
token_type & SaveBeforeReturn(const token_type &tok)
varmap_type & GetUsedVar()
Return a map containing the used variables only.
void AddValIdent(identfun_type a_pCallback)
bool IsStrVarTok(token_type &a_Tok)
const string_type & GetExpr() const
Return a reference to the formula.
bool IsUndefVarTok(token_type &a_Tok)
Check wheter a token at a given position is an undefined variable.
const valmap_type * m_pConstDef
This file contains the class definition of the muparser engine.
#define _nrT(x)
Activate this option in order to compile with OpenMP support.
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.
string_type::value_type char_type
The character type used by the parser.
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
@ cmADD
Operator item: add.
@ cmGE
Operator item: greater or equal.
@ cmLT
Operator item: less than.
@ cmPOW
Operator item: y to the power of ...
@ cmASSIGN
Operator item: Assignment operator.
@ cmARG_SEP
function argument separator
@ cmLE
Operator item: less or equal.
@ cmBO
Operator item: opening bracket.
@ cmMUL
Operator item: multiply.
@ cmDIV
Operator item: division.
@ cmBC
Operator item: closing bracket.
@ cmIF
For use in the ternary if-then-else operator.
@ cmNEQ
Operator item: not equal.
@ cmGT
Operator item: greater than.
@ cmEQ
Operator item: equals.
@ cmSUB
Operator item: subtract.
@ cmFUNC
Code for a generic function item.
@ cmELSE
For use in the ternary if-then-else operator.
@ ecUNASSIGNABLE_TOKEN
Token cant be identified.
@ ecMISSING_PARENS
Missing parens. (Example: "3*sin(3")
@ ecUNEXPECTED_EOF
Unexpected end of formula. (Example: "2+sin(")
@ ecUNEXPECTED_VAR
An unexpected variable token has been found.
@ ecUNEXPECTED_FUN
Unexpected function found. (Example: "sin(8)cos(9)")
@ ecUNEXPECTED_OPERATOR
Unexpected binary operator found.
@ ecUNEXPECTED_STR
A string has been found at an inapropriate position.
@ ecUNEXPECTED_PARENS
Unexpected Parenthesis, opening or closing.
@ ecINTERNAL_ERROR
Internal error of any kind.
@ ecUNEXPECTED_ARG_SEP
An unexpected comma has been found. (Example: "1,23")
@ ecUNTERMINATED_STRING
unterminated string constant. (Example: "3*valueof("hello)")
@ ecUNEXPECTED_CONDITIONAL
@ ecUNEXPECTED_VAL
An unexpected value token has been found.
std::string string_type
The stringtype used by the parser.