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);
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.
}
}
+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);
/* 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;
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.
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 */
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;