Example #1
0
void parser_t::Jump(){
	int temp;
	parsetree.push(NT_Jump);
	eat_token(T_goto);
	//cerr<<"goto ";
	scanner.next_token();
	temp = 	scanner.get_num();
	eat_token(T_num);

	scanner.next_token();
	if(scanner.next_token()== T_if){
		eat_token(T_if);
	//	cerr<<"if( ";
		//scanner.next_token();
		Expression();
		cerr<<" );\n";
		cerr<<"goto L";
		cerr<<temp;
		cerr<<"; \n";
		}
	else{
		cerr<<"goto L";
		cerr<<temp;
		cerr<<"; \n";
		}
	parsetree.pop();
}
Example #2
0
void parser_t::FactorP(){
	int temp = scanner.get_num();
	parsetree.push(NT_FactorP);
	switch(scanner.next_token()){
		case T_power:

			eat_token(T_power);
			Exp();

			FactorP();
			break;

		case T_eof:
			parsetree.drawepsilon();
			break;

		default:
			parsetree.drawepsilon();
			// syntax_error(NT_ExpressionP);
			break;

	}
	parsetree.pop();

}
Example #3
0
void parser_t::Factor(){
  token_type token;
  parsetree.push(NT_Factor);
  code_printf("intPow(");
  switch(token = scanner.next_token()){
  case T_openparen:
    eat_token(T_openparen);
    code_printf("(");
    Expression();
    code_printf(")");
    eat_token(T_closeparen);
    break;
  case T_m:
    code_printf("m[");
    eat_token(T_m);
    eat_token(T_opensquare);
    Expression();
    eat_token(T_closesquare);
    code_printf("]");
    break;
  case T_num:
    code_printf("%d",scanner.get_num());
    eat_token(T_num);
    break;
  default:
    syntax_error(NT_Factor);
    /*
    fprintf(stderr, "%d Invalid factor: %s\n", scanner.get_line(), token_to_string(token));
    assert(0);
    */
  }
  Power();
  parsetree.pop();
}
Example #4
0
void parser_t::Jump(){
  int number;
  parsetree.push(NT_Jump);
  eat_token(T_goto);
  eat_token(T_num);
  number = scanner.get_num();
  JumpIf();
  code_printf("goto my_label%d",number);
  parsetree.pop();
}
Example #5
0
void parser_t::Label(){
  parsetree.push(NT_Label);
  eat_token(T_label);
  eat_token(T_num);
  eat_token(T_colon);

  code_printf("my_label%d:\n", scanner.get_num());

  parsetree.pop();
}
Example #6
0
void parser_t::Label(){

	parsetree.push(NT_Jump);
	eat_token(T_label);
	cerr<<"L";
	eat_token(T_num);
	cerr<<scanner.get_num();
	cerr<<":\n";
	eat_token(T_colon);

	parsetree.pop();

}
Example #7
0
void parser_t::Exp(){

	parsetree.push(NT_Exp);

	switch (scanner.next_token()){

		case T_openparen:
			eat_token(T_openparen);
			cerr<<" ( ";
			Expression();
			//scanner.next_token();
			eat_token(T_closeparen);
			cerr<< " ) ";
			break;

		case T_m:
			eat_token(T_m);
			cerr<<"m";
			scanner.next_token();
			eat_token(T_opensquare);
			cerr<<"[ ";
			Expression();
			//scanner.next_token();
			eat_token(T_closesquare);
			cerr<<" ]";
			break;

		case T_num:
			eat_token(T_num);
			cerr<<scanner.get_num();
			break;

		case T_eof:
			parsetree.drawepsilon();
			break;

		default:
			syntax_error(NT_Exp);
			break;
	}


	parsetree.pop();
}