Exemple #1
0
// Jump -> "goto" number Jump_
void parser_t::Jump()
{
	parsetree.push(NT_Jump);

	eat_token(T_goto);
	char* label_name = scanner.scan_num();
	eat_token(T_num);

	Jump_(label_name);

	parsetree.pop();
}
Exemple #2
0
void parser_t::Label()
{
	parsetree.push(NT_Label);

	eat_token(T_label);
	char* label_name = scanner.scan_num();
	eat_token(T_num);
	eat_token(T_colon);

	fprintf(stderr, "\tlabel%s:", label_name);

	parsetree.pop();
}
Exemple #3
0
std::string parser_t::Expression()
{
	std::string firstExpression("");
	std::string result("");
	std::ostringstream stream;
	parsetree.push(NT_Expression);
	switch (scanner.next_token()) {
		case T_openparen:
			eat_token(T_openparen);
			firstExpression = Expression();
			if (scanner.next_token() != T_closeparen) syntax_error(NT_Expression);
			eat_token(T_closeparen);
			stream << "(" << firstExpression << ")";
			result = stream.str();
			break;
		case T_m:
			eat_token(T_m);
			if (scanner.next_token() != T_opensquare) syntax_error(NT_Expression);
			eat_token(T_opensquare);
			firstExpression = Expression();
			if (scanner.next_token() != T_closesquare) syntax_error(NT_Expression);
			eat_token(T_closesquare);
			stream << "m[" << firstExpression << "]";
			result = stream.str();
			break;
		case T_num:
			result = scanner.scan_num();
			eat_token(T_num);
			break;
		default:
			syntax_error(NT_Expression);
			break;
	}

	result = Expression_(result);

	parsetree.pop();

	return result;
}