#include <muParserTokenReader.h>
Public Member Functions | |
ParserTokenReader (ParserBase *a_pParent) | |
Constructor. | |
ParserTokenReader * | Clone (ParserBase *a_pParent) const |
Create instance of a ParserTokenReader identical with this and return its pointer. | |
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. | |
void | SetArgSep (char_type cArgSep) |
int | GetPos () const |
Return the current position of the token reader in the formula string. | |
const string_type & | GetFormula () const |
Return a reference to the formula. | |
const varmap_type & | GetUsedVar () const |
Return a map containing the used variables only. | |
char_type | GetArgSep () const |
void | IgnoreUndefVar (bool bIgnore) |
Set Flag that contronls behaviour in case of undefined variables beeing found. | |
void | ReInit () |
Reset the token reader to the start of the formula. | |
token_type | ReadNextToken () |
Read the next token from the string. | |
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, noANY = ~0 } |
Syntax codes. More... | |
typedef ParserToken < value_type, string_type > | token_type |
Private Member Functions | |
ParserTokenReader (const ParserTokenReader &a_Reader) | |
Copy constructor. | |
ParserTokenReader & | operator= (const ParserTokenReader &a_Reader) |
Assignement operator. | |
void | Assign (const ParserTokenReader &a_Reader) |
Assign state of a token reader to this token reader. | |
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. | |
bool | IsBuiltIn (token_type &a_Tok) |
Check if a built in operator or other token can be found. | |
bool | IsArgSep (token_type &a_Tok) |
bool | IsEOF (token_type &a_Tok) |
Check for End of Formula. | |
bool | IsInfixOpTok (token_type &a_Tok) |
Check if a string position contains a unary infix operator. | |
bool | IsFunTok (token_type &a_Tok) |
Check whether the token at a given position is a function token. | |
bool | IsPostOpTok (token_type &a_Tok) |
Check if a string position contains a unary post value operator. | |
bool | IsOprt (token_type &a_Tok) |
Check if a string position contains a binary operator. | |
bool | IsValTok (token_type &a_Tok) |
Check whether the token at a given position is a value token. | |
bool | IsVarTok (token_type &a_Tok) |
Check wheter a token at a given position is a variable token. | |
bool | IsStrVarTok (token_type &a_Tok) |
bool | IsUndefVarTok (token_type &a_Tok) |
Check wheter a token at a given position is an undefined variable. | |
bool | IsString (token_type &a_Tok) |
Check wheter a token at a given position is a string. | |
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. | |
token_type & | SaveBeforeReturn (const token_type &tok) |
Private Attributes | |
ParserBase * | m_pParser |
string_type | m_strFormula |
int | m_iPos |
int | m_iSynFlags |
bool | m_bIgnoreUndefVar |
const funmap_type * | m_pFunDef |
const funmap_type * | m_pPostOprtDef |
const funmap_type * | m_pInfixOprtDef |
const funmap_type * | m_pOprtDef |
const valmap_type * | m_pConstDef |
const strmap_type * | m_pStrVarDef |
varmap_type * | m_pVarDef |
The only non const pointer to parser internals. | |
facfun_type | m_pFactory |
void * | m_pFactoryData |
std::vector< identfun_type > | m_vIdentFun |
Value token identification function. | |
varmap_type | m_UsedVar |
value_type | m_fZero |
Dummy value of zero, referenced by undefined variables. | |
int | m_iBrackets |
token_type | m_lastTok |
char_type | m_cArgSep |
The character used for separating function arguments. |
enum mu::ParserTokenReader::ESynCodes [private] |
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.
mu::ParserTokenReader::ParserTokenReader | ( | ParserBase * | a_pParent | ) |
Constructor.
Create a Token reader and bind it to a parser object.
a_pParent | Parent parser object of the token reader. |
Referenced by Clone().
mu::ParserTokenReader::ParserTokenReader | ( | const ParserTokenReader & | a_Reader | ) | [private] |
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.
nothrow |
References ParserTokenReader().
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.
References ReInit().
int mu::ParserTokenReader::GetPos | ( | ) | const |
Return the current position of the token reader in the formula string.
nothrow |
const string_type & mu::ParserTokenReader::GetFormula | ( | ) | const |
Return a reference to the formula.
nothrow |
void mu::ParserTokenReader::IgnoreUndefVar | ( | bool | bIgnore | ) |
Set Flag that contronls behaviour in case of undefined variables beeing 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 supresses 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.
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.
nothrow |
References noASSIGN, noBC, noOPT, and noPOSTOP.
Referenced by SetFormula().
ParserTokenReader & mu::ParserTokenReader::operator= | ( | const ParserTokenReader & | a_Reader | ) | [private] |
void mu::ParserTokenReader::Assign | ( | const ParserTokenReader & | a_Reader | ) | [private] |
Assign state of a token reader to this token reader.
a_Reader | Object from which the state should be copied. |
nothrow |
References m_bIgnoreUndefVar, m_cArgSep, m_iBrackets, m_iPos, m_iSynFlags, m_pConstDef, m_pFactory, m_pFactoryData, m_pFunDef, m_pInfixOprtDef, m_pOprtDef, m_pParser, m_pPostOprtDef, m_pStrVarDef, m_pVarDef, m_strFormula, m_UsedVar, and m_vIdentFun.
Referenced by operator=(), and ParserTokenReader().
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.
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. |
nothrow |
Referenced by IsFunTok(), IsInfixOpTok(), IsOprt(), IsPostOpTok(), IsUndefVarTok(), IsValTok(), IsVarTok(), and ReadNextToken().
bool mu::ParserTokenReader::IsBuiltIn | ( | token_type & | a_Tok | ) | [private] |
Check if a built in operator or other token can be found.
a_Tok | [out] Operator token if one is found. This can either be a binary operator or an infix operator token. |
References mu::cmADD, mu::cmAND, mu::cmASSIGN, mu::cmBC, mu::cmBO, mu::cmDIV, mu::cmEND, mu::cmEQ, mu::cmFUNC, mu::cmGE, mu::cmGT, mu::cmLE, mu::cmLT, mu::cmMUL, mu::cmNEQ, mu::cmOR, mu::cmPOW, mu::cmSUB, mu::cmXOR, mu::ecINTERNAL_ERROR, mu::ecUNEXPECTED_OPERATOR, mu::ecUNEXPECTED_PARENS, Error(), mu::ParserToken< TBase, TString >::GetCode(), mu::ParserBase::GetOprtDef(), mu::ParserBase::HasBuiltInOprt(), IsInfixOpTok(), noARG_SEP, noASSIGN, noBC, noBO, noEND, noFUN, noINFIXOP, noOPT, noPOSTOP, noSTR, noVAL, noVAR, and mu::ParserToken< TBase, TString >::Set().
Referenced by ReadNextToken().
bool mu::ParserTokenReader::IsEOF | ( | token_type & | a_Tok | ) | [private] |
Check for End of Formula.
a_Tok | [out] If an eof is found the corresponding token will be stored there. |
nothrow |
References mu::cmEND, mu::ecMISSING_PARENS, mu::ecUNEXPECTED_EOF, Error(), noEND, and mu::ParserToken< TBase, TString >::Set().
Referenced by ReadNextToken().
bool mu::ParserTokenReader::IsInfixOpTok | ( | token_type & | a_Tok | ) | [private] |
Check if a string position contains a unary infix operator.
References mu::ecUNEXPECTED_OPERATOR, Error(), ExtractToken(), mu::ParserToken< TBase, TString >::GetAsString(), noASSIGN, noBC, noINFIXOP, noOPT, noPOSTOP, noSTR, mu::ParserToken< TBase, TString >::Set(), and mu::ParserBase::ValidInfixOprtChars().
Referenced by IsBuiltIn(), IsOprt(), and ReadNextToken().
bool mu::ParserTokenReader::IsFunTok | ( | token_type & | a_Tok | ) | [private] |
Check whether the token at a given position is a function token.
a_Tok | [out] If a value token is found it will be placed here. |
ParserException | if Syntaxflags do not allow a function at a_iPos |
References mu::ecUNEXPECTED_FUN, Error(), ExtractToken(), mu::ParserToken< TBase, TString >::GetAsString(), noANY, noBO, noFUN, mu::ParserToken< TBase, TString >::Set(), and mu::ParserBase::ValidNameChars().
Referenced by ReadNextToken().
bool mu::ParserTokenReader::IsOprt | ( | token_type & | a_Tok | ) | [private] |
Check if a string position contains a binary operator.
a_Tok | [out] Operator token if one is found. This can either be a binary operator or an infix operator token. |
References mu::ecUNEXPECTED_OPERATOR, Error(), ExtractToken(), mu::ParserToken< TBase, TString >::GetAsString(), IsInfixOpTok(), noARG_SEP, noASSIGN, noBC, noEND, noOPT, noPOSTOP, mu::ParserToken< TBase, TString >::Set(), and mu::ParserBase::ValidOprtChars().
Referenced by ReadNextToken().
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.
a_Tok | [out] If a value token is found it will be placed here. |
References mu::ecUNEXPECTED_VAL, Error(), ExtractToken(), m_vIdentFun, noASSIGN, noBO, noFUN, noINFIXOP, noSTR, noVAL, noVAR, mu::ParserToken< TBase, TString >::SetVal(), and mu::ParserBase::ValidNameChars().
Referenced by ReadNextToken().
bool mu::ParserTokenReader::IsVarTok | ( | token_type & | a_Tok | ) | [private] |
Check wheter a token at a given position is a variable token.
a_Tok | [out] If a variable token has been found it will be placed here. |
References mu::ecUNEXPECTED_VAR, Error(), ExtractToken(), m_pVarDef, noBO, noFUN, noINFIXOP, noPOSTOP, noSTR, noVAL, noVAR, mu::ParserToken< TBase, TString >::SetVar(), and mu::ParserBase::ValidNameChars().
Referenced by ReadNextToken().
bool mu::ParserTokenReader::IsUndefVarTok | ( | token_type & | a_Tok | ) | [private] |
Check wheter a token at a given position is an undefined variable.
a_Tok | [out] If a variable tom_pParser->m_vStringBufken has been found it will be placed here. |
nothrow |
References mu::ecUNEXPECTED_VAR, Error(), ExtractToken(), mu::ParserToken< TBase, TString >::GetAsString(), m_fZero, noBO, noFUN, noINFIXOP, noPOSTOP, noVAL, noVAR, mu::ParserToken< TBase, TString >::SetVar(), and mu::ParserBase::ValidNameChars().
Referenced by ReadNextToken().
bool mu::ParserTokenReader::IsString | ( | token_type & | a_Tok | ) | [private] |
Check wheter a token at a given position is a string.
a_Tok | [out] If a variable token has been found it will be placed here. |
nothrow |
References mu::ecUNEXPECTED_STR, mu::ecUNTERMINATED_STRING, Error(), mu::ParserBase::m_vStringBuf, noANY, noARG_SEP, noBC, noEND, noOPT, and mu::ParserToken< TBase, TString >::SetString().
Referenced by ReadNextToken().
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.
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. |
ParserException | always throws thats the only purpose of this function. |
References mu::ParserBase::Error().
Referenced by IsBuiltIn(), IsEOF(), IsFunTok(), IsInfixOpTok(), IsOprt(), IsPostOpTok(), IsString(), IsUndefVarTok(), IsValTok(), IsVarTok(), and ReadNextToken().