/** \brief Read the next token from the string. */ ParserTokenReader::token_type ParserTokenReader::ReadNextToken() { assert(m_pParser); std::stack<int> FunArgs; const char_type *szFormula = m_strFormula.c_str(); token_type tok; // Ignore all non printable characters when reading the expression while (szFormula[m_iPos]>0 && szFormula[m_iPos]<=0x20) ++m_iPos; if ( IsEOF(tok) ) return SaveBeforeReturn(tok); // Check for end of formula if ( IsOprt(tok) ) return SaveBeforeReturn(tok); // Check for user defined binary operator if ( IsFunTok(tok) ) return SaveBeforeReturn(tok); // Check for function token if ( IsBuiltIn(tok) ) return SaveBeforeReturn(tok); // Check built in operators / tokens if ( IsArgSep(tok) ) return SaveBeforeReturn(tok); // Check for function argument separators if ( IsValTok(tok) ) return SaveBeforeReturn(tok); // Check for values / constant tokens if ( IsVarTok(tok) ) return SaveBeforeReturn(tok); // Check for variable tokens if ( IsStrVarTok(tok) ) return SaveBeforeReturn(tok); // Check for string variables if ( IsString(tok) ) return SaveBeforeReturn(tok); // Check for String tokens if ( IsInfixOpTok(tok) ) return SaveBeforeReturn(tok); // Check for unary operators if ( IsPostOpTok(tok) ) return SaveBeforeReturn(tok); // Check for unary operators // Check String for undefined variable token. Done only if a // flag is set indicating to ignore undefined variables. // This is a way to conditionally avoid an error if // undefined variables occur. // (The GetUsedVar function must suppress the error for // undefined variables in order to collect all variable // names including the undefined ones.) if ( (m_bIgnoreUndefVar || m_pFactory) && IsUndefVarTok(tok) ) return SaveBeforeReturn(tok); // Check for unknown token // // !!! From this point on there is no exit without an exception possible... // string_type strTok; int iEnd = ExtractToken(m_pParser->ValidNameChars(), strTok, m_iPos); if (iEnd!=m_iPos) Error(ecUNASSIGNABLE_TOKEN, m_iPos, strTok); Error(ecUNASSIGNABLE_TOKEN, m_iPos, m_strFormula.substr(m_iPos)); return token_type(); // never reached }
/** \brief Read the next token from the string. */ ptr_tok_type TokenReader::ReadNextToken() { assert(m_pParser); SkipCommentsAndWhitespaces(); int token_pos = m_nPos; ptr_tok_type pTok; // Check for end of expression if (IsEOF(pTok)) return Store(pTok, token_pos); if (IsNewline(pTok)) return Store(pTok, token_pos); if (!(m_nSynFlags & noOPT) && IsOprt(pTok)) return Store(pTok, token_pos); // Check for user defined binary operator if (!(m_nSynFlags & noIFX) && IsInfixOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators if (IsValTok(pTok)) return Store(pTok, token_pos); // Check for values / constant tokens if (IsBuiltIn(pTok)) return Store(pTok, token_pos); // Check built in operators / tokens if (IsVarOrConstTok(pTok)) return Store(pTok, token_pos); // Check for variable tokens if (IsFunTok(pTok)) return Store(pTok, token_pos); if (!(m_nSynFlags & noPFX) && IsPostOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators // 2.) We have found no token, maybe there is a token that we don't expect here. // Again call the Identifier functions but this time only those we don't expect // to find. if ((m_nSynFlags & noOPT) && IsOprt(pTok)) return Store(pTok, token_pos); // Check for user defined binary operator if ((m_nSynFlags & noIFX) && IsInfixOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators if ((m_nSynFlags & noPFX) && IsPostOpTok(pTok)) return Store(pTok, token_pos); // Check for unary operators // </ibg> // Now we are in trouble because there is something completely unknown.... // Check the string for an undefined variable token. This is done // only if a flag is set indicating to ignore undefined variables. // This is a way to conditionally avoid an error if undefined variables // occur. The GetExprVar function must supress the error for undefined // variables in order to collect all variable names including the // undefined ones. if ((m_pParser->m_bIsQueryingExprVar || m_pParser->m_bAutoCreateVar) && IsUndefVarTok(pTok)) return Store(pTok, token_pos); // Check for unknown token // // !!! From this point on there is no exit without an exception possible... // string_type sTok; int iEnd = ExtractToken(m_pParser->ValidNameChars(), sTok, m_nPos); ErrorContext err; err.Errc = ecUNASSIGNABLE_TOKEN; err.Expr = m_sExpr; err.Pos = m_nPos; if (iEnd != m_nPos) err.Ident = sTok; else err.Ident = m_sExpr.substr(m_nPos); throw ParserError(err); }