expr.c 1.42 KB
Newer Older
1
#include <config.h>
2
#include <glib.h>
3 4 5
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include "numbers.h"
6 7 8 9
#include "symbol.h"
#include "expr.h"

char *parser_expr;
10
ParseErr parser_error;
11 12 13 14 15 16
EvalNode *parser_result;

EvalNode *
eval_parse_string (char *expr, int col, int row, char **error_msg)
{
	parser_expr = expr;
17
	parser_error = PARSE_OK;
18 19

	yyparse ();
20 21 22 23 24 25 26 27 28
	switch (parser_error){
	case PARSE_OK:
		*error_msg = NULL;
		break;

	case PARSE_ERR_NO_QUOTE:
		*error_msg = _("Missing quote");
		break;
	}
29 30 31
	return NULL;
}

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
static void
eval_release_value (Value *value)
{
	switch (value->type){
	case VALUE_STRING:
		symbol_unref (value->v.str);
		break;

	case VALUE_INTEGER:
		mpz_clear (value->v.v_int);
		break;
		
	case VALUE_FLOAT:
		mpf_clear (value->v.v_float);
		break;

	default:
		g_warning ("Unknown value type passed to eval_release_value\n");
	}
}

53 54 55
void
eval_release_node (EvalNode *node)
{
56 57
	g_return_if_fail (node != NULL);
	
58 59
	switch (node->oper){
	case OP_CONSTANT:
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
		eval_release_value (node->u.constant);
		break;
		
	case OP_FUNCALL:
		symbol_unref (node->u.function.symbol);
		break;

	case OP_ADD:
	case OP_SUB:
	case OP_MULT:
	case OP_DIV:
	case OP_EXP:
	case OP_CONCAT:
		eval_release_node (node->u.binary.value_a);
		eval_release_node (node->u.binary.value_b);
		break;

	case OP_NEG:
		eval_release_node (node->u.value);
		break;
		
81
	default:
82
		g_warning ("Unknown ExprNode type passed to eval_release_node\n");
83 84
	}
}
85