Exemplo n.º 1
0
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();
}
Exemplo n.º 2
0
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();
}
Exemplo n.º 3
0
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();
}
Exemplo n.º 4
0
int parser_t::Fact()
{
	int v;
	parsetree.push(NT_Fact);
	switch (scanner.next_token())
	{
		case T_num:
			v = scanner.get_number();
			eat_token(T_num);
			break;
		case T_openparen:
			eat_token(T_openparen);
			v = Expr(v);
			eat_token(T_closeparen);
			break;
		default:
			syntax_error(NT_Fact);
			break;
	}
	parsetree.pop();

	return v;
}