Пример #1
0
static int lex(cstate *cs, int value)
{
    int tok = _lex(cs, value);
    printf("TOKEN(%d) %s %s\n", value, TOKENNAMES[tok],
           tok == T_TEXT ? cs->text : "");
    return tok;
}
Пример #2
0
//
//	Get the next token for the parser, invoking yylex_token to get the next token from the lexer.
//	This routine gets renamed to buffered_yylex by a #define when using yacc so that the two purposes
//	above are split allowing lookahead buffering and primimimg to occur.
//
int CxxLexer::lex(CxxParser::semantic_type* yylval, CxxParser::location_type* yylloc)
{
    this->_yylval = yylval;
//     if(CxxDriver::Instance()->waitForExpressionParsingStart())
//     {
//         CxxDriver::Instance()->setExpressionParsingStarted();
//         yylval->token = CxxToken::dollarToken;
//         return yylval->token->value();
//     }
    CxxToken *aToken = primed_tokens[0];
    if (aToken)
    {
        primed_tokens[0] = primed_tokens[1];
        primed_tokens[1] = primed_tokens[2];
        primed_tokens[2] = 0;
    }
    else if (tokenReadIndex < tokenWriteIndex)
    {
        aToken = tokenBuffer[tokenReadIndex++];
    }
    else
    {
        aToken = (!_lex(yylval, yylloc)) ? 0 : CxxToken::yyToken;
        if (!aToken)
            return 0;
        if (tokenMarkDepth > 0)
            token_put(aToken);
        else
        {
            tokenWriteIndex = 0;
            tokenReadIndex = 0;
        }
    }
    yylval->token = aToken;
    return aToken->value();
}