OpcUaCanOpen
CANopen OPC-UA server
mu::ParserTokenReader Class Reference

Token reader for the ParserBase class. More...

#include <muParserTokenReader.h>

Public Member Functions

 ParserTokenReader (ParserBase *a_pParent)
 Constructor. More...
 
ParserTokenReaderClone (ParserBase *a_pParent) const
 Create instance of a ParserTokenReader identical with this and return its pointer. More...
 
void AddValIdent (identfun_type a_pCallback)
 
void SetVarCreator (facfun_type a_pFactory, void *pUserData)
 
void SetFormula (const string_type &a_strFormula)
 Initialize the token Reader. More...
 
void SetArgSep (char_type cArgSep)
 
int GetPos () const
 Return the current position of the token reader in the formula string. More...
 
const string_typeGetExpr () const
 Return a reference to the formula. More...
 
varmap_typeGetUsedVar ()
 Return a map containing the used variables only. More...
 
char_type GetArgSep () const
 
void IgnoreUndefVar (bool bIgnore)
 Set Flag that controls behaviour in case of undefined variables being found. More...
 
void ReInit ()
 Reset the token reader to the start of the formula. More...
 
token_type ReadNextToken ()
 Read the next token from the string. More...
 

Private Types

enum  ESynCodes {
  noBO = 1 << 0, noBC = 1 << 1, noVAL = 1 << 2, noVAR = 1 << 3,
  noARG_SEP = 1 << 4, noFUN = 1 << 5, noOPT = 1 << 6, noPOSTOP = 1 << 7,
  noINFIXOP = 1 << 8, noEND = 1 << 9, noSTR = 1 << 10, noASSIGN = 1 << 11,
  noIF = 1 << 12, noELSE = 1 << 13, sfSTART_OF_LINE = noOPT | noBC | noPOSTOP | noASSIGN | noIF | noELSE | noARG_SEP, noANY = ~0
}
 Syntax codes. More...
 
typedef ParserToken< value_type, string_typetoken_type
 

Private Member Functions

 ParserTokenReader (const ParserTokenReader &a_Reader)
 Copy constructor. More...
 
ParserTokenReaderoperator= (const ParserTokenReader &a_Reader)
 Assignment operator. More...
 
void Assign (const ParserTokenReader &a_Reader)
 Assign state of a token reader to this token reader. More...
 
void SetParent (ParserBase *a_pParent)
 
int ExtractToken (const char_type *a_szCharSet, string_type &a_strTok, int a_iPos) const
 Extract all characters that belong to a certain charset. More...
 
int ExtractOperatorToken (string_type &a_sTok, int a_iPos) const
 Check Expression for the presence of a binary operator token. More...
 
bool IsBuiltIn (token_type &a_Tok)
 Check if a built in operator or other token can be found. More...
 
bool IsArgSep (token_type &a_Tok)
 
bool IsEOF (token_type &a_Tok)
 Check for End of Formula. More...
 
bool IsInfixOpTok (token_type &a_Tok)
 Check if a string position contains a unary infix operator. More...
 
bool IsFunTok (token_type &a_Tok)
 Check whether the token at a given position is a function token. More...
 
bool IsPostOpTok (token_type &a_Tok)
 Check if a string position contains a unary post value operator. More...
 
bool IsOprt (token_type &a_Tok)
 Check if a string position contains a binary operator. More...
 
bool IsValTok (token_type &a_Tok)
 Check whether the token at a given position is a value token. More...
 
bool IsVarTok (token_type &a_Tok)
 Check wheter a token at a given position is a variable token. More...
 
bool IsStrVarTok (token_type &a_Tok)
 
bool IsUndefVarTok (token_type &a_Tok)
 Check wheter a token at a given position is an undefined variable. More...
 
bool IsString (token_type &a_Tok)
 Check wheter a token at a given position is a string. More...
 
void Error (EErrorCodes a_iErrc, int a_iPos=-1, const string_type &a_sTok=string_type()) const
 Create an error containing the parse error position. More...
 
token_typeSaveBeforeReturn (const token_type &tok)
 

