29 #ifndef MU_PARSER_BASE_H
30 #define MU_PARSER_BASE_H
49 #pragma warning(disable : 4251) // ...needs to have dll-interface to be used by clients of class ...
83 typedef std::vector<value_type> valbuf_type;
86 typedef std::vector<string_type> stringbuf_type;
95 static const int s_MaxNumOpenMPThreads;
105 static void EnableDebugDump(
bool bDumpCmd,
bool bDumpStack);
115 void Eval(
value_type* results,
int nBulkSize);
117 int GetNumResults()
const;
120 void SetVarFactory(
facfun_type a_pFactory,
void* pUserData =
nullptr);
123 void SetThousandsSep(
char_type cThousandsSep = 0);
126 void EnableOptimizer(
bool a_bIsOn =
true);
127 void EnableBuiltInOprt(
bool a_bIsOn =
true);
129 bool HasBuiltInOprt()
const;
141 AddCallback(a_strName,
ParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars());
154 AddCallback(a_strName,
ParserCallback(a_pFun, a_pUserData, a_bAllowOpt), m_FunDef, ValidNameChars());
161 void DefinePostfixOprt(
const string_type& a_strFun,
fun_type1 a_pOprt,
bool a_bAllowOpt =
true);
168 void ClearInfixOprt();
169 void ClearPostfixOprt();
178 string_type GetVersion(EParserVersionInfo eInfo = pviFULL)
const;
182 void DefineNameChars(
const char_type* a_szCharset);
183 void DefineOprtChars(
const char_type* a_szCharset);
184 void DefineInfixOprtChars(
const char_type* a_szCharset);
188 const char_type* ValidInfixOprtChars()
const;
198 virtual void InitCharSets() = 0;
199 virtual void InitFun() = 0;
200 virtual void InitConst() = 0;
201 virtual void InitOprt() = 0;
203 virtual void OnDetectVar(
string_type* pExpr,
int& nStart,
int& nEnd);
207 static bool g_DbgDumpCmdCode;
208 static bool g_DbgDumpStack;
211 template<
class TChar>
217 :std::numpunct<TChar>()
219 ,m_cDecPoint(cDecSep)
220 ,m_cThousandsSep(cThousandsSep)
225 char_type do_decimal_point()
const override
230 char_type do_thousands_sep()
const override
232 return m_cThousandsSep;
235 std::string do_grouping()
const override
242 return std::string(1, (
char)(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX));
255 void InitTokenReader();
259 void ApplyRemainingOprt(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal)
const;
260 void ApplyBinOprt(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal)
const;
261 void ApplyIfElse(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal)
const;
262 void ApplyFunc(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal,
int iArgCount)
const;
264 token_type ApplyStrFunc(
const token_type& a_FunTok,
const std::vector<token_type>& a_vArg)
const;
266 int GetOprtPrecedence(
const token_type& a_Tok)
const;
269 void CreateRPN()
const;
274 value_type ParseCmdCodeBulk(
int nOffset,
int nThreadID)
const;
279 void StackDump(
const std::stack<token_type >& a_stVal,
const std::stack<token_type >& a_stOprt)
const;
285 mutable ParseFunction m_pParseFormula;
287 mutable stringbuf_type m_vStringBuf;
288 stringbuf_type m_vStringVarBuf;
290 std::unique_ptr<token_reader_type> m_pTokenReader;
307 mutable valbuf_type m_vStackBuffer;
308 mutable int m_nFinalResultIdx;
313 #if defined(_MSC_VER)
Definition of the parser bytecode class.
value_type *(* facfun_type)(const char_type *, void *)
Callback used for variable creation factory 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.
void DefineFunUserData(const string_type &a_strName, T a_pFun, void *a_pUserData, bool a_bAllowOpt=true)
Define a parser function with user data (not null).
value_type(* fun_type1)(value_type)
Callback type used for functions with a single arguments.
std::map< string_type, ParserCallback > funmap_type
Container for Callback objects.
EOprtAssociativity
Parser operator precedence values.
This file contains the parser token reader definition.
std::map< string_type, value_type > valmap_type
Type used for storing constants.
void DefineFun(const string_type &a_strName, T a_pFun, bool a_bAllowOpt=true)
Define a parser function without arguments.
value_type(* fun_type2)(value_type, value_type)
Callback type used for functions with two arguments.
Error class of the parser.
MUP_BASETYPE value_type
The numeric datatype used by the parser.
A facet class used to change decimal and thousands separator.
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.
Token reader for the ParserBase class.
Bytecode implementation of the Math Parser.
MUP_STRING_TYPE string_type
The stringtype used by the parser.
ParserError exception_type
Type of the error class.
Encapsulation of prototypes for a numerical parser function.
Signs have a higher priority than ADD_SUB, but lower than power operator.
Mathematical expressions parser (base parser engine).
This file defines the error class used by the parser.
This file contains standard definitions used by the parser.