本文整理汇总了C++中scanner_t::eat_token方法的典型用法代码示例。如果您正苦于以下问题:C++ scanner_t::eat_token方法的具体用法?C++ scanner_t::eat_token怎么用?C++ scanner_t::eat_token使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scanner_t
的用法示例。
在下文中一共展示了scanner_t::eat_token方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Label
void parser_t::Label() {
parsetree.push(NT_Label);
scanner.eat_token(T_label);
scanner.eat_token(T_num);
scanner.eat_token(T_colon);
cerr_buffer.push_back("L" + scanner.get_number() + ":\n");
parsetree.pop();
}
示例2: Assignment
void parser_t::Assignment() {
parsetree.push(NT_Assignment);
scanner.eat_token(T_m);
scanner.eat_token(T_opensquare);
cerr_buffer.push_back("m[");
Expression();
scanner.eat_token(T_closesquare);
scanner.eat_token(T_equals);
cerr_buffer.push_back("]=");
Expression();
cerr_buffer.push_back(";\n");
parsetree.pop();
}
示例3: Print
void parser_t::Print() {
parsetree.push(NT_Print);
scanner.eat_token(T_print);
cerr_buffer.push_back("printf(\"%d\",");
Expression();
cerr_buffer.push_back(");\n");
parsetree.pop();
}
示例4: Jump
void parser_t::Jump() {
parsetree.push(NT_Jump);
scanner.eat_token(T_goto);
scanner.eat_token(T_num);
cerr_buffer.push_back("goto L" + scanner.get_number() + ";\n");
if (scanner.next_token() == T_if) {
scanner.eat_token(T_if);
// Insert if statement before goto
string goto_str = cerr_buffer.back();
cerr_buffer.pop_back();
cerr_buffer.push_back("if (");
Expression();
cerr_buffer.push_back(") {\n");
cerr_buffer.push_back(goto_str);
cerr_buffer.push_back("}\n");
}
parsetree.pop();
}
示例5: BracketTerm
void parser_t::BracketTerm() {
parsetree.push(NT_BracketTerm);
switch (scanner.next_token()) {
case T_openparen:
scanner.eat_token(T_openparen);
cerr_buffer.push_back("(");
Expression();
scanner.eat_token(T_closeparen);
cerr_buffer.push_back(")");
break;
case T_m:
scanner.eat_token(T_m);
scanner.eat_token(T_opensquare);
cerr_buffer.push_back("m[");
Expression();
scanner.eat_token(T_closesquare);
cerr_buffer.push_back("]");
break;
case T_num:
scanner.eat_token(T_num);
cerr_buffer.push_back(scanner.get_number());
break;
default:
syntax_error(NT_BracketTerm);
}
parsetree.pop();
}
示例6: Statements
//WRITEME: you will need to put the rest of the procedures here
void parser_t::Statements() {
parsetree.push(NT_Statements);
Statement();
if (scanner.next_token() != T_eof) {
Statements();
} else {
scanner.eat_token(T_eof);
parsetree.drawepsilon();
}
parsetree.pop();
}
示例7: TermRight
void parser_t::TermRight() {
parsetree.push(NT_TermRight);
switch (scanner.next_token()) {
case T_times:
scanner.eat_token(T_times);
cerr_buffer.push_back("*");
ExponentialTerm();
TermRight();
break;
case T_divide:
scanner.eat_token(T_divide);
cerr_buffer.push_back("/");
ExponentialTerm();
TermRight();
break;
default:
parsetree.drawepsilon();
break;
}
parsetree.pop();
}
示例8: ExpressionRight
void parser_t::ExpressionRight() {
parsetree.push(NT_ExpressionRight);
switch (scanner.next_token()) {
case T_plus:
scanner.eat_token(T_plus);
cerr_buffer.push_back("+");
Term();
ExpressionRight();
break;
case T_minus:
scanner.eat_token(T_minus);
cerr_buffer.push_back("-");
Term();
ExpressionRight();
break;
default:
parsetree.drawepsilon();
break;
}
parsetree.pop();
}
示例9: ExponentialTerm
void parser_t::ExponentialTerm() {
parsetree.push(NT_ExponentialTerm);
cerr_buffer.push_back("pow(");
BracketTerm();
if (scanner.next_token() == T_power) {
scanner.eat_token(T_power);
cerr_buffer.push_back(",");
ExponentialTerm();
cerr_buffer.push_back(")");
} else {
for (vector<string>::reverse_iterator itr = cerr_buffer.rbegin(); itr != cerr_buffer.rend(); itr++) {
if (*itr == "pow(") {
cerr_buffer.erase(--(itr.base()));
break;
}
}
}
parsetree.pop();
}
示例10: eat_token
//this function not only eats the token (moving the scanner forward one
//token), it also makes sure that token is drawn in the parse tree
//properly by calling push and pop.
void parser_t::eat_token(token_type t)
{
parsetree.push(t);
scanner.eat_token(t);
parsetree.pop();
}