예제 #1
0
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();
}
예제 #2
0
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();

}
예제 #3
0
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();
}