muParserX 2.0.0
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
mup::ParserXBase Class Reference

Implementation of the parser engine. More...

#include <mpParserBase.h>

Inheritance diagram for mup::ParserXBase:
Inheritance graph
[legend]

Public Member Functions

 ParserXBase ()
 Default constructor.
 
 ParserXBase (const ParserXBase &a_Parser)
 Copy constructor. More...
 
ParserXBaseoperator= (const ParserXBase &a_Parser)
 Assignement operator. More...
 
virtual ~ParserXBase ()
 Destructor. More...
 
const IValueEval () const
 Evaluate the expression. More...
 
void SetExpr (const string_type &a_sExpr)
 Set the mathematical expression. More...
 
void AddValueReader (IValueReader *a_pReader)
 Add a value reader object to muParserX. More...
 
void AddPackage (IPackage *p)
 Adds a new package to the parser. More...
 
void DefineConst (const string_type &ident, const Value &val)
 Define a parser Constant. More...
 
void DefineVar (const string_type &ident, const Variable &var)
 Add a user defined variable. More...
 
void DefineFun (const ptr_cal_type &fun)
 Add a callback object to the parser. More...
 
void DefineOprt (const TokenPtr< IOprtBin > &oprt)
 Define a binary operator. More...
 
void DefineOprt (const TokenPtr< IOprtBinShortcut > &oprt)
 Define a short circuit operator. More...
 
void DefinePostfixOprt (const TokenPtr< IOprtPostfix > &oprt)
 Add a user defined operator. More...
 
void DefineInfixOprt (const TokenPtr< IOprtInfix > &oprt)
 Add a user defined operator. More...
 
void ClearVar ()
 Clear all user defined variables. More...
 
void ClearFun ()
 Clear all function definitions. More...
 
void ClearConst ()
 Clear all user defined constants. More...
 
void ClearInfixOprt ()
 Clear the user defined Prefix operators. More...
 
void ClearPostfixOprt ()
 Clear all user defined postfix operators. More...
 
void ClearOprt ()
 Clear all user defined binary operators. More...
 
const var_maptypeGetExprVar () const
 Return a map containing the used variables only.
 
const var_maptypeGetVar () const
 Return a map containing the used variables only.
 
const val_maptypeGetConst () const
 Return a map containing all parser constants.
 
const fun_maptypeGetFunDef () const
 Return prototypes of all parser functions. More...
 
const string_typeGetExpr () const
 Retrieve the mathematical expression.
 
const char_type ** GetOprtDef () const
 Return the strings of all Operator identifiers. More...
 
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. More...
 
void DefineInfixOprtChars (const char_type *a_szCharset)
 Define the set of valid characters to be used in names of infix operators. More...
 
const char_typeValidNameChars () const
 Virtual function that defines the characters allowed in name identifiers. More...
 
const char_typeValidOprtChars () const
 Virtual function that defines the characters allowed in operator definitions. More...
 
const char_typeValidInfixOprtChars () const
 Virtual function that defines the characters allowed in infix operator definitions. More...
 
void CheckName (const string_type &a_sName, const string_type &a_CharSet) const
 Check if a given name contains invalid characters. More...
 

Static Public Member Functions

static string_type GetVersion ()
 Get the version number of muParserX. More...
 
static void EnableDebugDump (bool bDumpCmd, bool bDumpRPN)
 Enable the dumping of bytecode amd stack content on the console. More...
 

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.
 

Detailed Description

Implementation of the parser engine.

Author
Ingo Berg

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.

Constructor & Destructor Documentation

◆ ParserXBase()

mup::ParserXBase::ParserXBase ( const ParserXBase a_Parser)

Copy constructor.

Parameters
a_ParserReference to the other parser object

Implemented by calling Assign(a_Parser)

◆ ~ParserXBase()

mup::ParserXBase::~ParserXBase ( )
virtual

Destructor.

Exceptions
nothrow

Member Function Documentation

◆ AddPackage()

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.

◆ AddValueReader()

void mup::ParserXBase::AddValueReader ( IValueReader a_pReader)

Add a value reader object to muParserX.

Parameters
a_pReaderPointer to the value reader object.

◆ CheckName()

void mup::ParserXBase::CheckName ( const string_type a_strName,
const string_type a_szCharSet 
) const

Check if a given name contains invalid characters.

Parameters
a_strNameThe name to check
a_szCharSetThe characterset
Exceptions
ParserExceptionif the name contains invalid charakters.

◆ ClearConst()

void mup::ParserXBase::ClearConst ( )

Clear all user defined constants.

Exceptions
nothrow

Both numeric and string constants will be removed from the internal storage.

◆ ClearFun()

void mup::ParserXBase::ClearFun ( )

Clear all function definitions.

Exceptions
nothrow

◆ ClearInfixOprt()

void mup::ParserXBase::ClearInfixOprt ( )

Clear the user defined Prefix operators.

Exceptions
nothrow

◆ ClearOprt()

void mup::ParserXBase::ClearOprt ( )

Clear all user defined binary operators.

Exceptions
nothrow

◆ ClearPostfixOprt()

void mup::ParserXBase::ClearPostfixOprt ( )

Clear all user defined postfix operators.

