From: Eric S. Raymond Date: Fri, 4 Nov 1994 08:44:35 +0000 (+0000) Subject: A good running start -- READ and WRITE seem to work. X-Git-Tag: 1-2~74 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=82d3518fa84160df176b958ed2c2a3a739d7de96;p=cupl.git A good running start -- READ and WRITE seem to work. --- diff --git a/cupl.h b/cupl.h index 25b6f3d..22a352d 100644 --- a/cupl.h +++ b/cupl.h @@ -98,7 +98,7 @@ extern lvar *idlist; extern char *tokdump(int value); extern void yyerror(const char *errmsg); extern void interpret(node *tree); -extern int verbose; +extern int verbose, linewidth, fieldwidth; /* execute.c */ extern void execute(node *tree); diff --git a/cupl.xml b/cupl.xml index 767d06f..b547759 100644 --- a/cupl.xml +++ b/cupl.xml @@ -86,4 +86,13 @@ There are many limits in original CUPL that we do not enforce. There is no limit on the length of variable names short of the lexer's very long token buffer length. There is no hard limit on the number of statements in a program. There is no hard limit on the size of arrays. - +.P +While the format of number output does not exactly conform to original CUPL +rules, it is sufficiently ugly to please any but the pickiest. We +implement all of 5.2 except the fixing of the decimal point at +position 7 in each field. Instead we simply use printf(3)'s %f and %e +at field-width precision. +.P +Also, by default, we wrap after three 20-char fields rather than 6, so +as to fit on an 80-column line. Command-line options to change the +line and field widths are available. diff --git a/execute.c b/execute.c index 29c0c44..4e8f29b 100644 --- a/execute.c +++ b/execute.c @@ -114,14 +114,29 @@ static void cupl_write(node *tp) } } +static void make_scalar(value *v, scalar i) +/* initialize a scalar value element */ +{ + v->width = v->depth = 1; + v->elements = (scalar *)malloc(sizeof(scalar)); + v->elements[0] = i; +} + static value cupl_eval(node *tree) /* recursively evaluate a CUPL parse tree */ { - value leftside, rightside; + value leftside, rightside, result; node *np; switch(tree->type) { + case NUMBER: + make_scalar(&result, tree->u.numval); + return(result); + + case IDENTIFIER: + return(tree->syminf->value); + case READ: for_cdr(np, tree) cupl_read(np->car); @@ -148,11 +163,7 @@ void execute(node *tree) /* initially, all variables are scalars with zero values */ for_symbols(lp) - { - lp->value.width = lp->value.depth = 1; - lp->value.elements = (scalar *)malloc(sizeof(scalar)); - lp->value.elements[0] = 0; - } + make_scalar(&lp->value, 0); /* locate the data pointer */ data = last = (node *)NULL; diff --git a/main.c b/main.c index d7a6349..74b04af 100644 --- a/main.c +++ b/main.c @@ -4,7 +4,7 @@ NAME main.c -- main sequence of the CUPL compiler SYNOPSIS - cupl [-v] [file...] + cupl [-vn[y]] [-w nn] [-f nn] [file...] DESCRIPTION The main sequence of the Cornell University Programming Language compiler. @@ -22,9 +22,11 @@ extern int yylineno; /* the current source line count */ extern int yydebug; /* enable YACC instrumentation? */ #define CANTOPN "can't open file %s\n" -#define USAGE "usage: cupl [-v nnn]\n" +#define USAGE "usage: cupl [-vn[y]] [-w nn] [file...]\n" -int verbose; /* verbosity level of the interpreter */ +int verbose; /* verbosity level of the interpreter */ +int linewidth = 80; /* line width used for field wrapping */ +int fieldwidth = 20; /* field width */ static int execfile(const char *file) /* translate a CUPL file in the current directory */ @@ -57,15 +59,23 @@ char *argv[]; extern char *getenv(); int c; - while ((c = getopt(argc, argv, "v:")) != EOF) + while ((c = getopt(argc, argv, "f:v:w:")) != EOF) switch (c) { + case 'f': + fieldwidth = atoi(optarg); + break; + case 'v': verbose = atoi(optarg); if (strchr(optarg, 'y')) yydebug = 1; break; + case 'w': + linewidth = atoi(optarg); + break; + default: (void) fprintf(stderr, USAGE); break;