muParserX 2.0.0
|
Implementation of the parser engine. More...
#include <mpParserBase.h>
Public Member Functions | |
ParserXBase () | |
Default constructor. | |
ParserXBase (const ParserXBase &a_Parser) | |
Copy constructor. | |
ParserXBase & | operator= (const ParserXBase &a_Parser) |
Assignement operator. | |
virtual | ~ParserXBase () |
Destructor. | |
const IValue & | Eval () const |
Evaluate the expression. | |
void | SetExpr (const string_type &a_sExpr) |
Set the mathematical expression. | |
void | AddValueReader (IValueReader *a_pReader) |
Add a value reader object to muParserX. | |
void | AddPackage (IPackage *p) |
Adds a new package to the parser. | |
void | DefineConst (const string_type &ident, const Value &val) |
Define a parser Constant. | |
void | DefineVar (const string_type &ident, const Variable &var) |
Add a user defined variable. | |
void | DefineFun (const ptr_cal_type &fun) |
Add a callback object to the parser. | |
void | DefineOprt (const TokenPtr< IOprtBin > &oprt) |
Define a binary operator. | |
void | DefineOprt (const TokenPtr< IOprtBinShortcut > &oprt) |
Define a short circuit operator. | |
void | DefinePostfixOprt (const TokenPtr< IOprtPostfix > &oprt) |
Add a user defined operator. | |
void | DefineInfixOprt (const TokenPtr< IOprtInfix > &oprt) |
Add a user defined operator. | |
void | ClearVar () |
Clear all user defined variables. | |
void | ClearFun () |
Clear all function definitions. | |
void | ClearConst () |
Clear all user defined constants. | |
void | ClearInfixOprt () |
Clear the user defined Prefix operators. | |
void | ClearPostfixOprt () |
Clear all user defined postfix operators. | |
void | ClearOprt () |
Clear all user defined binary operators. | |
const var_maptype & | GetExprVar () const |
Return a map containing the used variables only. | |
const var_maptype & | GetVar () const |
Return a map containing the used variables only. | |
const val_maptype & | GetConst () const |
Return a map containing all parser constants. | |
const fun_maptype & | GetFunDef () const |
Return prototypes of all parser functions. | |
const string_type & | GetExpr () const |
Retrieve the mathematical expression. | |
const char_type ** | GetOprtDef () const |
Return the strings of all Operator identifiers. | |
void | DefineNameChars (const char_type *a_szCharset) |
Define the set of valid characters to be used in names of functions, variables, constants. | |
void | DefineOprtChars (const char_type *a_szCharset) |
Define the set of valid characters to be used in names of binary operators and postfix operators. | |
void | DefineInfixOprtChars (const char_type *a_szCharset) |
Define the set of valid characters to be used in names of infix operators. | |
const char_type * | ValidNameChars () const |
Virtual function that defines the characters allowed in name identifiers. | |
const char_type * | ValidOprtChars () const |
Virtual function that defines the characters allowed in operator definitions. | |
const char_type * | ValidInfixOprtChars () const |
Virtual function that defines the characters allowed in infix operator definitions. | |
void | CheckName (const string_type &a_sName, const string_type &a_CharSet) const |
Check if a given name contains invalid characters. | |
Static Public Member Functions | |
static string_type | GetVersion () |
Get the version number of muParserX. | |
static void | EnableDebugDump (bool bDumpCmd, bool bDumpRPN) |
Enable the dumping of bytecode amd stack content on the console. | |
Protected Attributes | |
fun_maptype | m_FunDef |
Function definitions. | |
oprt_pfx_maptype | m_PostOprtDef |
Postfix operator callbacks. | |
oprt_ifx_maptype | m_InfixOprtDef |
Infix operator callbacks. | |
oprt_bin_maptype | m_OprtDef |
Binary operator callbacks. | |
oprt_bin_shortcut_maptype | m_OprtShortcutDef |
short circuit operator definitions | |
val_maptype | m_valDef |
Definition of parser constants. | |
var_maptype | m_varDef |
user defind variables. | |
Implementation of the parser engine.
This is the muParser core. It provides the parsing logic and manages the callback functions, operators, variables and constants. Do not instantiate this class directly. Create an instance of mup::ParserX instead.
mup::ParserXBase::ParserXBase | ( | const ParserXBase & | a_Parser | ) |
Copy constructor.
a_Parser | Reference to the other parser object |
Implemented by calling Assign(a_Parser)
|
virtual |
Destructor.
nothrow |
void mup::ParserXBase::AddPackage | ( | IPackage * | p | ) |
Adds a new package to the parser.
The parser becomes the owner of the package pointer and is responsible for its deletion.
void mup::ParserXBase::AddValueReader | ( | IValueReader * | a_pReader | ) |
Add a value reader object to muParserX.
a_pReader | Pointer to the value reader object. |
void mup::ParserXBase::CheckName | ( | const string_type & | a_strName, |
const string_type & | a_szCharSet ) const |
Check if a given name contains invalid characters.
a_strName | The name to check |
a_szCharSet | The characterset |
ParserException | if the name contains invalid charakters. |
void mup::ParserXBase::ClearConst | ( | ) |
Clear all user defined constants.
nothrow |
Both numeric and string constants will be removed from the internal storage.
void mup::ParserXBase::ClearFun | ( | ) |
Clear all function definitions.
nothrow |
void mup::ParserXBase::ClearInfixOprt | ( | ) |
Clear the user defined Prefix operators.
nothrow |
void mup::ParserXBase::ClearOprt | ( | ) |
Clear all user defined binary operators.
nothrow |
void mup::ParserXBase::ClearPostfixOprt | ( | ) |
Clear all user defined postfix operators.
nothrow |
void mup::ParserXBase::ClearVar | ( | ) |
Clear all user defined variables.
nothrow |
Resets the parser to string parsing mode by calling ReInit.
void mup::ParserXBase::DefineConst | ( | const string_type & | ident, |
const Value & | val ) |
Define a parser Constant.
a_sName | The name of the constant |
a_Val | Const reference to the constants value |
Parser constants are handed over by const reference as opposed to variables which are handed over by reference. Consequently the parser can not change their value.
void mup::ParserXBase::DefineFun | ( | const ptr_cal_type & | fun | ) |
Add a callback object to the parser.
a_pFunc | Pointer to the intance of a parser callback object representing the function. |
The parser takes ownership over the callback object.
void mup::ParserXBase::DefineInfixOprt | ( | const TokenPtr< IOprtInfix > & | oprt | ) |
Add a user defined operator.
a_pOprt | Pointer to a unary postfix operator object. The parser will become the new owner of this object hence will destroy it. |
void mup::ParserXBase::DefineInfixOprtChars | ( | const char_type * | a_szCharset | ) |
Define the set of valid characters to be used in names of infix operators.
a_szCharset | A string containing all characters that can be used in infix operator identifiers. |
Define a binary operator.
a_pCallback | Pointer to the callback object |
void mup::ParserXBase::DefineOprt | ( | const TokenPtr< IOprtBinShortcut > & | oprt | ) |
Define a short circuit operator.
a_pCallback | Pointer to the callback object |
void mup::ParserXBase::DefineOprtChars | ( | const char_type * | a_szCharset | ) |
Define the set of valid characters to be used in names of binary operators and postfix operators.
a_szCharset | A string containing all characters that can be used in operator identifiers. |
void mup::ParserXBase::DefinePostfixOprt | ( | const TokenPtr< IOprtPostfix > & | oprt | ) |
Add a user defined operator.
a_pOprt | Pointer to a unary postfix operator object. The parser will become the new owner of this object hence will destroy it. |
void mup::ParserXBase::DefineVar | ( | const string_type & | ident, |
const Variable & | var ) |
Add a user defined variable.
a_sName | The variable name |
a_Var | The variable to be added to muParserX |
|
static |
Enable the dumping of bytecode amd stack content on the console.
bDumpCmd | Flag to enable dumping of the current bytecode to the console. |
bDumpStack | Flag to enable dumping of the stack content is written to the console. |
This function is for debug purposes only!
const IValue & mup::ParserXBase::Eval | ( | ) | const |
Evaluate the expression.
ParseException | if no Formula is set or in case of any other error related to the formula. |
A note on const correctness: I consider it important that Calc is a const function. Due to caching operations Calc changes only the state of internal variables with one exception m_UsedVar this is reset during string parsing and accessible from the outside. Instead of making Calc non const GetExprVar is non const because it explicitely calls Eval() forcing this update.
const fun_maptype & mup::ParserXBase::GetFunDef | ( | ) | const |
Return prototypes of all parser functions.
nothrow |
The return type is a map of the public type #funmap_type containing the prototype definitions for all numerical parser functions. String functions are not part of this map. The Prototype definition is encapsulated in objects of the class FunProt one per parser function each associated with function names via a map construct.
const char_type ** mup::ParserXBase::GetOprtDef | ( | ) | const |
Return the strings of all Operator identifiers.
nothrow |
GetOprt is a const function returning a pinter to an array of const char pointers.
|
static |
Get the version number of muParserX.
ParserXBase & mup::ParserXBase::operator= | ( | const ParserXBase & | a_Parser | ) |
Assignement operator.
a_Parser | Object to copy to this. |
nothrow |
Implemented by calling Assign(a_Parser). Self assignement is suppressed.
void mup::ParserXBase::SetExpr | ( | const string_type & | a_sExpr | ) |
Set the mathematical expression.
a_sExpr | String with the expression |
ParserException | in case of syntax errors. |
Triggers first time calculation thus the creation of the bytecode and scanning of used variables.
const char_type * mup::ParserXBase::ValidInfixOprtChars | ( | ) | const |
Virtual function that defines the characters allowed in infix operator definitions.
const char_type * mup::ParserXBase::ValidNameChars | ( | ) | const |
Virtual function that defines the characters allowed in name identifiers.
const char_type * mup::ParserXBase::ValidOprtChars | ( | ) | const |
Virtual function that defines the characters allowed in operator definitions.