当前位置: 首页>>代码示例>>C++>>正文


C++ scanner_t::next_token方法代码示例

本文整理汇总了C++中scanner_t::next_token方法的典型用法代码示例。如果您正苦于以下问题:C++ scanner_t::next_token方法的具体用法?C++ scanner_t::next_token怎么用?C++ scanner_t::next_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scanner_t的用法示例。


在下文中一共展示了scanner_t::next_token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Jump

void parser_t::Jump()
{
	parsetree.push(NT_Jump);

	if(scanner.next_token() == T_goto)
	{
		eat_token(T_goto);
		scanner.next_token();
		std::string tmp =  scanner.get_token_value();
		eat_token(T_num);

		//If there's an if statement, handle it it.
		if(scanner.next_token() == T_if) {
			eat_token(T_if);
			current = current + "if(";
			Expression();
			current = current + " != 0) { ";
			current = current + "goto L" + tmp + "; }\n ";
		}
		else {
			current = current + " goto L" + tmp + ";\n ";
		}
	}
	else { syntax_error(NT_Jump); }

	parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:27,代码来源:calc.cpp

示例2: Label

void parser_t::Label() 
{
	parsetree.push(NT_Label);

	if(scanner.next_token() == T_label) 
	{
		eat_token(T_label);
		current = c_code_main;
		scanner.next_token();
		current = current + "\n L" + scanner.get_token_value() + ":\n ";
				// printf("current:\n%s\n", current.c_str());

		eat_token(T_num);
		eat_token(T_colon);
		LabelStatements();
		// printf("current:\n%s\n", current.c_str());

   
		c_code_main = current;
		current = c_code_main;
		printf("%s\n", c_code_main.c_str());

	}
	else { syntax_error(NT_Label); }
	parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:26,代码来源:calc.cpp

示例3: Assignment

string parser_t::Assignment(string s)
{
    token_type watch = scanner.next_token();
    parsetree.push(NT_Assignment);
    if(watch == T_m){
        s.append("m");
        eat_token(T_m);
        s.append("[");
        eat_token(T_opensquare);
        s = Expression(s);
        s.append("]");
        eat_token(T_closesquare);
        s.append("=");
        eat_token(T_equals);
        s = Expression(s);
    }else{
        syntax_error(NT_Print);
    }
    watch = scanner.next_token();
    switch(watch){
        case T_eof:
        case T_label:
        case T_goto:
        case T_m:
        case T_print:
            break;
        default:
            syntax_error(NT_Print);
            break;
    }
    parsetree.pop();
    return s;
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:33,代码来源:calc.cpp

示例4: Jump

string parser_t::Jump(string s)
{
    token_type watch = scanner.next_token();
    parsetree.push(NT_Jump);
    if(watch == T_goto){
        eat_token(T_goto);
        s = Forward(s);
    }else{
        syntax_error(NT_Jump);
    }
    watch = scanner.next_token();
    switch(watch){
        case T_eof:
        case T_label:
        case T_goto:
        case T_m:
        case T_print:
            break;
        default:
            syntax_error(NT_Jump);
            break;
    }
    parsetree.pop();
    return s;
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:25,代码来源:calc.cpp

示例5: Factor

void parser_t::Factor()
{
	parsetree.push(NT_Factor);

	if(scanner.next_token() == T_num) 
	{
		current = current + scanner.get_token_value();
		// printf("%s\n", current.c_str());
		eat_token(T_num);
	}
	else if(scanner.next_token() == T_m) 
	{
		eat_token(T_m);
		eat_token(T_opensquare);
		current = current + "m[";
		Expression();

		eat_token(T_closesquare);
		current = current + "]";
	}
	else { syntax_error(NT_Factor); }

	parsetree.pop();

}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:25,代码来源:calc.cpp

示例6: Derivestate

void parser_t::Derivestate(){
  parsetree.push(NT_Derivestate);
  switch(scanner.next_token())
    {
    case T_label:
      Statement();
      Derivestate();
      break;
    case T_goto:
      Statement();
      Derivestate();
      break;
    case T_m:
      Statement();
      Derivestate();
      break;
    case T_print:
      Statement();
      Derivestate();
      break;
    case T_eof:
       eat_token(scanner.next_token());
       // parsetree.drawepsilon();
      //   cout<<"done"<<endl;
      break;
    default:
      syntax_error(NT_Derivestate);
	break;
    }
  parsetree.pop();


}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:33,代码来源:calc.cpp

示例7: Statement

void parser_t::Statement()
{
    string s;
    token_type watch = scanner.next_token();
    parsetree.push(NT_Statement);
    if(watch == T_label){
        s = Label(s);
    }else if(watch == T_goto){
        s = Jump(s);
    }else if(watch == T_m){
        s = Assignment(s);
    }else if(watch == T_print){
        s = Print(s);
    }else{
        syntax_error(NT_Statement);
    }
    cerr<<s<<";"<<endl;
    watch = scanner.next_token();
    switch(watch){
        case T_eof:
        case T_label:
        case T_goto:
        case T_m:
        case T_print:
            break;
        default:
            syntax_error(NT_Statement);
            break;
    }
    parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:31,代码来源:calc.cpp

示例8: Factor

void parser_t::Factor()
{
	//push this non-terminal onto the parse tree.
	//the parsetree class is just for drawing the finished
	//parse tree, and should in should have no effect the actual
	//parsing of the data
	parsetree.push(NT_Factor);

	switch( scanner.next_token() ) 
	{
		case T_num:
			eat_token(T_num);
			if(scanner.next_token()==T_power)
			{
				powBuffer=scanner.numberList[numberListSpot];
			}
			else
				cerr << scanner.numberList[numberListSpot];
			numberListSpot++;
			break;
		case T_m:
			eat_token(T_m);
			cerr << "m";
			if (scanner.next_token() == T_opensquare)
			{
				eat_token(T_opensquare);
				cerr << "[";
				Expression();
				if(scanner.next_token() == T_closesquare)
				{
					eat_token(T_closesquare);
					cerr << "]";
				}
				else
					syntax_error(NT_Factor);
			}
			else
				syntax_error(NT_Factor);
			break;
		case T_openparen:
			eat_token(T_openparen);
			cerr << "(";
			Expression();
			if (scanner.next_token() == T_closeparen)
			{
				eat_token(T_closeparen);
				cerr << ")";
			}
			else
				syntax_error(NT_Factor);
			break;
		default:
			syntax_error(NT_Factor);
			break;
	}

	//now that we are done with List, we can pop it from the data
	//stucture that is tracking it for drawing the parse tree
	parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:60,代码来源:calc.cpp

示例9: Jump

void parser_t::Jump()
{
	//push this non-terminal onto the parse tree.
	//the parsetree class is just for drawing the finished
	//parse tree, and should in should have no effect the actual
	//parsing of the data
	parsetree.push(NT_Jump);

	if(scanner.next_token() == T_goto)
	{
		eat_token(T_goto);
		if(scanner.next_token() == T_num)
		{
			eat_token(T_num);
			int labelNum = scanner.numberList[numberListSpot];
			numberListSpot++;
			JumpP(labelNum);
		}
		else
			syntax_error(NT_Jump);

	}
	else
		syntax_error(NT_Jump);

	//now that we are done with List, we can pop it from the data
	//stucture that is tracking it for drawing the parse tree
	parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:29,代码来源:calc.cpp

示例10: Label

string parser_t::Label(string s)
{
    token_type watch = scanner.next_token();
    parsetree.push(NT_Label);
    if(watch == T_label){
        s.append("L");
        eat_token(T_label);
        eat_token(T_num);
        char buf[100];
        snprintf(buf, 100, "%d", scanner.nextNumber);
        s.append(buf);
        s.append(":");
        eat_token(T_colon);
    }else{
        syntax_error(NT_Label);
    }
    watch = scanner.next_token();
    switch(watch){
        case T_eof:
        case T_label:
        case T_goto:
        case T_m:
        case T_print:
            break;
        default:
            syntax_error(NT_Label);
            break;
    }
    parsetree.pop();
    return s;
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:31,代码来源:calc.cpp

示例11: Jump

void parser_t::Jump(){
  parsetree.push(NT_Jump);
  if(scanner.next_token()==T_goto)
    eat_token(T_goto);
else
  syntax_error(NT_Jump);
  if(scanner.next_token()==T_num){
    eat_token(T_num);
    Secondjump();
  }
  else
    syntax_error(NT_Jump); 
  parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:14,代码来源:calc.cpp

示例12: Statements

void parser_t::Statements()
{
	//push this non-terminal onto the parse tree.
	//the parsetree class is just for drawing the finished
	//parse tree, and should in should have no effect the actual
	//parsing of the data
	parsetree.push(NT_Statements);

	bool thereIsMore = true;
		switch( scanner.next_token() )
		{
			case T_label:
			case T_goto:
			case T_m:
			case T_print:
				Statement();
				Statements();
				break;
			case T_eof:
				thereIsMore = false;
				break;
			default:
				syntax_error(NT_Statements);
				break;
		}

	//now that we are done with List, we can pop it from the data
	//stucture that is tracking it for drawing the parse tree
	parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:30,代码来源:calc.cpp

示例13: Statement

void parser_t::Statement()
{
	parsetree.push(NT_Statement);

	switch( scanner.next_token() )
	{
		case T_label:
			Label();
			break;
		case T_goto:
			Jump();
			break;
		case T_m:
			Assignment();
			break;
		case T_print:
			Print();
			break;
		default:
			syntax_error(NT_Statement);
	}
	
	fprintf( stderr, "\n");

	parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:26,代码来源:calc.cpp

示例14: Start

//Here is an example
void parser_t::Start()
{
  //push this non-terminal onto the parse tree.
  //the parsetree class is just for drawing the finished
  //parse tree, and should in should have no effect the actual
  //parsing of the data
  parsetree.push(NT_Start);

  switch( scanner.next_token() ) 
    {
    case T_plus:
      eat_token(T_plus);
      Start();
      break;
    case T_eof:
      parsetree.drawepsilon();
      break;
    default:
      syntax_error(NT_Start);
      break;
    }

  //now that we are done with List, we can pop it from the data
  //stucture that is tracking it for drawing the parse tree
  parsetree.pop();
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:27,代码来源:calc.cpp

示例15: Start

//Here is an example
void parser_t::Start()
{
	//push this non-terminal onto the parse tree.
	//the parsetree class is just for drawing the finished
	//parse tree, and should in should have no effect the actual
	//parsing of the data
	parsetree.push(NT_Start);

	fprintf(stderr, "int main()\n");
	fprintf(stderr, "{\n");
	fprintf(stderr, "\tint m[101];\n");
	fprintf(stderr, "\n");


	switch( scanner.next_token() )
	{
		case T_label:
		case T_goto:
		case T_m:
		case T_print:
			Statements();
			break;
		case T_eof:
			parsetree.drawepsilon();
			break;
		default:
			syntax_error(NT_Start);
			break;
	}

	//now that we are done with List, we can pop it from the data
	//stucture that is tracking it for drawing the parse tree
	parsetree.pop();
	fprintf(stderr, "}\n");
}
开发者ID:fenghuo,项目名称:AutoGrading,代码行数:36,代码来源:calc.cpp


注:本文中的scanner_t::next_token方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。