YFLAGS = -vlt
CFLAGS = $(CDEBUG) -D_POSIX_SOURCE -DYYDEBUG=1 -DPARSEDEBUG
-SOURCES = cupl.[ylh] tokdump.c main.c interpret.c execute.c
+SOURCES = cupl.[ylh] tokdump.c main.c interpret.c execute.c monitor.c
-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
+MODULES = main.o grammar.o lexer.o interpret.o tokdump.o execute.o monitor.o
+cupl: $(MODULES)
+ $(CC) $(MODULES) -o cupl
lexer.c: cupl.l
lex $(LFLAGS) cupl.l
interpret.o: interpret.c tokens.h cupl.h
interpret.o: interpret.c tokens.h cupl.h
execute.o: execute.c tokens.h cupl.h
+monitor.o: monitor.c tokens.h cupl.h
toktab.h: tokens.h
awk <tokens.h >toktab.h '/^#/ {print $$3 ", \"" $$3 "\","}'
tokdump.c -- token-dumper code (used for debugging)
interpret.c -- parse tree interpretation
execute.c -- actual execution
+monitor.c -- runtime support
main.c -- cupl's main sequence
CUPL samples
#define NOMEM "out of memory\n"
+/* miscellaneous */
extern char *tokdump(int value);
extern void yyerror(const char *errmsg);
extern void interpret(node *tree);
-extern void execute(node *tree);
extern int verbose;
+/* execute.c */
+extern void execute(node *tree);
+
+/* monitor.c */
+extern void die(char *msg, ...);
+extern void warn(char *msg, ...);
+
#define DEBUG_PARSEDUMP 1
#define DEBUG_CHECKDUMP 2
#define DEBUG_ALLOCATE 3
*****************************************************************************/
/*LINTLIBRARY*/
#include <stdio.h>
-#include <stdarg.h>
#include "cupl.h"
#include "tokens.h"
}
#endif /* PARSEDEBUG */
-static void warn(char *msg, ...)
-/* warn of an error and die */
-{
- va_list args;
-
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
-}
-
-static void die(char *msg, ...)
-/* complain of a fatal error and die */
-{
- va_list args;
-
- va_start(args, msg);
- vfprintf(stderr, msg, args);
- va_end(args);
-
- exit(1);
-}
-
static bool recursive_apply(node *tree, bool (*fun)(node *))
/* apply fun recursively to tree, short-circuiting on FALSE return */
{
/* now, hack label references to eliminate name references */
recursive_apply(tree, r_label_rewrite);
-
}
void interpret(node *tree)