Esempio n. 1
0
File: syntax.c Progetto: dzruyk/spam
static syn_node_t *
equity()
{
	syn_node_t *right, *result;
	opcode_t op;

	result = rel_op();

	if (result == NULL)
		return NULL;
	
	while (TRUE) {
		switch (current_tok) {
		case TOK_EQ:
			op = OP_EQ;
			break;
		case TOK_NEQ:
			op = OP_NEQ;
			break;
		default:
			return result;
		}
		tok_next();

		right = rel_op();
		if (right == NULL) {
			nerrors++;
			print_warn("uncomplited eq expression\n");
			right = syn_node_stub_new();
		}
		result = syn_node_op_new(result, right, op);
	}
	return result;

}
/**
 * Function representing the <log_prim_prime> productions
 */
attr RecursiveDescentParser::log_prim_prime() {
	OpCode opCode;
	attr retVal, lhs, rhs;
	
	if(errorCondition) return retVal;
	if(token == TK_IDENTIFIER ||
			token == TK_NUM ||
			token == TK_CHAR_CONST ||
			token == TK_LEFT_PARENTHESES)
	{
#if DEBUG_PARSER
		std::cout << "<log_prim_prime> --> <exp><relop><exp>)\n";
#endif
		Token sToken = token;
		lhs = exp();
		opCode = rel_op();
		rhs = exp();
		
		if(lhs.attrib == VA_ARRAY || rhs.attrib == VA_ARRAY) {
			errorHandler("Comparison error, array must be indexed", sToken);
		}
		
		if(lhs.type != rhs.type) {
			errorHandler("Comparison error, types must match.", sToken);
		}
		
		retVal.addr = symTab.getNextAddress();
		iCode.threeAddressCode(retVal, opCode, lhs, rhs);
		
		match(TK_RIGHT_PARENTHESES);
	}
	else if(token == TK_EXCLAMATION) 
	{
#if DEBUG_PARSER
		std::cout << "<log_prim_prime> --> !<log_exp>)\n";
#endif
		Token sToken = token;
		token = scanner->getToken();
		
		lhs = log_exp();
		
		if(lhs.attrib == VA_ARRAY) {
			errorHandler("Comparison error, unary not cannot be applied to an array", sToken);
		}
		
		retVal.addr = symTab.getNextAddress();
		iCode.threeAddressCode(retVal, TAC_NOT, lhs);
		
		match(TK_RIGHT_PARENTHESES);
	}
	else
	{
		errorHandler();
	}
	
	return retVal;
}