Пример #1
0
void check_expr_integrity(const TToken *tok, int *last_type)
{
	switch (*last_type) {
		case TOKEN_EOF:
				if (!token_is_operand(tok) && !token_is(tok, TOKEN_LROUND_BRACKET)) {
					my_exit_error(E_SYNTAX, 14);
				}
				break;
		case TOKEN_INT_VALUE:
		case TOKEN_DOUBLE_VALUE:
		case TOKEN_STRING_VALUE:
		case TOKEN_IDENTIFIER:
				if (!token_is_operator(tok) && !token_is(tok, TOKEN_RROUND_BRACKET)) {
					my_exit_error(E_SYNTAX, 15);
				}
				break;
		case TOKEN_LROUND_BRACKET:
				if (!token_is_operand(tok) && !token_is(tok, TOKEN_LROUND_BRACKET)) {
					my_exit_error(E_SYNTAX, 16);
				}
				break;
		case TOKEN_RROUND_BRACKET:
				if (!token_is_operator(tok) && !token_is(tok, TOKEN_RROUND_BRACKET)) {
					my_exit_error(E_SYNTAX, 17);
				}
				break;
		case TOKEN_MUL:
		case TOKEN_DIV:
		case TOKEN_ADD:
		case TOKEN_SUB:
		case TOKEN_EQUAL:
		case TOKEN_NOT_EQUAL:
		case TOKEN_GREATER:
		case TOKEN_GREATER_EQUAL:
		case TOKEN_LESS:
		case TOKEN_LESS_EQUAL:
				if (!(token_is_operand(tok)) && !token_is(tok, TOKEN_LROUND_BRACKET)) {
					my_exit_error(E_SYNTAX, 18);
				}
	}
	*last_type = tok->type;
}
Пример #2
0
struct Token *function_execute(struct Token *statement, struct List *scope){

	int header = statement->list->tokens[0]->type;

	if( token_is_operator(header) ) return function_operator(statement,scope);
	if(header == T_PRINT)           return function_print(statement,scope);
	if(header == T_IF)              return function_if(statement,scope);
	if(header == T_EXPRESSION)      return function_expression(statement,scope);
	if(header == T_STRING)          return statement->list->tokens[1];
	if(header == T_EQUALS)          return function_assignment(statement,scope);
	if(header == T_LOOKUP)          return function_lookup(statement,scope);
	if(header == T_NOT)             return function_not(statement,scope);

	printf("(ERROR:function_execute) Statement was not a valid function.\n");
	return token_create(T_NUMBER,0);
}