本文整理汇总了C++中Lexer::PeekToken方法的典型用法代码示例。如果您正苦于以下问题:C++ Lexer::PeekToken方法的具体用法?C++ Lexer::PeekToken怎么用?C++ Lexer::PeekToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lexer
的用法示例。
在下文中一共展示了Lexer::PeekToken方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: process_test_lexer_one_token
/*********************************************************************
*
* Function: process_test_lexer_one_token
* Purpose:
*
*********************************************************************/
static void process_test_lexer_one_token(const string &line,
int token_start, int line_number,
const Parameters ¶meters,
ErrorCount *errors)
{
string token_string, expected_token_type;
string extra;
token_string = extract_token(&token_start, line);
expected_token_type = extract_token(&token_start, line);
extra = extract_token(&token_start, line);
if (!token_string.compare("")
|| !expected_token_type.compare("")) {
cout << "Error: Missing match information on line " << line_number
<< "." << endl;
cout << " Format: test-lexer-one-token <token> <token-type> "
<< endl;
errors->IncrementErrors();
}
else if (extra.compare("")) {
cout << "Ignored extra input (" << extra << ") on line "
<< line_number << "." << endl;
}
Lexer lexer;
Lexer::TokenType token_type;
const char *token_name;
StringLexerSource *lexer_source;
lexer_source = new StringLexerSource(&token_string);
if (lexer_source == NULL) {
cout << "Error: Couldn't allocate LexerSource! on line ";
cout << line_number << "." << endl;
} else {
lexer.Initialize(lexer_source);
token_type = lexer.PeekToken(NULL);
token_name = lexer.strLexToken(token_type);
lexer.FinishedParse();
if (!strcmp(expected_token_type.c_str(), token_name)) {
cout << "OK: Token type for \"" << token_string << "\" is "
<< token_name << " on line " << line_number
<< "." << endl;
}
else {
cout << "Error: Token type for \"" << token_string << "\" is not "
<< expected_token_type << " but is \"" << token_name
<< "\" on line " << line_number << "." << endl;
errors->IncrementErrors();
}
delete lexer_source;
}
return;
}