Private Attributes

ParserBasem_pParser
 
string_type m_strFormula
 
int m_iPos
 
int m_iSynFlags
 
bool m_bIgnoreUndefVar
 
const funmap_typem_pFunDef
 
const funmap_typem_pPostOprtDef
 
const funmap_typem_pInfixOprtDef
 
const funmap_typem_pOprtDef
 
const valmap_typem_pConstDef
 
const strmap_typem_pStrVarDef
 
varmap_typem_pVarDef
 The only non const pointer to parser internals. More...
 
facfun_type m_pFactory
 
void * m_pFactoryData
 
std::list< identfun_typem_vIdentFun
 Value token identification function. More...
 
varmap_type m_UsedVar
 
value_type m_fZero
 Dummy value of zero, referenced by undefined variables. More...
 
int m_iBrackets
 
token_type m_lastTok
 
char_type m_cArgSep
 The character used for separating function arguments. More...
 

Detailed Description

Token reader for the ParserBase class.

Definition at line 54 of file muParserTokenReader.h.

Member Typedef Documentation

◆ token_type

Member Enumeration Documentation

◆ ESynCodes

Syntax codes.

The syntax codes control the syntax check done during the first time parsing of the expression string. They are flags that indicate which tokens are allowed next if certain tokens are identified.

Enumerator
noBO 

to avoid i.e. "cos(7)("

noBC 

to avoid i.e. "sin)" or "()"

noVAL 

to avoid i.e. "tan 2" or "sin(8)3.14"

noVAR 

to avoid i.e. "sin a" or "sin(8)a"

noARG_SEP 

to avoid i.e. ",," or "+," ...

noFUN 

to avoid i.e. "sqrt cos" or "(1)sin"

noOPT 

to avoid i.e. "(+)"

noPOSTOP 

to avoid i.e. "(5!!)" "sin!"

noINFIXOP 

to avoid i.e. "++4" "!!4"

noEND 

to avoid unexpected end of formula

noSTR 

to block numeric arguments on string functions

noASSIGN 

to block assignment to constant i.e. "4=7"

noIF 
noELSE 
sfSTART_OF_LINE 
noANY 

All of he above flags set.

Definition at line 87 of file muParserTokenReader.h.

Constructor & Destructor Documentation

◆ ParserTokenReader() [1/2]

mu::ParserTokenReader::ParserTokenReader ( ParserBase a_pParent)

Constructor.

Create a Token reader and bind it to a parser object.

Precondition
[assert] a_pParser may not be NULL
Postcondition
m_pParser==a_pParser
Parameters
a_pParentParent parser object of the token reader.

Definition at line 113 of file muParserTokenReader.cpp.

◆ ParserTokenReader() [2/2]

mu::ParserTokenReader::ParserTokenReader ( const ParserTokenReader a_Reader)
private

Copy constructor.

See also
Assign
Exceptions
nothrow

Definition at line 52 of file muParserTokenReader.cpp.

Member Function Documentation

◆ AddValIdent()

void mu::ParserTokenReader::AddValIdent ( identfun_type  a_pCallback)

Definition at line 163 of file muParserTokenReader.cpp.

◆ Assign()

void mu::ParserTokenReader::Assign ( const ParserTokenReader a_Reader)
private

Assign state of a token reader to this token reader.

Parameters
a_ReaderObject from which the state should be copied.
Exceptions
nothrow

Definition at line 79 of file muParserTokenReader.cpp.

◆ Clone()

ParserTokenReader * mu::ParserTokenReader::Clone ( ParserBase a_pParent) const

Create instance of a ParserTokenReader identical with this and return its pointer.

This is a factory method the calling function must take care of the object destruction.

Returns
A new ParserTokenReader object.
Exceptions
nothrow

Definition at line 148 of file muParserTokenReader.cpp.

◆ Error()

void mu::ParserTokenReader::Error ( EErrorCodes  a_iErrc,
int  a_iPos = -1,
const string_type a_sTok = string_type() 
) const
private

Create an error containing the parse error position.

