#
# Makefile for the CUPL project
#
-CUPLDIR = . # Not presently used -- will be if we implement the compiler
+CDEBUG = -g
YFLAGS = -vlt
-CFLAGS = -g -D_POSIX_SOURCE -DYYDEBUG=1 -DPARSEDEBUG
+CFLAGS = $(CDEBUG) -D_POSIX_SOURCE -DYYDEBUG=1 -DPARSEDEBUG
-SOURCES = cupl.[ylh] tokdump.c main.c interpret.c
+SOURCES = cupl.[ylh] tokdump.c main.c interpret.c execute.c
-cupl: main.o grammar.o lexer.o interpret.o tokdump.o
- $(CC) main.o grammar.o lexer.o interpret.o tokdump.o -o cupl
+cupl: main.o grammar.o lexer.o interpret.o tokdump.o execute.o
+ $(CC) main.o grammar.o lexer.o interpret.o tokdump.o execute.o -o cupl
lexer.c: cupl.l
lex $(LFLAGS) cupl.l
tokdump.o: tokdump.c toktab.h
lexer.o: lexer.c tokens.h cupl.h
interpret.o: interpret.c tokens.h cupl.h
+interpret.o: interpret.c tokens.h cupl.h
+execute.o: execute.c tokens.h cupl.h
toktab.h: tokens.h
awk <tokens.h >toktab.h '/^#/ {print $$3 ", \"" $$3 "\","}'
cupl.h -- fundamental types and defines
tokdump.c -- token-dumper code (used for debugging)
interpret.c -- parse tree interpretation
+execute.c -- actual execution
main.c -- cupl's main sequence
CUPL samples
}
node;
+/* this structure represents a CUPL value */
+typedef struct
+{
+ int type; /* type (syntax class) */
+ int rank; /* 0, 1, or 2 */
+ int width, depth; /* dimensions */
+ scalar *elements; /* elements */
+}
+value;
+
/* access to the symbol list */
typedef struct lvar_t
{
- struct lvar_t *next;
- node *node;
+ struct lvar_t *next; /* link to next variable */
+ node *node; /* variable's symbol info */
+ value value; /* variable's value */
/* information used for consistency checks */
int labeldef;
lvar;
extern lvar *idlist;
+#define for_symbols(s) for (s = idlist; s; s = s->next)
+
#define NOMEM "out of memory\n"
extern char *tokdump(int value);
extern void yyerror(const char *errmsg);
extern void interpret(node *tree);
+extern void execute(node *tree);
extern int verbose;
#define DEBUG_PARSEDUMP 1
+/*****************************************************************************
+
+NAME
+ interpret.c -- parse-tree interpretation
+
+SYNOPSIS
+ void interpret(node *tree) -- prepare and execute a parse tree
+
+DESCRIPTION
+ This code does interpretation, static checking, and label resolution
+of a CUPL parse tree. Actual execution is handed off to execute().
+
+*****************************************************************************/
+/*LINTLIBRARY*/
#include <stdio.h>
#include <stdarg.h>
#include "cupl.h"
/* does the (non-VARSET) node refer to its right operand? */
#define RIGHTREF(n) ((n) != PERFORM)
-/* this structure represents a CUPL value */
-typedef struct
-{
- int type; /* type (syntax class) */
- int rank; /* 0, 1, or 2 */
- union
- {
- scalar scalar;
-
- struct
- {
- int width, depth;
- scalar *elements;
- }
- array; /* a vector or matrix */
- } u;
-}
-value;
-
#ifdef PARSEDEBUG
/*
* Note: This prettyprint routine tries to keep cons lists of elements of the
return(TRUE);
}
-bool recursive_apply(node *tree, bool (*fun)(node *))
+static bool recursive_apply(node *tree, bool (*fun)(node *))
/* apply fun recursively to tree, short-circuiting on FALSE return */
{
if (tree == (node *)NULL)
node *n;
lvar *lp;
-#define for_symbols(s) for (s = idlist; s; s = s->next)
-
/* simple sanity check */
for (n = tree; n; n = n->u.n.right)
if (n->type != STATEMENT)
if (check_errors(tree))
return;
- /* actual interpretation or compilation goes here */
+ execute(tree);
}
/* interpret.c ends here */
-/* tokdump.c -- a token dumper for debugging */
+/*****************************************************************************
+
+NAME
+ tokdump.c -- a token dumper for debugging
+
+
+SYNOPSIS
+ char *tokdump(int value) -- return token name corresponding to value
+
+DESCRIPTION
+ Used for dumping the parse tree and error messages.
+
+*****************************************************************************/
+/*LINTLIBRARY*/
#include <string.h>
#include "tokens.h"