]> thyrsus.com Git - cupl.git/commitdiff
A good running start -- READ and WRITE seem to work.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 4 Nov 1994 08:44:35 +0000 (08:44 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 4 Nov 1994 08:44:35 +0000 (08:44 +0000)
cupl.h
cupl.xml
execute.c
main.c

diff --git a/cupl.h b/cupl.h
index 25b6f3dcaf12ec6224a28ea5c28915cd3569b1cf..22a352d80b8c237aaca23e4424f449530d394e00 100644 (file)
--- 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);
index 767d06f9cec70d85b7f1e7c9f97d786cbcbed955..b5477596794ce817b07ae9d2db0b3de46b9cb16a 100644 (file)
--- 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.
index 29c0c4470901a3b8bddc6e9a83de585a02d1ad21..4e8f29b1f29017afe41a9d2387354ea6189cd037 100644 (file)
--- 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 d7a634975188eb51bf5e31c462342e52ac036f7c..74b04af433a80eedc6a3ef3c7d3dfcf8be929da8 100644 (file)
--- 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;