This function will create an Parser Exception object containing the error text and its position.

Parameters
a_iErrc[in] The error code of type EErrorCodes.
a_iPos[in] The position where the error was detected.
a_strTok[in] The token string representation associated with the error.
Exceptions
ParserExceptionalways throws thats the only purpose of this function.

Definition at line 939 of file muParserTokenReader.cpp.

◆ ExtractOperatorToken()

int mu::ParserTokenReader::ExtractOperatorToken ( string_type a_sTok,
int  a_iPos 
) const
private

Check Expression for the presence of a binary operator token.

Userdefined binary operator "++" gives inconsistent parsing result for the equations "a++b" and "a ++ b" if alphabetic characters are allowed in operator tokens. To avoid this this function checks specifically for operator tokens.

Definition at line 348 of file muParserTokenReader.cpp.

◆ ExtractToken()

int mu::ParserTokenReader::ExtractToken ( const char_type a_szCharSet,
string_type a_sTok,
int  a_iPos 
) const
private

Extract all characters that belong to a certain charset.

Parameters
a_szCharSet[in] Const char array of the characters allowed in the token.
a_strTok[out] The string that consists entirely of characters listed in a_szCharSet.
a_iPos[in] Position in the string from where to start reading.
Returns
The Position of the first character not listed in a_szCharSet.
Exceptions
nothrow

Definition at line 324 of file muParserTokenReader.cpp.

◆ GetArgSep()

char_type mu::ParserTokenReader::GetArgSep ( ) const

Definition at line 953 of file muParserTokenReader.cpp.

◆ GetExpr()

const string_type & mu::ParserTokenReader::GetExpr ( ) const

Return a reference to the formula.

Returns
m_strFormula
Exceptions
nothrow

Definition at line 198 of file muParserTokenReader.cpp.

◆ GetPos()

int mu::ParserTokenReader::GetPos ( ) const

Return the current position of the token reader in the formula string.

Returns
m_iPos
Exceptions
nothrow

Definition at line 187 of file muParserTokenReader.cpp.

◆ GetUsedVar()

varmap_type & mu::ParserTokenReader::GetUsedVar ( )

Return a map containing the used variables only.

Definition at line 205 of file muParserTokenReader.cpp.

◆ IgnoreUndefVar()

void mu::ParserTokenReader::IgnoreUndefVar ( bool  bIgnore)

Set Flag that controls behaviour in case of undefined variables being found.

If true, the parser does not throw an exception if an undefined variable is found. otherwise it does. This variable is used internally only! It suppresses a "undefined variable" exception in GetUsedVar().
Those function should return a complete list of variables including those the are not defined by the time of it's call.

Definition at line 231 of file muParserTokenReader.cpp.

◆ IsArgSep()

bool mu::ParserTokenReader::IsArgSep ( token_type a_Tok)
private

Definition at line 478 of file muParserTokenReader.cpp.

◆ IsBuiltIn()

bool mu::ParserTokenReader::IsBuiltIn ( token_type a_Tok)
private

Check if a built in operator or other token can be found.

Parameters
a_Tok[out] Operator token if one is found. This can either be a binary operator or an infix operator token.
Returns
true if an operator token has been found.

Definition at line 375 of file muParserTokenReader.cpp.

◆ IsEOF()

bool mu::ParserTokenReader::IsEOF ( token_type a_Tok)
private

Check for End of Formula.

Returns
true if an end of formula is found false otherwise.
Parameters
a_Tok[out] If an eof is found the corresponding token will be stored there.
Exceptions
nothrow
See also
IsOprt, IsFunTok, IsStrFunTok, IsValTok, IsVarTok, IsString, IsInfixOpTok, IsPostOpTok

Definition at line 509 of file muParserTokenReader.cpp.

◆ IsFunTok()

bool mu::ParserTokenReader::IsFunTok ( token_type a_Tok)
private

Check whether the token at a given position is a function token.

Parameters
a_Tok[out] If a value token is found it will be placed here.
Exceptions
ParserExceptionif Syntaxflags do not allow a function at a_iPos
Returns
true if a function token has been found false otherwise.
Precondition
[assert] m_pParser!=0

