expr.c 1.66 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
EvalNode *parser_result;
12
int   parser_col, parser_row;
13 14 15 16 17

EvalNode *
eval_parse_string (char *expr, int col, int row, char **error_msg)
{
	parser_expr = expr;
18
	parser_error = PARSE_OK;
19 20 21
	parser_col = col;
	parser_row = row;
	
22
	yyparse ();
23 24 25 26 27 28 29 30 31
	switch (parser_error){
	case PARSE_OK:
		*error_msg = NULL;
		break;

	case PARSE_ERR_NO_QUOTE:
		*error_msg = _("Missing quote");
		break;
	}
32 33 34
	return NULL;
}

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
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");
	}
}

56 57 58
void
eval_release_node (EvalNode *node)
{
59 60
	g_return_if_fail (node != NULL);
	
61
	switch (node->oper){
62 63 64
	case OP_VAR:
		break;
		
65
	case OP_CONSTANT:
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
		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;
		
87
	default:
88
		g_warning ("Unknown ExprNode type passed to eval_release_node\n");
89
	}
90
	g_free (node);
91
}
92

93 94 95
Value *
eval_node (EvalNode *node)
{
96
	switch (node->oper){
Arturo Espinosa's avatar
Arturo Espinosa committed
97 98 99 100 101
	case OP_ADD:
	case OP_SUB:
	case OP_MULT:
	case OP_DIV:
	case OP_EXP:
102 103
	}
}