Exceptions
nothrow

◆ ClearVar()

void mup::ParserXBase::ClearVar ( )

Clear all user defined variables.

Exceptions
nothrow

Resets the parser to string parsing mode by calling #ReInit.

◆ DefineConst()

void mup::ParserXBase::DefineConst ( const string_type ident,
const Value val 
)

Define a parser Constant.

Parameters
a_sNameThe name of the constant
a_ValConst 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.

Here is the call graph for this function:

◆ DefineFun()

void mup::ParserXBase::DefineFun ( const ptr_cal_type fun)

Add a callback object to the parser.

Parameters
a_pFuncPointer to the intance of a parser callback object representing the function.
See also
GetFunDef, Function callback objects.

The parser takes ownership over the callback object.

◆ DefineInfixOprt()

void mup::ParserXBase::DefineInfixOprt ( const TokenPtr< IOprtInfix > &  oprt)

Add a user defined operator.

Parameters
a_pOprtPointer to a unary postfix operator object. The parser will become the new owner of this object hence will destroy it.

◆ DefineInfixOprtChars()

void mup::ParserXBase::DefineInfixOprtChars ( const char_type a_szCharset)

Define the set of valid characters to be used in names of infix operators.

Parameters
a_szCharsetA string containing all characters that can be used in infix operator identifiers.

◆ DefineOprt() [1/2]

void mup::ParserXBase::DefineOprt ( const TokenPtr< IOprtBin > &  oprt)

Define a binary operator.

Parameters
a_pCallbackPointer to the callback object

◆ DefineOprt() [2/2]

void mup::ParserXBase::DefineOprt ( const TokenPtr< IOprtBinShortcut > &  oprt)

Define a short circuit operator.

Parameters
a_pCallbackPointer to the callback object

◆ DefineOprtChars()

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.

Parameters
a_szCharsetA string containing all characters that can be used in operator identifiers.

◆ DefinePostfixOprt()

void mup::ParserXBase::DefinePostfixOprt ( const TokenPtr< IOprtPostfix > &  oprt)

Add a user defined operator.

Postcondition
Will reset the Parser to string parsing mode.
Parameters
a_pOprtPointer to a unary postfix operator object. The parser will become the new owner of this object hence will destroy it.

◆ DefineVar()

void mup::ParserXBase::DefineVar ( const string_type ident,
const Variable var 
)

Add a user defined variable.

Parameters
a_sNameThe variable name
a_VarThe variable to be added to muParserX
Here is the call graph for this function:

◆ EnableDebugDump()

void mup::ParserXBase::EnableDebugDump ( bool  bDumpRPN,
bool  bDumpStack 
)
static

Enable the dumping of bytecode amd stack content on the console.

Parameters
bDumpCmdFlag to enable dumping of the current bytecode to the console.
bDumpStackFlag to enable dumping of the stack content is written to the console.

This function is for debug purposes only!

◆ Eval()

const IValue & mup::ParserXBase::Eval ( ) const

Evaluate the expression.

Precondition
A formula must be set.
Variables must have been set (if needed)
See also
SetExpr
Returns
The evaluation result
Exceptions
ParseExceptionif 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.

◆ GetFunDef()

const fun_maptype & mup::ParserXBase::GetFunDef ( ) const

Return prototypes of all parser functions.

Returns
m_FunDef
See also
FunProt, Function callback objects.
Exceptions
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.

◆ GetOprtDef()

const char_type ** mup::ParserXBase::GetOprtDef ( ) const

Return the strings of all Operator identifiers.

Returns
Returns a pointer to the c_DefaultOprt array of const char *.
Exceptions
nothrow

GetOprt is a const function returning a pinter to an array of const char pointers.

◆ GetVersion()

string_type mup::ParserXBase::GetVersion ( )
static

Get the version number of muParserX.

Returns
A string containing the version number of muParserX.

◆ operator=()

ParserXBase & mup::ParserXBase::operator= ( const ParserXBase a_Parser)

Assignement operator.

Parameters
a_ParserObject to copy to this.
Returns
*this
Exceptions
nothrow

Implemented by calling Assign(a_Parser). Self assignement is suppressed.

◆ SetExpr()

void mup::ParserXBase::SetExpr ( const string_type a_sExpr)

Set the mathematical expression.

Parameters
a_sExprString with the expression
Exceptions
ParserExceptionin case of syntax errors.

Triggers first time calculation thus the creation of the bytecode and scanning of used variables.

◆ ValidInfixOprtChars()

const char_type * mup::ParserXBase::ValidInfixOprtChars ( ) const

Virtual function that defines the characters allowed in infix operator definitions.

See also
ValidNameChars, ValidOprtChars

◆ ValidNameChars()

const char_type * mup::ParserXBase::ValidNameChars ( ) const

Virtual function that defines the characters allowed in name identifiers.

See also
ValidOprtChars, #ValidPrefixOprtChars

◆ ValidOprtChars()

const char_type * mup::ParserXBase::ValidOprtChars ( ) const

Virtual function that defines the characters allowed in operator definitions.

See also
ValidNameChars, #ValidPrefixOprtChars


muParserX documentation - (C) 2010 Ingo Berg