36 #define wxT(x) MUP_T(x)
115 :m_pParser(a_pParent)
119 ,m_bIgnoreUndefVar(
false)
121 ,m_pPostOprtDef(
NULL)
122 ,m_pInfixOprtDef(
NULL)
128 ,m_pFactoryData(
NULL)
152 ptr->SetParent(a_pParent);
153 return ptr.release();
255 std::stack<int> FunArgs;
259 while (szFormula[
m_iPos]==
' ')
325 if (iEnd==(
int)string_type::npos)
345 for (
int i=0; pOprtDef[
i];
i++)
347 std::size_t
len( std::char_traits<char_type>::length(pOprtDef[
i]) );
493 a_Tok.
Set(item->second, sTok);
517 funmap_type::const_iterator item =
m_pFunDef->find(strTok);
521 a_Tok.
Set(item->second, strTok);
543 funmap_type::const_iterator item =
m_pOprtDef->find(strTok);
547 a_Tok.
Set(item->second, strTok);
587 if (sTok.find(item->first)!=0)
590 a_Tok.
Set(item->second, sTok);
616 #if defined(_MSC_VER)
617 #pragma warning( disable : 4244 )
629 valmap_type::const_iterator item =
m_pConstDef->find(strTok);
633 a_Tok.
SetVal(item->second, strTok);
645 std::vector<identfun_type>::const_iterator item =
m_vIdentFun.begin();
655 a_Tok.
SetVal(fVal, strTok);
663 #if defined(_MSC_VER)
664 #pragma warning( default : 4244 )
683 varmap_type::const_iterator item =
m_pVarDef->find(strTok);
691 a_Tok.
SetVar(item->second, strTok);
709 strmap_type::const_iterator item =
m_pStrVarDef->find(strTok);
754 a_Tok.
SetVar(fVar, strTok );
762 (*m_pVarDef)[strTok] = fVar;
792 std::size_t iEnd(0), iSkip(0);
795 for(iEnd=(
int)strBuf.find(
wxT(
"\"") ); iEnd!=string_type::npos; iEnd=(
int)strBuf.find(
wxT(
"\""), iEnd))
797 if (strBuf[iEnd-1]!=
'\\')
break;
798 strBuf.replace(iEnd-1, 2,
wxT(
"\"") );
802 if (iEnd==string_type::npos)
805 string_type strTok(strBuf.begin(), strBuf.begin()+iEnd);
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.
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
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
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.
std::vector< identfun_type > m_vIdentFun
Value token identification function.
token_type ReadNextToken()
Read the next token from the string.
const varmap_type & GetUsedVar() const
Return a map containing the used variables only.
@ 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
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)
void AddValIdent(identfun_type a_pCallback)
const string_type & GetFormula() const
Return a reference to the formula.
bool IsStrVarTok(token_type &a_Tok)
bool IsUndefVarTok(token_type &a_Tok)
Check wheter a token at a given position is an undefined variable.
const valmap_type * m_pConstDef
ECmdCode GetCode() const
Return the token type.
ParserToken & SetVal(TBase a_fVal, const TString &a_strTok=TString())
Make this token a value token.
const TString & GetAsString() const
Return the token identifier.
ParserToken & SetVar(TBase *a_pVar, const TString &a_strTok)
make this token a variable token.
ParserToken & Set(ECmdCode a_iType, const TString &a_strTok=TString())
Assign a token type.
ParserToken & SetString(const TString &a_strTok, std::size_t a_iSize)
Make this token a variable token.
unsigned int
A callback function used to compare two keys in a database.
This file contains the class definition of the muparser engine.
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.
string_type::value_type char_type
The character type 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 * > 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.
@ cmXOR
Operator item: logical xor.
@ cmDIV
Operator item: division.
@ cmAND
Operator item: logical and.
@ cmBC
Operator item: closing bracket.
@ cmOR
Operator item: logical or.
@ cmNEQ
Operator item: not equal.
@ cmGT
Operator item: greater than.
@ cmEQ
Operator item: equals.
@ cmSUB
Operator item: subtract.
@ cmFUNC
Code for a function item.
@ 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_VAL
An unexpected value token has been found.
double value_type
The numeric datatype used by the parser.
std::string string_type
The stringtype used by the parser.