]> thyrsus.com Git - cupl.git/commitdiff
More comments, split out execute().
authorEric S. Raymond <esr@thyrsus.com>
Thu, 3 Nov 1994 14:15:28 +0000 (14:15 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 3 Nov 1994 14:15:28 +0000 (14:15 +0000)
Makefile
READ.ME
cupl.h
interpret.c
tokdump.c

index c13bd38af91ccc1f9e4e885f99d015b36b2bf1cb..d8b9254b2c02bc0e7f2287d72dff3eaf792e5cb7 100644 (file)
--- 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 <tokens.h >toktab.h '/^#/ {print $$3 ", \"" $$3 "\","}'
diff --git a/READ.ME b/READ.ME
index 584a0f15beb4e028640e648e60bec6ef1f76bbd8..7d2f09b8a6c5a7e4745da22c2760f3e21ce90ed1 100644 (file)
--- 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 f80b08dd193fb3274065a61e2e9d5f2396feeff0..ae39c014c68e5b8545adcdbac162261e7e57108e 100644 (file)
--- 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
index 56bc18bfb221dbd5c719a0a555a209b121c03bcc..362f55b864354a04ec24c5cca334f974206afdce 100644 (file)
@@ -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 <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
@@ -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 */
index 07324ab13e5c01a7f4e5415e9352f1ade1127b36..9497adc21d4330216344a88dda5e1506013b3c19 100644 (file)
--- 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 <string.h>
 #include "tokens.h"