From: Eric S. Raymond Date: Thu, 3 Nov 1994 14:15:28 +0000 (+0000) Subject: More comments, split out execute(). X-Git-Tag: 1-2~93 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=01585de7a8ac9eb6d84417fa7c232a65bdff9e97;p=cupl.git More comments, split out execute(). --- diff --git a/Makefile b/Makefile index c13bd38..d8b9254 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ # # 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 @@ -25,6 +25,8 @@ grammar.o: grammar.c cupl.h 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 toktab.h '/^#/ {print $$3 ", \"" $$3 "\","}' diff --git a/READ.ME b/READ.ME index 584a0f1..7d2f09b 100644 --- a/READ.ME +++ b/READ.ME @@ -37,6 +37,7 @@ cupl.l -- the LEX lexical-analyzer description 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 diff --git a/cupl.h b/cupl.h index f80b08d..ae39c01 100644 --- a/cupl.h +++ b/cupl.h @@ -54,11 +54,22 @@ typedef struct edon } 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; @@ -69,11 +80,14 @@ typedef struct lvar_t 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 diff --git a/interpret.c b/interpret.c index 56bc18b..362f55b 100644 --- a/interpret.c +++ b/interpret.c @@ -1,3 +1,17 @@ +/***************************************************************************** + +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 #include #include "cupl.h" @@ -24,25 +38,6 @@ /* 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 @@ -160,7 +155,7 @@ static bool r_mark_labels(node *tp) 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) @@ -181,8 +176,6 @@ static bool check_errors(node *tree) 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) @@ -249,7 +242,7 @@ void interpret(node *tree) if (check_errors(tree)) return; - /* actual interpretation or compilation goes here */ + execute(tree); } /* interpret.c ends here */ diff --git a/tokdump.c b/tokdump.c index 07324ab..9497adc 100644 --- a/tokdump.c +++ b/tokdump.c @@ -1,4 +1,17 @@ -/* 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 #include "tokens.h"