25 #ifndef MU_PARSER_BASE_H
26 #define MU_PARSER_BASE_H
77 typedef std::vector<value_type> valbuf_type;
80 typedef std::vector<string_type> stringbuf_type;
89 static const int s_MaxNumOpenMPThreads = 16;
142 bool a_bAllowOpt =
false);
178 int a_iPos = (
int)mu::string_type::npos,
185 virtual void InitCharSets() = 0;
186 virtual void InitFun() = 0;
187 virtual void InitConst() = 0;
188 virtual void InitOprt() = 0;
190 virtual void OnDetectVar(
string_type *pExpr,
int &nStart,
int &nEnd);
194 static bool g_DbgDumpCmdCode;
195 static bool g_DbgDumpStack;
198 template<
class TChar>
204 :std::numpunct<TChar>()
206 ,m_cDecPoint(cDecSep)
207 ,m_cThousandsSep(cThousandsSep)
212 virtual char_type do_decimal_point()
const
217 virtual char_type do_thousands_sep()
const
219 return m_cThousandsSep;
222 virtual std::string do_grouping()
const
229 return std::string(1, (
char)(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX));
242 void InitTokenReader();
260 int iArgCount)
const;
262 token_type ApplyStrFunc(
const token_type &a_FunTok,
263 const std::vector<token_type> &a_vArg)
const;
265 int GetOprtPrecedence(
const token_type &a_Tok)
const;
268 void CreateRPN()
const;
272 value_type ParseCmdCodeBulk(
int nOffset,
int nThreadID)
const;
286 mutable ParseFunction m_pParseFormula;
288 mutable stringbuf_type m_vStringBuf;
289 stringbuf_type m_vStringVarBuf;
291 std::auto_ptr<token_reader_type> m_pTokenReader;
307 mutable int m_nIfElseCounter;
310 mutable valbuf_type m_vStackBuffer;
311 mutable int m_nFinalResultIdx;
void DefinePostfixOprt(const string_type &a_strFun, fun_type1 a_pOprt, bool a_bAllowOpt=true)
Add a user defined operator.
void DefineInfixOprtChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of infix operators.
Definition of the parser bytecode class.
void DefineNameChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of functions, variables, constants.
void DefineVar(const string_type &a_sName, value_type *a_fVar)
Add a user defined variable.
const funmap_type & GetFunDef() const
Return prototypes of all parser functions.
static std::locale s_locale
The locale 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.
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
static const char_type * c_DefaultOprt[]
Identifiers for built in binary operators.
void ClearConst()
Clear all user defined constants.
const char_type * ValidInfixOprtChars() const
Virtual function that defines the characters allowed in infix operator definitions.
void ClearOprt()
Clear all user defined binary operators.
void SetArgSep(char_type cArgSep)
Set argument separator.
const char_type * ValidOprtChars() const
Virtual function that defines the characters allowed in operator definitions.
void AddValIdent(identfun_type a_pCallback)
Add a value parsing function.
void SetDecSep(char_type cDecSep)
Set the decimal separator.
value_type Eval() const
Calculate the result.
Parser stack implementation.
bool HasBuiltInOprt() const
Query status of built in variables.
void ResetLocale()
Resets the locale.
std::map< string_type, ParserCallback > funmap_type
Container for Callback objects.
void ClearVar()
Clear all user defined variables.
void EnableOptimizer(bool a_bIsOn=true)
Enable or disable the formula optimization feature.
void DefineInfixOprt(const string_type &a_strName, fun_type1 a_pOprt, int a_iPrec=prINFIX, bool a_bAllowOpt=true)
Add a user defined operator.
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 SetVarFactory(facfun_type a_pFactory, void *pUserData=NULL)
Set a function that can create variable pointer for unknown expression variables. ...
const string_type & GetExpr() const
Retrieve the formula.
EOprtAssociativity
Parser operator precedence values.
void DefineOprtChars(const char_type *a_szCharset)
Define the set of valid characters to be used in names of binary operators and postfix operators...
const char_type * ValidNameChars() const
Virtual function that defines the characters allowed in name identifiers.
This file contains the parser token reader definition.
void SetThousandsSep(char_type cThousandsSep=0)
Sets the thousands operator.
std::map< string_type, value_type > valmap_type
Type used for storing constants.
void ClearPostfixOprt()
Clear all user defined postfix operators.
const valmap_type & GetConst() const
Return a map containing all parser constants.
void DefineFun(const string_type &a_strName, T a_pFun, bool a_bAllowOpt=true)
Define a parser function without arguments.
void DefineOprt(const string_type &a_strName, fun_type2 a_pFun, unsigned a_iPri=0, EOprtAssociativity a_eAssociativity=oaLEFT, bool a_bAllowOpt=false)
Define a binary operator.
Error class of the parser.
const varmap_type & GetVar() const
Return a map containing the used variables only.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
A facet class used to change decimal and thousands separator.
void SetExpr(const string_type &a_sExpr)
Set the formula.
static void EnableDebugDump(bool bDumpCmd, bool bDumpStack)
Enable the dumping of bytecode and stack content on the console.
Namespace for mathematical applications.
string_type GetVersion(EParserVersionInfo eInfo=pviFULL) const
Returns the version of muparser.
void RemoveVar(const string_type &a_strVarName)
Remove a variable from internal storage.
const char_type ** GetOprtDef() const
Get the default symbols used for the built in operators.
This file defines the stack used by muparser.
string_type::value_type char_type
The character type used by the parser.
Token reader for the ParserBase class.
ParserBase & operator=(const ParserBase &a_Parser)
Assignment operator.
void DefineConst(const string_type &a_sName, value_type a_fVal)
Add a user defined constant.
void EnableBuiltInOprt(bool a_bIsOn=true)
Enable or disable the built in binary operators.
Bytecode implementation of the Math Parser.
MUP_STRING_TYPE string_type
The stringtype used by the parser.
value_type(* fun_type1)(value_type)
Callback type used for functions with a single arguments.
ParserError exception_type
Type of the error class.
int(* identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal)
Callback used for functions that identify values in a string.
void ClearFun()
Clear all functions.
void DefineStrConst(const string_type &a_sName, const string_type &a_strVal)
Define a new string constant.
char_type GetArgSep() const
Get the argument separator character.
value_type *(* facfun_type)(const char_type *, void *)
Callback used for variable creation factory functions.
value_type(* fun_type2)(value_type, value_type)
Callback type used for functions with two arguments.
int GetNumResults() const
Return the number of results on the calculation stack.
void Init()
Initialize user defined functions.
Encapsulation of prototypes for a numerical parser function.
void ClearInfixOprt()
Clear the user defined Prefix operators.
Signs have a higher priority than ADD_SUB, but lower than power operator.
Mathematical expressions parser (base parser engine).
const varmap_type & GetUsedVar() const
Return a map containing the used variables only.
This file defines the error class used by the parser.
This file contains standard definitions used by the parser.