From: Eric S. Raymond Date: Fri, 4 Nov 1994 07:33:06 +0000 (+0000) Subject: First running program. X-Git-Tag: 1-2~76 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=db6872f09f819d6962fb1e12210d24697593f329;p=cupl.git First running program. --- diff --git a/cupl.y b/cupl.y index e553c3e..a1d0459 100644 --- 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;} ; diff --git a/execute.c b/execute.c index c9c2c23..dd570ca 100644 --- 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;