summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjaortega <jaortega>2000-12-02 22:32:48 +0000
committerjaortega <jaortega>2000-12-02 22:32:48 +0000
commitdda8ef14aca2b99d620323b3173e967456c92314 (patch)
tree54b3efaf81638539d3d9feb639aa22b4ffdc5a81
parent99cc30339d9cb98b240a6e0ef59c333fe3194018 (diff)
downloadmdk-dda8ef14aca2b99d620323b3173e967456c92314.tar.gz
mdk-dda8ef14aca2b99d620323b3173e967456c92314.tar.bz2
added mix_eval_t, a w-expression evaluator
-rw-r--r--ChangeLog12
-rw-r--r--mixlib/.cvsignore4
-rw-r--r--mixlib/Makefile.am15
-rw-r--r--mixlib/mix_eval.c154
-rw-r--r--mixlib/mix_eval.h95
-rw-r--r--mixlib/mix_eval_scanner.l246
-rw-r--r--mixlib/testsuite/.cvsignore1
-rw-r--r--mixlib/testsuite/Makefile.am4
-rw-r--r--mixlib/testsuite/mix_eval_t.c115
-rw-r--r--mixlib/xmix_eval.h55
-rw-r--r--po/ca.po2
11 files changed, 685 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index a89b27c..5c5e037 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
-Version 0.1.1
+Version 0.2
+ * mix_eval_t.c: (new file) unit test for mix_eval_t
+ * mix_eval.h, mix_eval.c, mix_eval_scanner.l: (new files)
+ mix_eval_t type (an w-expression evaluator).
+ * mix_device.c (mix_device_write) File buffers are now flushed after
+ a write operation.
+Version 0.1.1 (18/11/00)
* Bug fix: local symbols are now handled properly (see
samples/stress{1,2}.mixal)
* Bug fix: unary - on future refs is handled now (see
@@ -9,5 +15,5 @@ Version 0.1.1
* mix_vm.c (mix_vm_run): overflow of the location pointer checked:
the vm halts if this happens.
-Version 0.1
- * initial revision \ No newline at end of file
+Version 0.1 (01/11/00)
+ * initial revision
diff --git a/mixlib/.cvsignore b/mixlib/.cvsignore
index d2486ce..71b540f 100644
--- a/mixlib/.cvsignore
+++ b/mixlib/.cvsignore
@@ -1,5 +1,7 @@
+
.deps
Makefile
Makefile.in
+lex.yy.c
+mix_eval_scanner.c
mix_scanner.c
-
diff --git a/mixlib/Makefile.am b/mixlib/Makefile.am
index 26355cf..a81403c 100644
--- a/mixlib/Makefile.am
+++ b/mixlib/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
-# Copyright (C) 2000 jose antonio ortega ruiz <jaortega@retemail.es>
+# Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
@@ -24,14 +24,5 @@ libmix_a_SOURCES = mix.h mix.c \
mix_file.h mix_file.c \
mix_code_file.h mix_code_file.c \
mix_parser.h xmix_parser.h mix_parser.c mix_scanner.l \
- mix_device.h mix_device.c
-
-
-
-
-
-
-
-
-
-
+ mix_device.h mix_device.c \
+ mix_eval.h mix_eval.c xmix_eval.h mix_eval_scanner.l
diff --git a/mixlib/mix_eval.c b/mixlib/mix_eval.c
new file mode 100644
index 0000000..683b8ac
--- /dev/null
+++ b/mixlib/mix_eval.c
@@ -0,0 +1,154 @@
+/* -*-c-*- -------------- mix_eval.c :
+ * Implementation of the functions declared in mix_eval.h
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: "00/12/02 23:13:47 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.
+ *
+ */
+
+
+#include "xmix_eval.h"
+
+
+static const gchar *errors_[] = {
+ N_("Successful evaluation"),
+ N_("Syntax error in expression"),
+ N_("Out of range F-specification"),
+ N_("Mismatched parenthesis"),
+ N_("Undefined symbol"),
+ N_("Internal error")
+};
+
+
+/* create a new evaluator */
+mix_eval_t *
+mix_eval_new (void)
+{
+ mix_eval_t *result = g_new (mix_eval_t, 1);
+ result->table = mix_symbol_table_new ();
+ if (result->table == NULL) {
+ g_free (result);
+ return NULL;
+ }
+ result->towner = TRUE;
+ result->value = MIX_WORD_ZERO;
+ result->errpos = 0;
+ return result;
+}
+
+/* create a new evaluator with an external symbol table */
+mix_eval_t *
+mix_eval_new_with_table (mix_symbol_table_t *table)
+{
+ mix_eval_t *result = g_new (mix_eval_t, 1);
+ result->table = table;
+ result->towner = FALSE;
+ result->value = MIX_WORD_ZERO;
+ result->errpos = 0;
+ return result;
+}
+
+/* delete */
+void
+mix_eval_delete (mix_eval_t *eval)
+{
+ g_return_if_fail (eval);
+ if (eval->table && eval->towner) {
+ mix_symbol_table_delete (eval->table);
+ }
+ g_free (eval);
+}
+
+/* eval an expression */
+mix_eval_result_t
+mix_eval_expression_with_loc (mix_eval_t *eval, const gchar *expr,
+ mix_short_t loc)
+{
+ mix_eval_data_ data;
+
+ if (expr == NULL || eval == NULL)
+ return MIX_EVAL_INTERN;
+ data.expr = g_strdup_printf ("%s\n", expr);
+ data.table = eval->table;
+ data.errpos = eval->errpos;
+ data.value = eval->value;
+ data.loc = loc;
+ eval->result = mix_eval_expr (&data);
+ if (eval->result == MIX_EVAL_OK) {
+ eval->value = data.value;
+ eval->errpos = -1;
+ } else {
+ eval->errpos = data.errpos;
+ }
+ g_free (data.expr);
+
+ return eval->result;
+}
+
+/* get the result of the last evaluation */
+mix_word_t
+mix_eval_value (mix_eval_t *eval)
+{
+ g_return_val_if_fail (eval != NULL, MIX_WORD_ZERO);
+ return eval->value;
+}
+
+/* get the last eval result code */
+mix_eval_result_t
+mix_eval_last_error (mix_eval_t *eval)
+{
+ g_return_val_if_fail (eval != NULL, MIX_EVAL_INTERN);
+ return eval->result;
+}
+
+/* get the last error string */
+const gchar*
+mix_eval_last_error_string (mix_eval_t *eval)
+{
+ g_return_val_if_fail (eval != NULL, errors_[MIX_EVAL_INTERN]);
+ return errors_[eval->result];
+}
+
+/* get the position of last error */
+guint
+mix_eval_last_error_pos (mix_eval_t *eval)
+{
+ g_return_val_if_fail (eval != NULL, 0);
+ return eval->errpos;
+}
+
+/* add, or redefine, a symbol. see mix_symbol_table.h for
+ possible outcomes. */
+gint
+mix_eval_set_symbol (mix_eval_t *eval, const gchar *symbol,
+ mix_word_t value)
+{
+ g_return_val_if_fail (eval != NULL && eval->table != NULL,
+ MIX_SYM_FAIL);
+ return mix_symbol_table_insert (eval->table, symbol, value);
+}
+
+void
+mix_eval_remove_symbol (mix_eval_t *eval, const gchar *symbol)
+{
+ g_return_if_fail (eval != NULL && eval->table != NULL);
+ mix_symbol_table_remove (eval->table, symbol);
+}
+
+
+
diff --git a/mixlib/mix_eval.h b/mixlib/mix_eval.h
new file mode 100644
index 0000000..94995fb
--- /dev/null
+++ b/mixlib/mix_eval.h
@@ -0,0 +1,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 */
+
diff --git a/mixlib/mix_eval_scanner.l b/mixlib/mix_eval_scanner.l
new file mode 100644
index 0000000..443654d
--- /dev/null
+++ b/mixlib/mix_eval_scanner.l
@@ -0,0 +1,246 @@
+/* -*-c-*- ------------------ mix_eval_scanner.l :
+ * scanner used by mix_eval_t
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: <00/12/02 22:48:00 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.
+ *
+ */
+
+%{
+#include "mix.h"
+#include "xmix_eval.h"
+
+#define YY_DECL \
+ mix_eval_result_t mix_eval_expr (mix_eval_data_ *data)
+
+#define RETURN_STATE(err) \
+ do { \
+ done = TRUE; \
+ state = err; \
+ BEGIN (INITIAL); \
+ } while (FALSE)
+
+#define CLEAN_UP() \
+ do { \
+ yy_delete_buffer (buffer); \
+ g_free (expr_cp); \
+ } while (FALSE)
+
+static mix_word_t
+ eval_binop_ (const gchar *op, mix_word_t x, mix_word_t y);
+
+static void
+ unput_word_ (mix_word_t word);
+
+%}
+
+%option nomain
+%option caseless
+%option pointer
+%option stack
+%option noyywrap
+%option noyy_top_state
+%option noreject
+%option outfile="lex.yy.c"
+
+%s EVAL
+%s WEVAL
+
+ws [ \t]+
+digit [0-9]
+letter [A-Z]
+number [+-]?{digit}+
+mixchar [0-9A-Z .,'')(+*/=$<>@;:\-]
+locsymbol {digit}H
+flocsymbol {digit}F
+blocsymbol {digit}B
+symbol {digit}*{letter}+[A-Z0-9]*
+binop "+"|"-"|"*"|"/"|"//"|":"
+atexpr {digit}+|{symbol}|\*
+expr [+-]?{atexpr}({binop}{1}{atexpr})*
+fpart \({expr}\)
+wexpr {expr}({fpart})?(,{expr}({fpart})?)*
+
+
+%%
+
+%{
+ YY_BUFFER_STATE buffer;
+ mix_word_t expr_val = MIX_WORD_ZERO, wexpr_val = MIX_WORD_ZERO;
+ mix_word_t wexpr_val_tmp = MIX_WORD_ZERO;
+ mix_eval_result_t state = MIX_EVAL_OK;
+ gchar *expr_cp;
+ gboolean is_fp = FALSE, done = FALSE;
+ g_assert (data != NULL && data->expr != NULL);
+ /* make room enough to unput computed values */
+ expr_cp = g_strdup_printf (" %s", data->expr);
+ buffer = yy_scan_string (expr_cp);
+%}
+
+
+<*><<EOF>> {
+ CLEAN_UP ();
+ return MIX_EVAL_INTERN;
+}
+
+<INITIAL>{
+ {ws} /* eat whitespace */
+ . {
+ if (!done && state == MIX_EVAL_OK) {
+ yyless (0);
+ yy_push_state (WEVAL);
+ } else {
+ CLEAN_UP ();
+ if (state == MIX_EVAL_OK) return (MIX_EVAL_SYNTAX);
+ return state;
+ }
+ }
+ "\n" {
+ CLEAN_UP();
+ if (state == MIX_EVAL_OK)
+ data->value = wexpr_val;
+ return state;
+ }
+}
+
+<WEVAL>{
+ {number}"(" {
+ is_fp = TRUE;
+ wexpr_val_tmp = mix_word_new (atol (yytext));
+ }
+ {number}")" {
+ glong val = atol (yytext);
+ if ( !is_fp ) {
+ RETURN_STATE (MIX_EVAL_MIS_PAREN);
+ } else if ( val < 0 || val > MIX_BYTE_MAX
+ || !mix_fspec_is_valid (mix_byte_new (val)) ) {
+ RETURN_STATE (MIX_EVAL_INV_FSPEC);
+ } else {
+ is_fp = FALSE;
+ wexpr_val = mix_word_store_field (mix_byte_new (val),
+ wexpr_val_tmp,
+ wexpr_val);
+ }
+ }
+ {number} {
+ wexpr_val = mix_word_new (atol (yytext));
+ }
+ {expr} yyless (0); yy_push_state (EVAL);
+ ,/{expr} /* eat comma if followed by expression */
+ [\t\n ] { /* ok if not inside an f-part */
+ if ( is_fp ) {
+ RETURN_STATE (MIX_EVAL_MIS_PAREN);
+ }
+ unput (yytext[yyleng-1]);
+ done = TRUE;
+ yy_pop_state ();
+ }
+ . RETURN_STATE (MIX_EVAL_SYNTAX);
+}
+
+<EVAL>{
+ {binop}{digit}+ {
+ const gchar *s = ( yytext[1] == '/' ) ? yytext+2 : yytext+1;
+ mix_word_t value = mix_word_new (atol (s));
+ expr_val = eval_binop_ (yytext, expr_val, value);
+ }
+ {binop}{symbol} {
+ const gchar *s = ( yytext[1] == '/' ) ? yytext+2 : yytext+1;
+ if ( !mix_symbol_table_is_defined (data->table, s) ) {
+ RETURN_STATE (MIX_EVAL_UNDEF_SYM);
+ }
+ expr_val = eval_binop_ (yytext, expr_val,
+ mix_symbol_table_value (data->table, s));
+ }
+ "***" {
+ mix_word_t loc = mix_short_to_word_fast (data->loc);
+ (void)mix_word_mul (loc, loc, NULL, &loc);
+ unput_word_ (loc);
+ }
+ {binop}"*" {
+ expr_val = eval_binop_ (yytext, expr_val,
+ mix_short_to_word_fast (data->loc));
+ }
+ "*" unput_word_ (mix_short_to_word_fast (data->loc));
+ {number} expr_val = mix_word_new (atol (yytext));
+ {symbol} {
+ if ( !mix_symbol_table_is_defined (data->table, yytext) ) {
+ RETURN_STATE (MIX_EVAL_UNDEF_SYM);
+ }
+ expr_val = mix_symbol_table_value (data->table, yytext);
+ }
+ [,)(\n\t ] {
+ unput (yytext[0]);
+ unput_word_ (expr_val);
+ yy_pop_state ();
+ }
+
+ . RETURN_STATE (MIX_EVAL_SYNTAX);
+}
+
+
+%%
+
+static mix_word_t
+eval_binop_ (const gchar *op, mix_word_t x, mix_word_t y)
+{
+ mix_word_t result = MIX_WORD_ZERO;
+ switch (op[0])
+ {
+ case '+':
+ result = mix_word_add (x,y);
+ break;
+ case '-':
+ result = mix_word_sub (x,y);
+ break;
+ case '*':
+ mix_word_mul (x, y, NULL, &result);
+ break;
+ case ':':
+ {
+ mix_word_t a;
+ mix_word_mul (x, 8, NULL, &a);
+ result = mix_word_add (a, y);
+ break;
+ }
+ case '/':
+ if ( strlen (op) > 1 && op[1] == '/' ) {
+ mix_word_div (x,MIX_WORD_ZERO,y, &result, NULL);
+ } else {
+ mix_word_div (MIX_WORD_ZERO, x, y, &result, NULL);
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ return result;
+}
+
+
+static void
+unput_word_ (mix_word_t word)
+{
+ gchar *value;
+ gint k;
+ value = g_strdup_printf ("%s%ld",
+ mix_word_is_negative (word)? "-":"+",
+ mix_word_magnitude (word));
+ for (k = strlen (value) - 1; k >= 0; --k)
+ unput (value[k]);
+ g_free (value);
+}
diff --git a/mixlib/testsuite/.cvsignore b/mixlib/testsuite/.cvsignore
index fa47ca5..c936d6c 100644
--- a/mixlib/testsuite/.cvsignore
+++ b/mixlib/testsuite/.cvsignore
@@ -11,6 +11,7 @@ disk5.dev
disk6.dev
disk7.dev
mixdevtest
+mixevaltest
mixinstest
mixparsertest
mixtypest
diff --git a/mixlib/testsuite/Makefile.am b/mixlib/testsuite/Makefile.am
index 62d5db6..81ef11d 100644
--- a/mixlib/testsuite/Makefile.am
+++ b/mixlib/testsuite/Makefile.am
@@ -11,7 +11,7 @@
INCLUDES = -I..
LDADD = $(top_builddir)/mixlib/libmix.a
-check_PROGRAMS = mixtypest mixinstest mixvminstest mixparsertest mixdevtest
+check_PROGRAMS = mixtypest mixinstest mixvminstest mixparsertest mixdevtest mixevaltest
TESTS = $(check_PROGRAMS)
mixtypest_SOURCES = test.h mix_types_t.c
@@ -19,6 +19,8 @@ mixinstest_SOURCES = test.h mix_ins_t.c
mixvminstest_SOURCES = test.h mix_vm_ins_t.c
mixparsertest_SOURCES = test.h mix_parser_t.c
mixdevtest_SOURCES = test.h mix_device_t.c
+mixevaltest_SOURCES = test.h mix_eval_t.c
+
diff --git a/mixlib/testsuite/mix_eval_t.c b/mixlib/testsuite/mix_eval_t.c
new file mode 100644
index 0000000..e9b53c8
--- /dev/null
+++ b/mixlib/testsuite/mix_eval_t.c
@@ -0,0 +1,115 @@
+/* -*-c-*- -------------- mix_eval_t.c :
+ * Test of mix_eval_t
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: "00/12/02 23:18:39 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.
+ *
+ */
+
+
+#include <stdlib.h>
+#include <mix_eval.h>
+/* Define VERBOSE_TEST if you want to get prints of the test */
+/* #define VERBOSE_TEST */
+#include "test.h"
+
+typedef struct test_case_t
+{
+ const gchar *expr;
+ gint value;
+ mix_eval_result_t result;
+} test_case_t;
+
+#define ok_case(exp,val) {exp, val, MIX_EVAL_OK}
+#define err_case(exp,err) {exp, 0, err}
+
+typedef struct sym_val_t
+{
+ const gchar *sym;
+ mix_word_t value;
+} sym_val_t;
+
+#define new_symbol(sym,val) {sym, mix_word_new (val)}
+
+int
+main(int argc, char **argv)
+{
+ size_t k;
+ mix_eval_t *eval;
+ mix_short_t loc = mix_short_new (30);
+ sym_val_t symbols[] = {
+ new_symbol ("s0", 43),
+ new_symbol ("s1", -1234),
+ new_symbol ("s2", 0),
+ new_symbol ("s3", -20),
+ new_symbol (NULL, 0)
+ };
+
+ test_case_t cases[] = {
+ ok_case ("2343", 2343),
+ ok_case ("-890", -890),
+ ok_case ("15+1015", 1030),
+ ok_case ("1-481", -480),
+ ok_case ("2300/10", 230),
+ ok_case ("24*3", 72),
+ ok_case ("2:5", 21),
+ ok_case ("1//3", 357913941),
+ ok_case ("12+*", 42),
+ ok_case ("***", 900),
+ ok_case ("1:3*2-4", 18),
+ ok_case ("-1+5*20/6", 13),
+ ok_case ("-1000(0,2),1", 1),
+ ok_case ("s0-s2*3", 129),
+ ok_case ("s3**", -600),
+ ok_case ("s3(3:5)", 20),
+ ok_case ("-s1", 1234),
+ ok_case ("s1/10+s0", 166),
+ err_case ("foo", MIX_EVAL_UNDEF_SYM),
+ err_case ("11--2", MIX_EVAL_SYNTAX),
+ err_case ("foo*3", MIX_EVAL_UNDEF_SYM),
+ err_case ("32),1", MIX_EVAL_MIS_PAREN),
+ err_case ("2000(88)", MIX_EVAL_INV_FSPEC),
+ ok_case (NULL, 0)
+ };
+
+ INIT_TEST;
+ g_print ("Entering mix_eval test...");
+ eval = mix_eval_new ();
+
+ for (k = 0; symbols[k].sym; ++k)
+ mix_eval_set_symbol (eval, symbols[k].sym, symbols[k].value);
+
+ for (k = 0; cases[k].expr; ++k) {
+ mix_eval_result_t r = cases[k].result, s;
+ g_print ("Evaluating \"%s\" = %d ...",
+ cases[k].expr, cases[k].value);
+
+ s = mix_eval_expression_with_loc (eval, cases[k].expr, loc);
+ g_assert (s == r);
+ if ( s == MIX_EVAL_OK ) {
+ mix_word_print (mix_eval_value (eval), "... ");
+ g_print ("\n");
+ g_assert (mix_eval_value (eval) == mix_word_new(cases[k].value));
+ }
+ }
+ mix_eval_delete (eval);
+
+ return EXIT_SUCCESS;
+}
+
+
diff --git a/mixlib/xmix_eval.h b/mixlib/xmix_eval.h
new file mode 100644
index 0000000..5382d73
--- /dev/null
+++ b/mixlib/xmix_eval.h
@@ -0,0 +1,55 @@
+/* -*-c-*- ---------------- xmix_eval.h :
+ * Definition of opaque types in mix_eval.h
+ * ------------------------------------------------------------------
+ * Last change: Time-stamp: <00/12/02 03:53:09 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 XMIX_EVAL_H
+#define XMIX_EVAL_H
+
+#include "mix_eval.h"
+
+/* the evaluator type */
+struct mix_eval_t
+{
+ mix_symbol_table_t *table; /* symbol table */
+ gboolean towner; /* true if owns the table */
+ mix_eval_result_t result; /* last evaluation result */
+ gint errpos; /* location of last error */
+ mix_word_t value; /* last computed value */
+};
+
+/* flex scanner data/result struct */
+typedef struct mix_eval_data_
+{
+ gchar *expr;
+ const mix_symbol_table_t *table;
+ mix_word_t value;
+ mix_short_t loc;
+ gint errpos;
+} mix_eval_data_;
+
+/* flex scanner prototype */
+extern
+mix_eval_result_t mix_eval_expr (mix_eval_data_ *data);
+
+#endif /* XMIX_EVAL_H */
+
diff --git a/po/ca.po b/po/ca.po
index 7d058a1..3f9fb85 100644
--- a/po/ca.po
+++ b/po/ca.po
@@ -4,7 +4,7 @@
msgid ""
msgstr ""
"Project-Id-Version: mdk 0.1\n"
-"POT-Creation-Date: 2000-11-18 11:56+0100\n"
+"POT-Creation-Date: 2000-11-19 01:37+0100\n"
"PO-Revision-Date: 2000-02-28 01:37+01:00\n"
"Last-Translator: jose antonio ortega ruiz <jaortega@retemail.es>\n"
"Language-Team: jose antonio ortega ruiz <jaortega@retemail.es>\n"