]> thyrsus.com Git - cupl.git/commitdiff
First running program.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 4 Nov 1994 07:33:06 +0000 (07:33 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 4 Nov 1994 07:33:06 +0000 (07:33 +0000)
cupl.y
execute.c

diff --git a/cupl.y b/cupl.y
index e553c3eb66c94d98a472128e429b18fd7d0be89a..a1d0459234dcbcee3a1e12ef2c0584f5caa36c92 100644 (file)
--- a/cupl.y
+++ b/cupl.y
@@ -193,9 +193,9 @@ writel      :    witem ',' writel           {$$ = cons(WRITE, $1, $3);}
        |    witem                      {$$ = cons(WRITE, $1, NULLNODE);}
        ;
 
-witem  :    IDENTIFIER                 {$$ = cons(WRITE,  $1, NULLNODE);}
+witem  :    IDENTIFIER                 {$$ = $1;}
        |    '/' IDENTIFIER             {$$ = cons(FWRITE, $2, NULLNODE);}
-       |    STRING                     {$$ = cons(FWRITE, $1, NULLNODE);}
+       |    STRING                     {$$ = $1;}
        |    /* EMPTY */                {$$ = (node *)NULL;}
        ;
 
index c9c2c2352e0739cabf13cbaf79a4faba0e26c79c..dd570caf09755842713df903b9c65bd3be224e41 100644 (file)
--- a/execute.c
+++ b/execute.c
@@ -34,18 +34,35 @@ static void cupl_read(node *tp)
        int     n;
 
        for (n = 0; n < v->width * v->depth; n++)
-           if (ATOMIC(data->car->type))
+           if (data == (node *)NULL)
            {
-               v->elements[n] = data->car->u.numval;
+               warn("data list too short\n");
+               v->elements[n] = 1;     /* 5-2 */
+           }
+           else
+           {
+               if (data->car->type == NUMBER)
+                   v->elements[n] = data->car->u.numval;
+               else
+               {
+                   if (strcmp(tp->u.string , data->car->car->u.string))
+                       warn("data mismatch; expecting %s, saw %s\n",
+                            tp->u.string , data->car->car->u.string);
+                   v->elements[n] = data->car->cdr->u.numval;
+               }
+
                data = data->cdr;
            }
-       /* code to handle conses expressing check variables goes here */
     }
 }
 
 static void cupl_write(node *tp)
 /* evaluate a WRITE item */
 {
+    if (tp->type == STRING)
+       (void) fputs(tp->u.string, stdout);
+    else
+       (void) printf("%f", tp->syminf->value.elements[0]);
 }
 
 static value cupl_eval(node *tree)
@@ -62,7 +79,7 @@ static value cupl_eval(node *tree)
        break;
 
     case WRITE:
-       for_cdr(np, tree->car)
+       for_cdr(np, tree)
            cupl_write(np->car);
        break;
 
@@ -75,7 +92,7 @@ static value cupl_eval(node *tree)
 void execute(node *tree)
 /* execute a CUPL program described by a parse tree */
 {
-    node       *np, *next;
+    node       *np, *next, *last;
     lvar       *lp;
 
     /* initially, all variables are scalars with zero values */
@@ -87,16 +104,24 @@ void execute(node *tree)
     }
 
     /* locate the data pointer */
-    data = (node *)NULL;
+    data = last = (node *)NULL;
     for_cdr(np, tree)
+    {
        if (np->car->type == DATA)
        {
            data = np->car;
            break;
        }
+       last = np;
+    }
+
+    /* break the link to the data */
     if (!data)
        warn("no data supplied\n");
+    else if (last)
+       last->cdr = (node *)NULL;
 
+    /* now execute the program */
     for (pc = tree; pc; pc = next)
     {
        next = pc->cdr;