Definition at line 579 of file muParserTokenReader.cpp.

◆ IsInfixOpTok()

bool mu::ParserTokenReader::IsInfixOpTok ( token_type a_Tok)
private

Check if a string position contains a unary infix operator.

Returns
true if a function token has been found false otherwise.

Definition at line 534 of file muParserTokenReader.cpp.

◆ IsOprt()

bool mu::ParserTokenReader::IsOprt ( token_type a_Tok)
private

Check if a string position contains a binary operator.

Parameters
a_Tok[out] Operator token if one is found. This can either be a binary operator or an infix operator token.
Returns
true if an operator token has been found.

Definition at line 610 of file muParserTokenReader.cpp.

◆ IsPostOpTok()

bool mu::ParserTokenReader::IsPostOpTok ( token_type a_Tok)
private

Check if a string position contains a unary post value operator.

Definition at line 670 of file muParserTokenReader.cpp.

◆ IsString()

bool mu::ParserTokenReader::IsString ( token_type a_Tok)
private

Check wheter a token at a given position is a string.

Parameters
a_Tok[out] If a variable token has been found it will be placed here.
Returns
true if a string token has been found.
See also
IsOprt, IsFunTok, IsStrFunTok, IsValTok, IsVarTok, IsEOF, IsInfixOpTok, IsPostOpTok
Exceptions
nothrow

Definition at line 896 of file muParserTokenReader.cpp.

◆ IsStrVarTok()

bool mu::ParserTokenReader::IsStrVarTok ( token_type a_Tok)
private

Definition at line 809 of file muParserTokenReader.cpp.

◆ IsUndefVarTok()

bool mu::ParserTokenReader::IsUndefVarTok ( token_type a_Tok)
private

Check wheter a token at a given position is an undefined variable.

Parameters
a_Tok[out] If a variable tom_pParser->m_vStringBufken has been found it will be placed here.
Returns
true if a variable token has been found.
Exceptions
nothrow

Definition at line 844 of file muParserTokenReader.cpp.

◆ IsValTok()

bool mu::ParserTokenReader::IsValTok ( token_type a_Tok)
private

Check whether the token at a given position is a value token.

Value tokens are either values or constants.

Parameters
a_Tok[out] If a value token is found it will be placed here.
Returns
true if a value token has been found.

Definition at line 722 of file muParserTokenReader.cpp.

◆ IsVarTok()

bool mu::ParserTokenReader::IsVarTok ( token_type a_Tok)
private

Check wheter a token at a given position is a variable token.

Parameters
a_Tok[out] If a variable token has been found it will be placed here.
Returns
true if a variable token has been found.

Definition at line 778 of file muParserTokenReader.cpp.

◆ operator=()

ParserTokenReader & mu::ParserTokenReader::operator= ( const ParserTokenReader a_Reader)
private

Assignment operator.

Self assignment will be suppressed otherwise Assign is called.

Parameters
a_ReaderObject to copy to this token reader.
Exceptions
nothrow

Definition at line 65 of file muParserTokenReader.cpp.

◆ ReadNextToken()

ParserTokenReader::token_type mu::ParserTokenReader::ReadNextToken ( )

Read the next token from the string.

Definition at line 256 of file muParserTokenReader.cpp.

◆ ReInit()

void mu::ParserTokenReader::ReInit ( )

Reset the token reader to the start of the formula.

The syntax flags will be reset to a value appropriate for the start of a formula.

Postcondition
m_iPos==0, m_iSynFlags = noOPT | noBC | noPOSTOP | noSTR
Exceptions
nothrow
See also
ESynCodes

Definition at line 245 of file muParserTokenReader.cpp.

◆ SaveBeforeReturn()

ParserTokenReader::token_type & mu::ParserTokenReader::SaveBeforeReturn ( const token_type tok)
private

Definition at line 156 of file muParserTokenReader.cpp.

◆ SetArgSep()

void mu::ParserTokenReader::SetArgSep ( char_type  cArgSep)

