Make the expression code a little nicer and fix bugs found
[pspp-builds.git] / src / compute.c
index 9c20e0ee781f1999922790eaa421807d01115b72..4cc9a18797b4c8b7eea55c8d57fad1f3ff83e103 100644 (file)
@@ -18,7 +18,7 @@
    02111-1307, USA. */
 
 #include <config.h>
-#include <assert.h>
+#include "error.h"
 #include <stdlib.h>
 #include "alloc.h"
 #include "command.h"
@@ -75,8 +75,6 @@ cmd_compute (void)
   struct lvalue *lvalue = NULL;
   struct compute_trns *compute = NULL;
 
-  lex_match_id ("COMPUTE");
-
   lvalue = lvalue_parse ();
   if (lvalue == NULL)
     goto fail;
@@ -232,11 +230,10 @@ cmd_if (void)
   struct compute_trns *compute = NULL;
   struct lvalue *lvalue = NULL;
 
-  lex_match_id ("IF");
   compute = compute_trns_create ();
 
   /* Test expression. */
-  compute->test = expr_parse (PXP_BOOLEAN);
+  compute->test = expr_parse (EXPR_BOOLEAN);
   if (compute->test == NULL)
     goto fail;
 
@@ -279,7 +276,7 @@ parse_rvalue_expression (struct compute_trns *compute,
 
   assert (type == NUMERIC || type == ALPHA);
 
-  compute->rvalue = expr_parse (type == ALPHA ? PXP_STRING : PXP_NUMERIC);
+  compute->rvalue = expr_parse (type == ALPHA ? EXPR_STRING : EXPR_NUMERIC);
   if (compute->rvalue == NULL)
     return 0;
 
@@ -360,7 +357,7 @@ lvalue_parse (void)
       lex_get ();
       if (!lex_force_match ('('))
        goto lossage;
-      lvalue->element = expr_parse (PXP_NUMERIC);
+      lvalue->element = expr_parse (EXPR_NUMERIC);
       if (lvalue->element == NULL)
         goto lossage;
       if (!lex_force_match (')'))
@@ -442,25 +439,3 @@ lvalue_destroy (struct lvalue *lvalue)
   expr_free (lvalue->element);
   free (lvalue);
 }
-\f
-/* EVALUATE. */
-
-int
-cmd_evaluate (void)
-{
-  struct expression *expr;
-
-  lex_match_id ("EVALUATE");
-  expr = expr_parse (PXP_DUMP);
-  if (!expr)
-    return CMD_FAILURE;
-
-  expr_free (expr);
-  if (token != '.')
-    {
-      msg (SE, _("Extra characters after expression."));
-      return CMD_FAILURE;
-    }
-  
-  return CMD_SUCCESS;
-}