summaryrefslogtreecommitdiffhomepage
path: root/mixlib/mix_eval.h
blob: 94995fbe55de4a2d68af6e2348629b92a35fa896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* -*-c-*- ---------------- mix_eval.h :
 * mix_eval_t is an evaluator of MIX W-expressions
 * ------------------------------------------------------------------
 *  Last change: Time-stamp: <00/12/02 23:11:44 jose>
 * ------------------------------------------------------------------
 * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
 *  
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 */


#ifndef MIX_EVAL_H
#define MIX_EVAL_H

#include "mix.h"
#include "mix_types.h"
#include "mix_symbol_table.h"

/* the evaluator type */
typedef struct mix_eval_t mix_eval_t;

/* possible evaluation outcomes*/
typedef enum {
  MIX_EVAL_OK, /* sucess*/
  MIX_EVAL_SYNTAX, /* syntax error */
  MIX_EVAL_INV_FSPEC, /* out of range fspec */
  MIX_EVAL_MIS_PAREN, /* mismatched parenthesis */
  MIX_EVAL_UNDEF_SYM, /* undefined symbol */
  MIX_EVAL_INTERN /* internal error */
} mix_eval_result_t;

/* create a new evaluator */
extern mix_eval_t *
mix_eval_new (void);

/* create a new evaluator with an external symbol table */
extern mix_eval_t *
mix_eval_new_with_table (mix_symbol_table_t *table);

/* delete */
extern void
mix_eval_delete (mix_eval_t *eval);

/* eval an expression providing a value for loc counter */
extern mix_eval_result_t
mix_eval_expression_with_loc (mix_eval_t *eval, const gchar *expr,
			      mix_short_t loc);
/* eval an expression with null loc*/
#define mix_eval_expression (eval,expr) \
  mix_eval_expression_with_loc (eval, expr, MIX_SHORT_ZERO)


/* get the result of the last evaluation */
extern mix_word_t
mix_eval_value (mix_eval_t *eval);

/* get the last eval result code */
extern mix_eval_result_t 
mix_eval_last_error (mix_eval_t *eval);

/* get the last error string */
extern const gchar*
mix_eval_last_error_string (mix_eval_t *eval);

/* get the position of last error */
extern guint
mix_eval_last_error_pos (mix_eval_t *eval);

/* add, or redefine, a symbol. see mix_symbol_table.h for
   possible outcomes. */
extern gint
mix_eval_set_symbol (mix_eval_t *eval, const gchar *symbol,
		     mix_word_t value);

extern void
mix_eval_remove_symbol (mix_eval_t *eval, const gchar *symbol);




#endif /* MIX_EVAL_H */