Definition at line 947 of file muParserTokenReader.cpp.

◆ SetFormula()

void mu::ParserTokenReader::SetFormula ( const string_type a_strFormula)

Initialize the token Reader.

Sets the formula position index to zero and set Syntax flags to default for initial formula parsing.

Precondition
[assert] triggered if a_szFormula==0

Definition at line 216 of file muParserTokenReader.cpp.

◆ SetParent()

void mu::ParserTokenReader::SetParent ( ParserBase a_pParent)
private

Definition at line 303 of file muParserTokenReader.cpp.

◆ SetVarCreator()

void mu::ParserTokenReader::SetVarCreator ( facfun_type  a_pFactory,
void *  pUserData 
)

Definition at line 175 of file muParserTokenReader.cpp.

Member Data Documentation

◆ m_bIgnoreUndefVar

bool mu::ParserTokenReader::m_bIgnoreUndefVar
private

Definition at line 139 of file muParserTokenReader.h.

◆ m_cArgSep

char_type mu::ParserTokenReader::m_cArgSep
private

The character used for separating function arguments.

Definition at line 155 of file muParserTokenReader.h.

◆ m_fZero

value_type mu::ParserTokenReader::m_fZero
private

Dummy value of zero, referenced by undefined variables.

Definition at line 152 of file muParserTokenReader.h.

◆ m_iBrackets

int mu::ParserTokenReader::m_iBrackets
private

Definition at line 153 of file muParserTokenReader.h.

◆ m_iPos

int mu::ParserTokenReader::m_iPos
private

Definition at line 137 of file muParserTokenReader.h.

◆ m_iSynFlags

int mu::ParserTokenReader::m_iSynFlags
private

Definition at line 138 of file muParserTokenReader.h.

◆ m_lastTok

token_type mu::ParserTokenReader::m_lastTok
private

Definition at line 154 of file muParserTokenReader.h.

◆ m_pConstDef

const valmap_type* mu::ParserTokenReader::m_pConstDef
private

Definition at line 145 of file muParserTokenReader.h.

◆ m_pFactory

facfun_type mu::ParserTokenReader::m_pFactory
private

Definition at line 148 of file muParserTokenReader.h.

◆ m_pFactoryData

void* mu::ParserTokenReader::m_pFactoryData
private

Definition at line 149 of file muParserTokenReader.h.

◆ m_pFunDef

const funmap_type* mu::ParserTokenReader::m_pFunDef
private

Definition at line 141 of file muParserTokenReader.h.

◆ m_pInfixOprtDef

const funmap_type* mu::ParserTokenReader::m_pInfixOprtDef
private

Definition at line 143 of file muParserTokenReader.h.

◆ m_pOprtDef

const funmap_type* mu::ParserTokenReader::m_pOprtDef
private

Definition at line 144 of file muParserTokenReader.h.

◆ m_pParser

ParserBase* mu::ParserTokenReader::m_pParser
private

Definition at line 135 of file muParserTokenReader.h.

◆ m_pPostOprtDef

const funmap_type* mu::ParserTokenReader::m_pPostOprtDef
private

Definition at line 142 of file muParserTokenReader.h.

◆ m_pStrVarDef

const strmap_type* mu::ParserTokenReader::m_pStrVarDef
private

Definition at line 146 of file muParserTokenReader.h.

◆ m_pVarDef

varmap_type* mu::ParserTokenReader::m_pVarDef
private

The only non const pointer to parser internals.

Definition at line 147 of file muParserTokenReader.h.

◆ m_strFormula

string_type mu::ParserTokenReader::m_strFormula
private

Definition at line 136 of file muParserTokenReader.h.

◆ m_UsedVar

varmap_type mu::ParserTokenReader::m_UsedVar
private

Definition at line 151 of file muParserTokenReader.h.

◆ m_vIdentFun

std::list<identfun_type> mu::ParserTokenReader::m_vIdentFun
private

Value token identification function.

Definition at line 150 of file muParserTokenReader.h.


The documentation for this class was generated from the following files: