29 #ifndef MU_PARSER_BASE_H
30 #define MU_PARSER_BASE_H
78 typedef std::vector<value_type> valbuf_type;
81 typedef std::vector<string_type> stringbuf_type;
90 static const int s_MaxNumOpenMPThreads;
100 static void EnableDebugDump(
bool bDumpCmd,
bool bDumpStack);
110 void Eval(
value_type* results,
int nBulkSize);
112 int GetNumResults()
const;
115 void SetVarFactory(
facfun_type a_pFactory,
void* pUserData =
nullptr);
118 void SetThousandsSep(
char_type cThousandsSep = 0);
121 void EnableOptimizer(
bool a_bIsOn =
true);
122 void EnableBuiltInOprt(
bool a_bIsOn =
true);
124 bool HasBuiltInOprt()
const;
136 AddCallback(a_strName,
ParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars());
143 void DefinePostfixOprt(
const string_type& a_strFun,
fun_type1 a_pOprt,
bool a_bAllowOpt =
true);
150 void ClearInfixOprt();
151 void ClearPostfixOprt();
160 string_type GetVersion(EParserVersionInfo eInfo = pviFULL)
const;
163 void DefineNameChars(
const char_type* a_szCharset);
164 void DefineOprtChars(
const char_type* a_szCharset);
165 void DefineInfixOprtChars(
const char_type* a_szCharset);
169 const char_type* ValidInfixOprtChars()
const;
179 virtual void InitCharSets() = 0;
180 virtual void InitFun() = 0;
181 virtual void InitConst() = 0;
182 virtual void InitOprt() = 0;
184 virtual void OnDetectVar(
string_type* pExpr,
int& nStart,
int& nEnd);
188 static bool g_DbgDumpCmdCode;
189 static bool g_DbgDumpStack;
192 template<
class TChar>
198 :std::numpunct<TChar>()
200 , m_cDecPoint(cDecSep)
201 , m_cThousandsSep(cThousandsSep)
206 virtual char_type do_decimal_point()
const
211 virtual char_type do_thousands_sep()
const
213 return m_cThousandsSep;
216 virtual std::string do_grouping()
const
223 return std::string(1, (
char)(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX));
236 void InitTokenReader();
240 void ApplyRemainingOprt(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal)
const;
241 void ApplyBinOprt(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal)
const;
242 void ApplyIfElse(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal)
const;
243 void ApplyFunc(std::stack<token_type>& a_stOpt, std::stack<token_type>& a_stVal,
int iArgCount)
const;
245 token_type ApplyStrFunc(
const token_type& a_FunTok,
const std::vector<token_type>& a_vArg)
const;
247 int GetOprtPrecedence(
const token_type& a_Tok)
const;
250 void CreateRPN()
const;
255 value_type ParseCmdCodeBulk(
int nOffset,
int nThreadID)
const;
260 void StackDump(
const std::stack<token_type >& a_stVal,
const std::stack<token_type >& a_stOprt)
const;
266 mutable ParseFunction m_pParseFormula;
268 mutable stringbuf_type m_vStringBuf;
269 stringbuf_type m_vStringVarBuf;
271 std::unique_ptr<token_reader_type> m_pTokenReader;
288 mutable valbuf_type m_vStackBuffer;
289 mutable int m_nFinalResultIdx;
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.
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.