From 54b309d530ff0b454929cfacb2610a7dab1ad413 Mon Sep 17 00:00:00 2001 From: misterunix Date: Mon, 8 Dec 2014 15:01:01 -0600 Subject: [PATCH 1/3] Base. Compiles but has seg fault at line 84 in cpu.c I remember seeing this last time I did this. Cant remember what it was. Going to clean the code base up with -Wall. --- src/Makefile | 73 ++ src/compiler.c | 6 +- src/compiler.h | 2 +- src/crobots.h | 6 + src/grammar.c | 1414 +++++++++++++++++------- src/intrins.c | 2 +- src/lexanal.c | 2780 ++++++++++++++++++++++++++++++++++-------------- src/lexanal.h | 317 ++++++ src/lexanal.l | 55 +- src/main.c | 7 +- src/rook.r | 3 - src/tokens.h | 72 +- 12 files changed, 3418 insertions(+), 1319 deletions(-) create mode 100644 src/Makefile create mode 100644 src/lexanal.h diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..1d33a89 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,73 @@ +# makefile for crobots + +OBJS = main.o grammar.o lexanal.o compiler.o cpu.o intrins.o display.o screen.o motion.o + +SOURCES = crobots.h compiler.h tokens.h main.c grammar.y grammar.c lexanal.l lexanal.c compiler.c cpu.c intrins.c display.c screen.c screend.c motion.c + +DOS = main.c grammar.c lexanal.c compiler.c cpu.c intrins.c display.c screend.c motion.c + +DOSA = main.c grammar.c lexanal.c compiler.c cpu.c intrins.c display.c screena.c motion.c + +# Xenix cc flags: optimize(O), omit stack checking(K), separate text and data(i) + +CFLAGS = -O2 -DUNIX +LIBS = -lm -lcurses + +# note - grammar.c and lexanal.c: both yacc (grammar.y) and lex (lexanal.l) +# place '# line' and/or '# ifdef' that sometimes choke the PC-DOS compiler, +# Lattice C, ver 2.14. The egrep filters are designed to remove +# the troublesome spots. +# Lattice does not accept '# line nn' or '#' (null) statements, and gets +# confused when '#ifdef symbol .... #endif' are nested. + +crobots: $(OBJS) + cc -s $(CFLAGS) $(OBJS) -o crobots $(LIBS) + +main.o: crobots.h main.c + cc $(CFLAGS) -c main.c + +grammar.o: crobots.h compiler.h grammar.y + yacc -d grammar.y + egrep -v '# line|^#$$' y.tab.c >grammar.c + rm y.tab.c + mv y.tab.h tokens.h + cc $(CFLAGS) -c grammar.c + +lexanal.o: crobots.h compiler.h lexanal.l grammar.y + lex --nostdinit --header-file=lexanal.h lexanal.l + egrep -v '# ifdef|# endif' lex.yy.c >lexanal.c + rm lex.yy.c + cc $(CFLAGS) -c lexanal.c + +compiler.o: crobots.h compiler.h tokens.h compiler.c + cc $(CFLAGS) -c compiler.c + +cpu.o: crobots.h grammar.y cpu.c + cc $(CFLAGS) -c cpu.c + +intrins.o: crobots.h intrins.c + cc $(CFLAGS) -c intrins.c + +display.o: crobots.h display.c + cc $(CFLAGS) -c display.c + +screen.o: crobots.h screen.c + cc $(CFLAGS) -c screen.c + +motion.o: crobots.h motion.c + cc $(CFLAGS) -c motion.c + +dos: + cc -s -dos -K -i -O -DDOS $(DOS) -o crobotsx.exe -lm + /bin/rm *.o + +dosa: + cc -s -dos -K -i -O -DDOS $(DOSA) -o crobotsa.exe -lm + /bin/rm *.o +print: + pr -t $(SOURCES) | lpr + +lint: + lint -abc *.c | tee crobots.lint + @echo 'lint output kept in crobots.lint' + diff --git a/src/compiler.c b/src/compiler.c index cf7f5eb..e4a4417 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -12,6 +12,7 @@ /* compiler.c - compiler routines in support of grammar.c */ #include +#include "lexanal.h" #include "crobots.h" /* EXT causes externals to be declared without extern keyword in compiler.h */ @@ -35,7 +36,7 @@ char *s; } -char *malloc(); +/* char *malloc(); */ /* init_comp - initializes the compiler for one file */ @@ -92,6 +93,9 @@ init_comp() *(op_stack + i) = 0; } + yyin = f_in; + yyout = f_out; + } diff --git a/src/compiler.h b/src/compiler.h index 05e8ef4..e72e298 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -16,7 +16,7 @@ #define MAXSYM 64 /* maximum number of symbol table entries per pool */ #define NESTLEVEL 16 /* maximum nest level for ifs, whiles, and fcalls */ -extern char yytext[]; /* from lexical analyzer */ +extern char *yytext; /* from lexical analyzer */ extern FILE *f_in, /* the comiler input source file */ *f_out; /* the compiler diagnostic file, assumed opened */ diff --git a/src/crobots.h b/src/crobots.h index c65b213..c93736f 100644 --- a/src/crobots.h +++ b/src/crobots.h @@ -9,6 +9,12 @@ /* */ /*****************************************************************************/ +#include +#include +#include +#include + +#define YY_NO_INPUT /* common defines */ /* note-the INIT flag (or lack of it) causes extern for all but one module */ diff --git a/src/grammar.c b/src/grammar.c index 1f64643..53d3083 100644 --- a/src/grammar.c +++ b/src/grammar.c @@ -1,4 +1,25 @@ +#ifndef lint +static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93"; +#endif + +#include +#include + +#define YYBYACC 1 +#define YYMAJOR 1 +#define YYMINOR 9 +#define YYPATCH 20070509 + +#define YYEMPTY (-1) +#define yyclearin (yychar = YYEMPTY) +#define yyerrok (yyerrflag = 0) +#define YYRECOVERING (yyerrflag != 0) +extern int yyparse(void); + +static int yygrowstack(void); +#define YYPREFIX "yy" +#line 2 "grammar.y" /*****************************************************************************/ @@ -14,367 +35,771 @@ #include "crobots.h" #include "compiler.h" -# define IDENTIFIER 257 -# define CONSTANT 258 -# define INC_OP 259 -# define DEC_OP 260 -# define LEFT_OP 261 -# define RIGHT_OP 262 -# define LE_OP 263 -# define GE_OP 264 -# define EQ_OP 265 -# define NE_OP 266 -# define AND_OP 267 -# define OR_OP 268 -# define MUL_ASSIGN 269 -# define DIV_ASSIGN 270 -# define MOD_ASSIGN 271 -# define ADD_ASSIGN 272 -# define SUB_ASSIGN 273 -# define LEFT_ASSIGN 274 -# define RIGHT_ASSIGN 275 -# define AND_ASSIGN 276 -# define XOR_ASSIGN 277 -# define OR_ASSIGN 278 -# define EXTERN 279 -# define AUTO 280 -# define REGISTER 281 -# define INT 282 -# define LONG 283 -# define IF 284 -# define ELSE 285 -# define WHILE 286 -# define FOR 287 -# define RETURN 288 -# define BREAK 289 -# define U_NEGATIVE 290 -# define U_NOT 291 -# define U_ONES 292 -#define yyclearin yychar = -1 -#define yyerrok yyerrflag = 0 -extern int yychar; -extern short yyerrflag; -#ifndef YYMAXDEPTH -#define YYMAXDEPTH 150 +#line 39 "y.tab.c" +#define IDENTIFIER 257 +#define CONSTANT 258 +#define INC_OP 259 +#define DEC_OP 260 +#define LEFT_OP 261 +#define RIGHT_OP 262 +#define LE_OP 263 +#define GE_OP 264 +#define EQ_OP 265 +#define NE_OP 266 +#define AND_OP 267 +#define OR_OP 268 +#define MUL_ASSIGN 269 +#define DIV_ASSIGN 270 +#define MOD_ASSIGN 271 +#define ADD_ASSIGN 272 +#define SUB_ASSIGN 273 +#define LEFT_ASSIGN 274 +#define RIGHT_ASSIGN 275 +#define AND_ASSIGN 276 +#define XOR_ASSIGN 277 +#define OR_ASSIGN 278 +#define EXTERN 279 +#define AUTO 280 +#define REGISTER 281 +#define INT 282 +#define LONG 283 +#define IF 284 +#define ELSE 285 +#define WHILE 286 +#define FOR 287 +#define RETURN 288 +#define BREAK 289 +#define U_NEGATIVE 290 +#define U_NOT 291 +#define U_ONES 292 +#define YYERRCODE 256 +short yylhs[] = { -1, + 1, 1, 1, 4, 4, 4, 4, 4, 5, 6, + 6, 8, 8, 8, 8, 9, 9, 9, 10, 10, + 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, + 15, 15, 15, 15, 15, 16, 16, 16, 17, 17, + 18, 18, 19, 19, 20, 20, 21, 21, 22, 7, + 7, 23, 24, 24, 24, 24, 24, 24, 24, 24, + 24, 24, 24, 3, 25, 25, 26, 26, 26, 26, + 27, 27, 30, 30, 28, 28, 28, 29, 29, 31, + 33, 33, 33, 34, 36, 36, 37, 35, 35, 38, + 39, 39, 40, 40, 11, 11, 41, 42, 42, 42, + 42, 42, 32, 32, 32, 43, 43, 44, 44, 44, + 44, 44, 45, 45, 45, 45, 51, 51, 50, 50, + 46, 46, 47, 47, 52, 53, 54, 55, 48, 57, + 56, 49, 49, 49, 0, 0, 58, 58, 59, 59, + 60, 60, 2, +}; +short yylen[] = { 2, + 1, 1, 3, 1, 3, 2, 2, 2, 2, 1, + 3, 1, 2, 2, 2, 1, 1, 1, 1, 4, + 1, 3, 3, 3, 1, 3, 3, 1, 3, 3, + 1, 3, 3, 3, 3, 1, 3, 3, 1, 3, + 1, 3, 1, 3, 1, 3, 1, 3, 1, 1, + 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 3, 1, 2, 1, 2, + 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, + 1, 2, 3, 2, 1, 2, 1, 1, 3, 1, + 1, 3, 2, 1, 1, 2, 1, 3, 2, 3, + 3, 4, 1, 3, 4, 1, 3, 1, 1, 1, + 1, 1, 2, 3, 3, 4, 1, 2, 1, 2, + 1, 2, 1, 1, 2, 4, 4, 1, 2, 1, + 4, 2, 2, 3, 1, 2, 1, 1, 2, 3, + 1, 2, 1, +}; +short yydefred[] = { 0, + 143, 75, 76, 77, 78, 79, 0, 81, 138, 0, + 0, 0, 0, 0, 0, 135, 137, 136, 65, 0, + 71, 0, 68, 70, 0, 117, 0, 141, 0, 139, + 84, 82, 87, 0, 88, 0, 66, 0, 140, 2, + 0, 0, 0, 130, 0, 0, 16, 17, 18, 0, + 121, 113, 4, 1, 0, 0, 0, 64, 0, 0, + 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 50, 0, 119, 108, 109, 110, 111, 112, 0, + 0, 123, 124, 0, 0, 0, 0, 118, 142, 83, + 0, 72, 0, 103, 74, 0, 13, 14, 0, 133, + 0, 132, 0, 0, 85, 0, 122, 7, 8, 9, + 6, 0, 10, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 53, 52, 19, 15, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 51, 114, 120, 115, 0, + 0, 129, 0, 89, 106, 0, 0, 134, 3, 0, + 0, 86, 96, 0, 5, 0, 22, 23, 24, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 116, 128, 0, 0, 0, 104, + 127, 20, 99, 94, 0, 0, 0, 91, 0, 0, + 11, 126, 131, 105, 107, 93, 100, 0, 98, 101, + 0, 92, 102, +}; +short yydgoto[] = { 7, + 53, 54, 55, 56, 57, 112, 58, 126, 60, 61, + 194, 62, 63, 64, 65, 66, 67, 68, 69, 70, + 71, 72, 73, 125, 26, 27, 20, 11, 12, 21, + 13, 95, 14, 15, 34, 195, 35, 196, 197, 198, + 163, 164, 156, 74, 75, 76, 77, 78, 79, 80, + 29, 82, 83, 84, 187, 85, 86, 16, 17, 30, +}; +short yysindex[] = { 182, + 0, 0, 0, 0, 0, 0, 182, 0, 0, -57, + -87, -87, -119, -31, -40, 0, 0, 0, 0, 16, + 0, 508, 0, 0, -33, 0, -57, 0, -119, 0, + 0, 0, 0, 14, 0, -244, 0, 522, 0, 0, + 535, 535, -13, 0, 725, -6, 0, 0, 0, 40, + 0, 0, 0, 0, 8, 71, 188, 0, 528, 648, + 0, 79, 6, -222, -32, -98, 21, 25, -36, -183, + -168, 0, 648, 0, 0, 0, 0, 0, 0, -16, + -22, 0, 0, 32, 32, 68, 70, 0, 0, 0, + -244, 0, 522, 0, 0, 648, 0, 0, 648, 0, + 58, 0, 96, 98, 0, -4, 0, 0, 0, 0, + 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 648, 648, 648, + 648, 648, 648, 648, 648, 648, 648, 648, 648, 648, + 648, 648, 648, 648, 648, 0, 0, 0, 0, 17, + -144, 0, 648, 0, 0, -10, 113, 0, 0, 648, + 4, 0, 0, 117, 0, 648, 0, 0, 0, 79, + 79, 6, 6, -222, -222, -222, -222, -32, -32, -98, + 21, 25, -36, -183, 0, 0, 32, 124, 85, 0, + 0, 0, 0, 0, 12, 128, 129, 0, 134, 42, + 0, 0, 0, 0, 0, 0, 0, -111, 0, 0, + 136, 0, 0, +}; +short yyrindex[] = { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + -51, -45, 0, 53, 0, 0, 0, 0, 0, 0, + 0, 27, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 91, 0, 0, 160, 0, + 0, 335, 372, 432, 489, 626, 115, 700, 61, -38, + 54, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 139, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 55, 0, 0, 0, 0, 0, 343, + 355, 392, 412, 440, 449, 460, 469, 501, 624, 628, + 702, 719, 140, 20, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 83, 0, 141, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, +}; +short yygindex[] = { 0, + 0, 813, -30, 0, 0, 0, -19, 878, 0, 211, + 168, 56, 80, 212, 187, 48, 81, 102, 90, 107, + 0, 0, 0, 0, 41, 35, 0, 0, -17, 227, + -5, -83, 0, 0, 0, 243, 205, 104, 0, 94, + 147, 0, 0, 290, 3, 0, 0, 0, 0, 229, + 288, 0, 0, 0, 0, 0, 0, 308, 0, 295, +}; +#define YYTABLESIZE 1067 +short yytable[] = { 48, + 32, 19, 47, 25, 22, 47, 50, 67, 31, 155, + 48, 47, 1, 69, 101, 28, 48, 50, 94, 103, + 47, 87, 47, 50, 28, 51, 99, 137, 47, 138, + 87, 89, 105, 189, 10, 161, 51, 113, 133, 134, + 9, 10, 51, 161, 193, 23, 24, 9, 131, 48, + 132, 161, 102, 146, 90, 125, 50, 91, 141, 36, + 48, 47, 125, 48, 48, 103, 107, 125, 157, 88, + 73, 50, 48, 94, 37, 51, 47, 165, 48, 50, + 166, 125, 210, 144, 47, 73, 47, 143, 162, 25, + 51, 52, 49, 80, 49, 97, 80, 49, 97, 145, + 25, 45, 149, 49, 45, 205, 25, 153, 147, 49, + 110, 80, 49, 80, 190, 130, 158, 48, 142, 45, + 128, 88, 188, 95, 50, 129, 95, 12, 12, 47, + 38, 12, 12, 12, 12, 12, 159, 12, 160, 25, + 186, 185, 49, 105, 48, 125, 201, 125, 125, 12, + 12, 12, 12, 191, 25, 41, 200, 49, 41, 2, + 3, 4, 5, 6, 203, 49, 139, 140, 207, 94, + 5, 6, 208, 41, 209, 80, 213, 162, 49, 95, + 46, 90, 105, 46, 12, 45, 170, 171, 180, 206, + 105, 2, 3, 4, 5, 6, 19, 19, 46, 1, + 19, 19, 19, 19, 19, 67, 19, 93, 41, 204, + 49, 69, 172, 173, 12, 12, 1, 104, 19, 19, + 48, 19, 181, 1, 40, 41, 42, 50, 111, 47, + 135, 136, 47, 183, 1, 40, 41, 42, 41, 41, + 1, 40, 41, 42, 182, 2, 3, 4, 5, 6, + 43, 184, 44, 19, 45, 46, 2, 3, 4, 5, + 6, 43, 92, 44, 46, 45, 46, 43, 1, 44, + 127, 45, 46, 1, 40, 41, 42, 5, 6, 125, + 125, 125, 125, 19, 19, 5, 6, 48, 1, 40, + 41, 42, 106, 5, 6, 154, 1, 40, 41, 42, + 43, 212, 44, 211, 45, 46, 125, 199, 125, 150, + 125, 125, 81, 49, 18, 43, 39, 44, 0, 45, + 46, 5, 6, 5, 6, 178, 179, 45, 45, 108, + 109, 80, 80, 80, 80, 80, 0, 0, 167, 168, + 169, 1, 40, 41, 42, 0, 174, 175, 176, 177, + 0, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 148, + 192, 0, 25, 151, 152, 25, 0, 25, 25, 25, + 26, 41, 41, 26, 0, 26, 26, 26, 0, 0, + 0, 0, 27, 25, 25, 27, 25, 27, 27, 27, + 0, 26, 26, 0, 26, 0, 46, 46, 0, 28, + 0, 0, 28, 27, 27, 28, 27, 0, 0, 0, + 19, 19, 19, 19, 19, 19, 19, 19, 25, 29, + 28, 28, 29, 28, 0, 29, 26, 0, 1, 148, + 0, 0, 0, 0, 1, 40, 41, 42, 27, 30, + 29, 29, 30, 29, 0, 30, 0, 0, 25, 25, + 2, 3, 4, 5, 6, 28, 26, 26, 0, 31, + 30, 30, 31, 30, 0, 31, 202, 34, 27, 27, + 34, 0, 0, 34, 0, 29, 35, 0, 0, 35, + 31, 31, 35, 31, 0, 28, 28, 32, 34, 34, + 32, 34, 0, 32, 0, 30, 33, 35, 35, 33, + 35, 0, 33, 0, 0, 29, 29, 0, 32, 32, + 0, 32, 0, 0, 0, 31, 36, 33, 33, 36, + 33, 0, 36, 34, 0, 30, 30, 0, 37, 0, + 0, 37, 35, 0, 37, 0, 0, 36, 0, 0, + 0, 0, 0, 32, 48, 31, 31, 0, 0, 37, + 0, 50, 33, 34, 34, 0, 47, 48, 38, 0, + 0, 0, 35, 35, 96, 0, 0, 0, 0, 47, + 0, 0, 36, 32, 32, 0, 0, 0, 124, 0, + 0, 0, 33, 33, 37, 25, 25, 25, 25, 25, + 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, + 26, 0, 36, 36, 0, 27, 27, 27, 27, 27, + 27, 27, 27, 0, 37, 37, 0, 0, 0, 0, + 25, 0, 28, 28, 28, 28, 28, 28, 28, 28, + 0, 0, 0, 0, 93, 0, 0, 49, 0, 0, + 0, 0, 29, 29, 29, 29, 29, 29, 29, 29, + 49, 38, 0, 39, 38, 40, 39, 38, 40, 39, + 0, 40, 30, 30, 30, 30, 30, 30, 30, 30, + 48, 0, 38, 0, 39, 0, 40, 50, 0, 0, + 0, 0, 47, 0, 31, 31, 31, 31, 31, 31, + 0, 0, 34, 34, 34, 34, 34, 34, 0, 0, + 0, 35, 35, 35, 35, 35, 35, 38, 0, 39, + 0, 40, 32, 32, 32, 32, 32, 32, 0, 0, + 0, 33, 33, 33, 33, 33, 33, 0, 0, 0, + 43, 0, 42, 43, 0, 42, 0, 38, 38, 39, + 39, 40, 40, 36, 36, 36, 36, 48, 43, 44, + 42, 0, 44, 0, 50, 37, 37, 37, 37, 47, + 0, 0, 0, 49, 0, 0, 0, 44, 1, 40, + 41, 42, 0, 100, 0, 0, 2, 3, 4, 5, + 6, 1, 40, 41, 42, 42, 114, 115, 116, 117, + 118, 119, 120, 121, 122, 123, 0, 0, 0, 0, + 0, 0, 8, 0, 0, 0, 0, 0, 0, 8, + 0, 0, 8, 43, 43, 42, 42, 33, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, + 0, 0, 44, 44, 0, 0, 0, 0, 8, 0, + 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 38, 38, + 38, 38, 39, 39, 40, 40, 0, 0, 0, 0, + 0, 0, 59, 33, 1, 40, 41, 42, 0, 0, + 0, 0, 0, 0, 0, 59, 0, 0, 97, 98, + 0, 0, 59, 0, 0, 0, 0, 59, 0, 0, + 0, 0, 0, 0, 59, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 59, 0, 0, 0, 0, 0, 0, 59, 59, 0, + 0, 59, 59, 0, 0, 0, 43, 43, 42, 42, + 59, 0, 0, 59, 0, 0, 59, 0, 0, 0, + 0, 1, 40, 41, 42, 44, 44, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 59, 0, 0, + 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 59, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 59, 0, 59, +}; +short yycheck[] = { 33, + 41, 59, 41, 123, 10, 44, 40, 59, 40, 93, + 33, 45, 257, 59, 45, 13, 33, 40, 38, 50, + 59, 27, 45, 40, 22, 59, 40, 60, 45, 62, + 36, 29, 50, 44, 0, 40, 59, 57, 261, 262, + 0, 7, 59, 40, 41, 11, 12, 7, 43, 33, + 45, 40, 59, 73, 41, 33, 40, 44, 38, 44, + 41, 45, 40, 44, 33, 96, 59, 45, 99, 29, + 44, 40, 33, 93, 59, 59, 45, 41, 59, 40, + 44, 59, 41, 267, 45, 59, 125, 124, 106, 123, + 59, 125, 126, 41, 41, 41, 44, 44, 44, 268, + 123, 41, 125, 126, 44, 189, 123, 40, 125, 126, + 40, 59, 59, 61, 125, 37, 59, 33, 94, 59, + 42, 81, 153, 41, 40, 47, 44, 37, 38, 45, + 61, 41, 42, 43, 44, 45, 41, 47, 41, 123, + 285, 125, 126, 161, 125, 123, 166, 125, 126, 59, + 60, 61, 62, 41, 123, 41, 40, 126, 44, 279, + 280, 281, 282, 283, 41, 126, 265, 266, 41, 189, + 282, 283, 44, 59, 41, 123, 41, 195, 125, 41, + 41, 41, 200, 44, 94, 125, 131, 132, 141, 195, + 208, 279, 280, 281, 282, 283, 37, 38, 59, 257, + 41, 42, 43, 44, 45, 257, 47, 123, 94, 125, + 126, 257, 133, 134, 124, 125, 257, 50, 59, 60, + 33, 62, 142, 257, 258, 259, 260, 40, 41, 268, + 263, 264, 45, 144, 257, 258, 259, 260, 124, 125, + 257, 258, 259, 260, 143, 279, 280, 281, 282, 283, + 284, 145, 286, 94, 288, 289, 279, 280, 281, 282, + 283, 284, 36, 286, 125, 288, 289, 284, 257, 286, + 60, 288, 289, 257, 258, 259, 260, 282, 283, 257, + 258, 259, 260, 124, 125, 282, 283, 268, 257, 258, + 259, 260, 50, 282, 283, 91, 257, 258, 259, 260, + 284, 208, 286, 200, 288, 289, 284, 161, 286, 81, + 288, 289, 25, 126, 7, 284, 22, 286, -1, 288, + 289, 282, 283, 282, 283, 139, 140, 267, 268, 259, + 260, 279, 280, 281, 282, 283, -1, -1, 128, 129, + 130, 257, 258, 259, 260, -1, 135, 136, 137, 138, + -1, 261, 262, 263, 264, 265, 266, 267, 268, 269, + 270, 271, 272, 273, 274, 275, 276, 277, 278, 80, + 160, -1, 38, 84, 85, 41, -1, 43, 44, 45, + 38, 267, 268, 41, -1, 43, 44, 45, -1, -1, + -1, -1, 38, 59, 60, 41, 62, 43, 44, 45, + -1, 59, 60, -1, 62, -1, 267, 268, -1, 38, + -1, -1, 41, 59, 60, 44, 62, -1, -1, -1, + 261, 262, 263, 264, 265, 266, 267, 268, 94, 38, + 59, 60, 41, 62, -1, 44, 94, -1, 257, 150, + -1, -1, -1, -1, 257, 258, 259, 260, 94, 38, + 59, 60, 41, 62, -1, 44, -1, -1, 124, 125, + 279, 280, 281, 282, 283, 94, 124, 125, -1, 38, + 59, 60, 41, 62, -1, 44, 187, 38, 124, 125, + 41, -1, -1, 44, -1, 94, 38, -1, -1, 41, + 59, 60, 44, 62, -1, 124, 125, 38, 59, 60, + 41, 62, -1, 44, -1, 94, 38, 59, 60, 41, + 62, -1, 44, -1, -1, 124, 125, -1, 59, 60, + -1, 62, -1, -1, -1, 94, 38, 59, 60, 41, + 62, -1, 44, 94, -1, 124, 125, -1, 38, -1, + -1, 41, 94, -1, 44, -1, -1, 59, -1, -1, + -1, -1, -1, 94, 33, 124, 125, -1, -1, 59, + -1, 40, 94, 124, 125, -1, 45, 33, 61, -1, + -1, -1, 124, 125, 40, -1, -1, -1, -1, 45, + -1, -1, 94, 124, 125, -1, -1, -1, 61, -1, + -1, -1, 124, 125, 94, 261, 262, 263, 264, 265, + 266, 267, 268, 261, 262, 263, 264, 265, 266, 267, + 268, -1, 124, 125, -1, 261, 262, 263, 264, 265, + 266, 267, 268, -1, 124, 125, -1, -1, -1, -1, + 123, -1, 261, 262, 263, 264, 265, 266, 267, 268, + -1, -1, -1, -1, 123, -1, -1, 126, -1, -1, + -1, -1, 261, 262, 263, 264, 265, 266, 267, 268, + 126, 38, -1, 38, 41, 38, 41, 44, 41, 44, + -1, 44, 261, 262, 263, 264, 265, 266, 267, 268, + 33, -1, 59, -1, 59, -1, 59, 40, -1, -1, + -1, -1, 45, -1, 263, 264, 265, 266, 267, 268, + -1, -1, 263, 264, 265, 266, 267, 268, -1, -1, + -1, 263, 264, 265, 266, 267, 268, 94, -1, 94, + -1, 94, 263, 264, 265, 266, 267, 268, -1, -1, + -1, 263, 264, 265, 266, 267, 268, -1, -1, -1, + 41, -1, 41, 44, -1, 44, -1, 124, 125, 124, + 125, 124, 125, 265, 266, 267, 268, 33, 59, 41, + 59, -1, 44, -1, 40, 265, 266, 267, 268, 45, + -1, -1, -1, 126, -1, -1, -1, 59, 257, 258, + 259, 260, -1, 59, -1, -1, 279, 280, 281, 282, + 283, 257, 258, 259, 260, 94, 269, 270, 271, 272, + 273, 274, 275, 276, 277, 278, -1, -1, -1, -1, + -1, -1, 0, -1, -1, -1, -1, -1, -1, 7, + -1, -1, 10, 124, 125, 124, 125, 15, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, 27, + -1, -1, 124, 125, -1, -1, -1, -1, 36, -1, + 126, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 265, 266, + 267, 268, 267, 268, 267, 268, -1, -1, -1, -1, + -1, -1, 25, 91, 257, 258, 259, 260, -1, -1, + -1, -1, -1, -1, -1, 38, -1, -1, 41, 42, + -1, -1, 45, -1, -1, -1, -1, 50, -1, -1, + -1, -1, -1, -1, 57, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 73, -1, -1, -1, -1, -1, -1, 80, 81, -1, + -1, 84, 85, -1, -1, -1, 267, 268, 267, 268, + 93, -1, -1, 96, -1, -1, 99, -1, -1, -1, + -1, 257, 258, 259, 260, 267, 268, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 195, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, 150, -1, -1, + 153, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, 166, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, 187, -1, 189, +}; +#define YYFINAL 7 +#ifndef YYDEBUG +#define YYDEBUG 0 +#endif +#define YYMAXTOKEN 292 +#if YYDEBUG +char *yyname[] = { +"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +"'!'",0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'","','","'-'",0,"'/'",0,0,0,0,0, +0,0,0,0,0,0,"';'","'<'","'='","'>'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,"'^'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +"'{'","'|'","'}'","'~'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"IDENTIFIER","CONSTANT","INC_OP", +"DEC_OP","LEFT_OP","RIGHT_OP","LE_OP","GE_OP","EQ_OP","NE_OP","AND_OP","OR_OP", +"MUL_ASSIGN","DIV_ASSIGN","MOD_ASSIGN","ADD_ASSIGN","SUB_ASSIGN","LEFT_ASSIGN", +"RIGHT_ASSIGN","AND_ASSIGN","XOR_ASSIGN","OR_ASSIGN","EXTERN","AUTO","REGISTER", +"INT","LONG","IF","ELSE","WHILE","FOR","RETURN","BREAK","U_NEGATIVE","U_NOT", +"U_ONES", +}; +char *yyrule[] = { +"$accept : file", +"primary_expr : identifier", +"primary_expr : CONSTANT", +"primary_expr : '(' expr ')'", +"postfix_expr : primary_expr", +"postfix_expr : fcall_start argument_expr_list ')'", +"postfix_expr : fcall_start ')'", +"postfix_expr : postfix_expr INC_OP", +"postfix_expr : postfix_expr DEC_OP", +"fcall_start : postfix_expr '('", +"argument_expr_list : assignment_expr", +"argument_expr_list : argument_expr_list ',' assignment_expr", +"unary_expr : postfix_expr", +"unary_expr : INC_OP unary_expr", +"unary_expr : DEC_OP unary_expr", +"unary_expr : unary_operator cast_expr", +"unary_operator : '-'", +"unary_operator : '!'", +"unary_operator : '~'", +"cast_expr : unary_expr", +"cast_expr : '(' type_name ')' cast_expr", +"multiplicative_expr : cast_expr", +"multiplicative_expr : multiplicative_expr '*' cast_expr", +"multiplicative_expr : multiplicative_expr '/' cast_expr", +"multiplicative_expr : multiplicative_expr '%' cast_expr", +"additive_expr : multiplicative_expr", +"additive_expr : additive_expr '+' multiplicative_expr", +"additive_expr : additive_expr '-' multiplicative_expr", +"shift_expr : additive_expr", +"shift_expr : shift_expr LEFT_OP additive_expr", +"shift_expr : shift_expr RIGHT_OP additive_expr", +"relational_expr : shift_expr", +"relational_expr : relational_expr '<' shift_expr", +"relational_expr : relational_expr '>' shift_expr", +"relational_expr : relational_expr LE_OP shift_expr", +"relational_expr : relational_expr GE_OP shift_expr", +"equality_expr : relational_expr", +"equality_expr : equality_expr EQ_OP relational_expr", +"equality_expr : equality_expr NE_OP relational_expr", +"and_expr : equality_expr", +"and_expr : and_expr '&' equality_expr", +"exclusive_or_expr : and_expr", +"exclusive_or_expr : exclusive_or_expr '^' and_expr", +"inclusive_or_expr : exclusive_or_expr", +"inclusive_or_expr : inclusive_or_expr '|' exclusive_or_expr", +"logical_and_expr : inclusive_or_expr", +"logical_and_expr : logical_and_expr AND_OP inclusive_or_expr", +"logical_or_expr : logical_and_expr", +"logical_or_expr : logical_or_expr OR_OP logical_and_expr", +"conditional_expr : logical_or_expr", +"assignment_expr : conditional_expr", +"assignment_expr : assignment_lval assignment_expr", +"assignment_lval : unary_expr assignment_operator", +"assignment_operator : '='", +"assignment_operator : MUL_ASSIGN", +"assignment_operator : DIV_ASSIGN", +"assignment_operator : MOD_ASSIGN", +"assignment_operator : ADD_ASSIGN", +"assignment_operator : SUB_ASSIGN", +"assignment_operator : LEFT_ASSIGN", +"assignment_operator : RIGHT_ASSIGN", +"assignment_operator : AND_ASSIGN", +"assignment_operator : XOR_ASSIGN", +"assignment_operator : OR_ASSIGN", +"expr : assignment_expr", +"declaration : declaration_specifiers ';'", +"declaration : declaration_specifiers init_declarator_list ';'", +"declaration_specifiers : storage_class_specifier", +"declaration_specifiers : storage_class_specifier declaration_specifiers", +"declaration_specifiers : type_specifier", +"declaration_specifiers : type_specifier declaration_specifiers", +"init_declarator_list : init_declarator", +"init_declarator_list : init_declarator_list ',' init_declarator", +"init_declarator : declarator", +"init_declarator : declarator '=' initializer", +"storage_class_specifier : EXTERN", +"storage_class_specifier : AUTO", +"storage_class_specifier : REGISTER", +"type_specifier : INT", +"type_specifier : LONG", +"declarator : declarator2", +"declarator2 : identifier", +"declarator2 : func_start ')'", +"declarator2 : func_start parameter_declaration_list ')'", +"func_start : declarator2 '('", +"type_specifier_list : type_specifier", +"type_specifier_list : type_specifier_list type_specifier", +"parameter_identifier : identifier", +"parameter_declaration_list : parameter_identifier", +"parameter_declaration_list : parameter_declaration_list ',' parameter_identifier", +"parameter_type_list : parameter_list", +"parameter_list : parameter_declaration", +"parameter_list : parameter_list ',' parameter_declaration", +"parameter_declaration : type_specifier_list declarator", +"parameter_declaration : type_name", +"type_name : type_specifier_list", +"type_name : type_specifier_list abstract_declarator", +"abstract_declarator : abstract_declarator2", +"abstract_declarator2 : '(' abstract_declarator ')'", +"abstract_declarator2 : '(' ')'", +"abstract_declarator2 : '(' parameter_type_list ')'", +"abstract_declarator2 : abstract_declarator2 '(' ')'", +"abstract_declarator2 : abstract_declarator2 '(' parameter_type_list ')'", +"initializer : assignment_expr", +"initializer : '{' initializer_list '}'", +"initializer : '{' initializer_list ',' '}'", +"initializer_list : initializer", +"initializer_list : initializer_list ',' initializer", +"statement : compound_statement", +"statement : expression_statement", +"statement : selection_statement", +"statement : iteration_statement", +"statement : jump_statement", +"compound_statement : '{' '}'", +"compound_statement : '{' statement_list '}'", +"compound_statement : '{' declaration_list '}'", +"compound_statement : '{' declaration_list statement_list '}'", +"declaration_list : declaration", +"declaration_list : declaration_list declaration", +"statement_list : statement", +"statement_list : statement_list statement", +"expression_statement : ';'", +"expression_statement : expr ';'", +"selection_statement : selection1_statement", +"selection_statement : selection2_statement", +"selection1_statement : if_clause statement", +"selection2_statement : if_clause statement else_clause statement", +"if_clause : IF '(' expr ')'", +"else_clause : ELSE", +"iteration_statement : while_clause statement", +"while_token : WHILE", +"while_clause : while_token '(' expr ')'", +"jump_statement : BREAK ';'", +"jump_statement : RETURN ';'", +"jump_statement : RETURN expr ';'", +"file : external_definition", +"file : file external_definition", +"external_definition : function_definition", +"external_definition : declaration", +"function_definition : declarator function_body", +"function_definition : declaration_specifiers declarator function_body", +"function_body : compound_statement", +"function_body : declaration_list compound_statement", +"identifier : IDENTIFIER", +}; #endif #ifndef YYSTYPE -#define YYSTYPE int +typedef int YYSTYPE; +#endif +#if YYDEBUG +#include #endif -YYSTYPE yylval, yyval; -# define YYERRCODE 256 -short yyexca[] ={ --1, 1, - 0, -1, - -2, 0, - }; -# define YYNPROD 144 -# define YYLAST 536 -short yyact[]={ - - 72, 107, 158, 22, 15, 16, 105, 77, 17, 137, - 138, 72, 71, 118, 143, 144, 32, 72, 77, 139, - 121, 140, 25, 71, 77, 17, 47, 54, 170, 71, - 12, 13, 14, 15, 16, 197, 172, 47, 12, 13, - 14, 15, 16, 47, 5, 199, 80, 78, 151, 79, - 72, 27, 172, 83, 172, 196, 72, 77, 127, 82, - 74, 68, 71, 77, 203, 72, 88, 63, 71, 85, - 131, 88, 77, 48, 34, 204, 47, 71, 200, 28, - 87, 156, 47, 98, 96, 164, 103, 201, 165, 145, - 22, 146, 94, 73, 90, 86, 208, 91, 130, 72, - 212, 22, 207, 38, 73, 72, 77, 22, 206, 155, - 73, 71, 77, 72, 149, 191, 152, 71, 194, 147, - 77, 129, 190, 168, 148, 71, 72, 100, 22, 167, - 39, 104, 85, 77, 102, 29, 136, 2, 71, 18, - 22, 72, 92, 73, 19, 202, 22, 3, 77, 73, - 56, 132, 99, 71, 51, 157, 134, 55, 73, 12, - 13, 14, 15, 16, 21, 133, 154, 150, 42, 50, - 72, 95, 89, 161, 20, 49, 159, 123, 160, 166, - 162, 152, 71, 46, 174, 175, 173, 40, 163, 153, - 37, 210, 73, 192, 45, 153, 20, 132, 73, 182, - 183, 195, 188, 180, 181, 44, 73, 43, 187, 108, - 109, 110, 111, 112, 113, 114, 115, 116, 117, 73, - 17, 171, 141, 142, 17, 76, 65, 66, 198, 33, - 205, 152, 17, 11, 73, 17, 76, 65, 66, 119, - 120, 17, 76, 65, 66, 209, 12, 13, 14, 15, - 16, 59, 211, 60, 213, 53, 52, 12, 13, 14, - 15, 16, 59, 73, 60, 84, 53, 52, 59, 17, - 60, 9, 53, 52, 17, 76, 65, 66, 15, 16, - 17, 76, 65, 66, 12, 13, 14, 15, 16, 17, - 76, 65, 66, 7, 15, 16, 15, 16, 81, 8, - 26, 59, 106, 60, 126, 53, 52, 59, 58, 60, - 57, 53, 52, 61, 15, 16, 15, 16, 67, 128, - 70, 41, 64, 17, 76, 65, 66, 62, 69, 17, - 76, 65, 66, 125, 75, 10, 10, 17, 76, 65, - 66, 10, 1, 0, 62, 62, 35, 0, 0, 135, - 17, 76, 65, 66, 0, 0, 62, 0, 62, 10, - 62, 93, 0, 62, 0, 17, 76, 65, 66, 0, - 122, 124, 0, 97, 0, 62, 0, 101, 0, 23, - 4, 4, 62, 0, 0, 0, 0, 0, 0, 24, - 6, 6, 0, 62, 17, 76, 65, 66, 30, 31, - 62, 36, 0, 0, 0, 0, 169, 62, 0, 62, - 0, 0, 0, 184, 185, 186, 0, 93, 0, 0, - 36, 0, 10, 0, 0, 0, 35, 0, 62, 0, - 0, 0, 0, 0, 193, 0, 0, 0, 176, 177, - 178, 179, 0, 0, 135, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, - 0, 0, 62, 0, 0, 0, 135, 0, 0, 0, - 62, 0, 169, 0, 0, 0, 0, 0, 0, 189, - 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 10 }; -short yypact[]={ - --249,-249,-1000,-1000,-1000,-120, -37, 95,-241,-241, --1000, -25,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000, --1000,-120, -22,-1000, -37,-1000, 36, 5,-1000,-1000, --1000,-1000,-1000, 53,-1000,-1000,-1000,-1000,-1000, 17, - -33,-1000,-1000,-1000,-1000,-1000,-1000,-1000, 25,-1000, --1000, 23, 24, 93,-1000, 23, 94,-1000, 108, 91, --1000,-262, -60,-254, -20, 137, 137, 108, -66,-1000, - 80,-1000,-1000,-1000, -24,-1000,-1000, 32, 98,-256, - -41,-247, 46, 77,-1000, 10,-1000,-232, 72,-1000, --1000,-232,-1000,-1000,-1000, -16,-1000,-1000,-1000,-1000, - 22,-283, 108,-1000, 108, 108,-1000,-1000,-1000,-1000, --1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000, 108,-1000, --1000,-1000,-1000, 108,-1000,-1000,-1000, 108, 44,-1000, --1000, 108, 88, 82, -4,-1000, 108, 108, 108, 108, - 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, --1000,-1000,-1000, 72,-1000,-1000,-1000, 23,-1000, 81, - 74,-254, -66, -24,-1000, 108, 98,-1000, 108,-1000, --1000, 78, 14,-256, -41, -41,-247,-247,-247,-247, - 46, 46, 77, 77,-1000,-1000,-1000, 20,-1000,-1000, --1000,-1000,-1000,-1000, 34, 67,-1000, 61, 52,-1000, - 12,-1000,-1000, 66,-1000, 59,-1000,-1000,-278,-1000, --1000,-1000,-1000,-1000 }; -short yypgo[]={ - - 0, 342, 328, 334, 73, 322, 320, 319, 27, 304, - 318, 265, 87, 53, 59, 298, 46, 49, 47, 60, - 61, 67, 313, 310, 308, 302, 379, 389, 300, 299, - 271, 79, 44, 48, 293, 233, 229, 78, 74, 35, - 228, 45, 28, 221, 208, 321, 168, 207, 205, 194, - 183, 130, 164, 175, 169, 157, 155, 154, 150, 137, - 147, 144 }; -short yyr1[]={ - - 0, 2, 2, 2, 5, 5, 5, 5, 5, 6, - 7, 7, 9, 9, 9, 9, 10, 10, 10, 11, - 11, 13, 13, 13, 13, 14, 14, 14, 15, 15, - 15, 16, 16, 16, 16, 16, 17, 17, 17, 18, - 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, - 8, 8, 24, 25, 25, 25, 25, 25, 25, 25, - 25, 25, 25, 25, 4, 26, 26, 27, 27, 27, - 27, 28, 28, 31, 31, 29, 29, 29, 30, 30, - 32, 34, 34, 34, 35, 37, 37, 38, 36, 36, - 39, 40, 40, 41, 41, 12, 12, 42, 43, 43, - 43, 43, 43, 33, 33, 33, 44, 44, 45, 45, - 45, 45, 45, 46, 46, 46, 46, 52, 52, 51, - 51, 47, 47, 48, 48, 53, 54, 55, 56, 49, - 58, 57, 50, 50, 50, 1, 1, 59, 59, 60, - 60, 61, 61, 3 }; -short yyr2[]={ - - 0, 1, 1, 3, 1, 3, 2, 2, 2, 2, - 1, 3, 1, 2, 2, 2, 1, 1, 1, 1, - 4, 1, 3, 3, 3, 1, 3, 3, 1, 3, - 3, 1, 3, 3, 3, 3, 1, 3, 3, 1, - 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, - 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 2, 3, 1, 2, 1, - 2, 1, 3, 1, 3, 1, 1, 1, 1, 1, - 1, 1, 2, 3, 2, 1, 2, 1, 1, 3, - 1, 1, 3, 2, 1, 1, 2, 1, 3, 2, - 3, 3, 4, 1, 3, 4, 1, 3, 1, 1, - 1, 1, 1, 2, 3, 3, 4, 1, 2, 1, - 2, 1, 2, 1, 1, 2, 4, 4, 1, 2, - 1, 4, 2, 2, 3, 1, 2, 1, 1, 2, - 3, 1, 2, 1 }; -short yychk[]={ - --1000, -1, -59, -60, -26, -32, -27, -34, -29, -30, - -3, -35, 279, 280, 281, 282, 283, 257, -59, -61, - -46, -52, 123, -26, -27, 59, -28, -32, -31, 40, - -27, -27, 41, -36, -38, -3, -26, -46, 125, -51, - -52, -45, -46, -47, -48, -49, -50, 59, -4, -53, - -54, -57, 289, 288, -8, -55, -58, -23, -24, 284, - 286, -22, -9, -21, -5, 259, 260, -10, -20, -2, - -6, 45, 33, 126, -19, -3, 258, 40, -18, -17, - -16, -15, -14, -13, -11, -32, 59, 44, 61, -61, - 41, 44, 125, -45, 125, -51, 59, -45, 59, 59, - -4, -45, 40, -8, 40, 268, -25, 61, 269, 270, - 271, 272, 273, 274, 275, 276, 277, 278, 267, 259, - 260, 40, -9, 40, -9, -11, -9, 124, -7, 41, - -8, 94, -4, -12, -37, -30, 38, 265, 266, 60, - 62, 263, 264, 261, 262, 43, 45, 42, 47, 37, - -31, -33, -8, 123, -38, 125, 59, -56, 285, -4, - -4, -21, -20, -19, 41, 44, -18, 41, 41, -30, - -42, -43, 40, -17, -16, -16, -15, -15, -15, -15, - -14, -14, -13, -13, -11, -11, -11, -44, -33, -45, - 41, 41, -8, -11, 40, -42, 41, -39, -40, -41, - -37, -12, 125, 44, 41, -39, 41, 41, 44, -32, - 125, -33, 41, -41 }; -short yydef[]={ - - 0, -2, 135, 137, 138, 0, 0, 80, 67, 69, - 81, 0, 75, 76, 77, 78, 79, 143, 136, 139, - 141, 0, 0, 117, 0, 65, 0, 73, 71, 84, - 68, 70, 82, 0, 88, 87, 118, 142, 113, 0, - 0, 119, 108, 109, 110, 111, 112, 121, 0, 123, - 124, 0, 0, 0, 64, 0, 0, 50, 0, 0, - 130, 49, 19, 47, 12, 0, 0, 0, 45, 4, - 0, 16, 17, 18, 43, 1, 2, 0, 41, 39, - 36, 31, 28, 25, 21, 73, 66, 0, 0, 140, - 83, 0, 114, 120, 115, 0, 122, 129, 132, 133, - 0, 125, 0, 51, 0, 0, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 0, 7, - 8, 9, 13, 0, 14, 15, 19, 0, 0, 6, - 10, 0, 0, 0, 95, 85, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 72, 74, 103, 0, 89, 116, 134, 0, 128, 0, - 0, 48, 46, 44, 5, 0, 42, 3, 0, 86, - 96, 97, 0, 40, 37, 38, 32, 33, 34, 35, - 29, 30, 26, 27, 22, 23, 24, 0, 106, 126, - 131, 127, 11, 20, 0, 0, 99, 0, 90, 91, - 95, 94, 104, 0, 101, 0, 98, 100, 0, 93, - 105, 107, 102, 92 }; -# define YYFLAG -1000 -# define YYERROR goto yyerrlab -# define YYACCEPT return(0) -# define YYABORT return(1) - -/* parser for yacc output */ - -int yydebug = 0; /* 1 for debugging */ -YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */ -int yychar = -1; /* current input token number */ -int yynerrs = 0; /* number of errors */ -short yyerrflag = 0; /* error recovery flag */ - -yyparse() { - - short yys[YYMAXDEPTH]; - short yyj, yym; - register YYSTYPE *yypvt; - register short yystate, *yyps, yyn; - register YYSTYPE *yypv; - register short *yyxi; - - yystate = 0; - yychar = -1; - yynerrs = 0; - yyerrflag = 0; - yyps= &yys[-1]; - yypv= &yyv[-1]; - - yystack: /* put a state and value onto the stack */ - - if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar ); - if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); } - *yyps = yystate; - ++yypv; - *yypv = yyval; - - yynewstate: - - yyn = yypact[yystate]; - - if( yyn<= YYFLAG ) goto yydefault; /* simple state */ - - if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0; - if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault; - - if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */ - yychar = -1; - yyval = yylval; - yystate = yyn; - if( yyerrflag > 0 ) --yyerrflag; - goto yystack; - } - - yydefault: - /* default state action */ - - if( (yyn=yydef[yystate]) == -2 ) { - if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0; - /* look through exception table */ - - for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */ - - while( *(yyxi+=2) >= 0 ){ - if( *yyxi == yychar ) break; - } - if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */ - } - - if( yyn == 0 ){ /* error */ - /* error ... attempt to resume parsing */ - - switch( yyerrflag ){ - case 0: /* brand new error */ +/* define the initial stack-sizes */ +#ifdef YYSTACKSIZE +#undef YYMAXDEPTH +#define YYMAXDEPTH YYSTACKSIZE +#else +#ifdef YYMAXDEPTH +#define YYSTACKSIZE YYMAXDEPTH +#else +#define YYSTACKSIZE 10000 +#define YYMAXDEPTH 10000 +#endif +#endif - yyerror( "syntax error" ); - yyerrlab: - ++yynerrs; +#define YYINITSTACKSIZE 500 - case 1: - case 2: /* incompletely recovered error ... try again */ +int yydebug; +int yynerrs; +int yyerrflag; +int yychar; +short *yyssp; +YYSTYPE *yyvsp; +YYSTYPE yyval; +YYSTYPE yylval; - yyerrflag = 3; +/* variables for the parser stack */ +static short *yyss; +static short *yysslim; +static YYSTYPE *yyvs; +static int yystacksize; +/* allocate initial stack or double stack size, up to YYMAXDEPTH */ +static int yygrowstack(void) +{ + int newsize, i; + short *newss; + YYSTYPE *newvs; - /* find a state where "error" is a legal shift action */ + if ((newsize = yystacksize) == 0) + newsize = YYINITSTACKSIZE; + else if (newsize >= YYMAXDEPTH) + return -1; + else if ((newsize *= 2) > YYMAXDEPTH) + newsize = YYMAXDEPTH; - while ( yyps >= yys ) { - yyn = yypact[*yyps] + YYERRCODE; - if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){ - yystate = yyact[yyn]; /* simulate a shift of "error" */ - goto yystack; - } - yyn = yypact[*yyps]; + i = yyssp - yyss; + newss = (yyss != 0) + ? (short *)realloc(yyss, newsize * sizeof(*newss)) + : (short *)malloc(newsize * sizeof(*newss)); + if (newss == 0) + return -1; - /* the current yyps has no shift onn "error", pop stack */ + yyss = newss; + yyssp = newss + i; + newvs = (yyvs != 0) + ? (YYSTYPE *)realloc(yyvs, newsize * sizeof(*newvs)) + : (YYSTYPE *)malloc(newsize * sizeof(*newvs)); + if (newvs == 0) + return -1; - if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] ); - --yyps; - --yypv; - } + yyvs = newvs; + yyvsp = newvs + i; + yystacksize = newsize; + yysslim = yyss + newsize - 1; + return 0; +} - /* there is no state on the stack with an error shift ... abort */ +#define YYABORT goto yyabort +#define YYREJECT goto yyabort +#define YYACCEPT goto yyaccept +#define YYERROR goto yyerrlab +int +yyparse(void) +{ + register int yym, yyn, yystate; +#if YYDEBUG + register const char *yys; - yyabort: - return(1); + if ((yys = getenv("YYDEBUG")) != 0) + { + yyn = *yys; + if (yyn >= '0' && yyn <= '9') + yydebug = yyn - '0'; + } +#endif + yynerrs = 0; + yyerrflag = 0; + yychar = YYEMPTY; - case 3: /* no shift yet; clobber input char */ + if (yyss == NULL && yygrowstack()) goto yyoverflow; + yyssp = yyss; + yyvsp = yyvs; + *yyssp = yystate = 0; - if( yydebug ) printf( "error recovery discards char %d\n", yychar ); +yyloop: + if ((yyn = yydefred[yystate]) != 0) goto yyreduce; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + } + if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, shifting to state %d\n", + YYPREFIX, yystate, yytable[yyn]); +#endif + if (yyssp >= yysslim && yygrowstack()) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + yychar = YYEMPTY; + if (yyerrflag > 0) --yyerrflag; + goto yyloop; + } + if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yychar) + { + yyn = yytable[yyn]; + goto yyreduce; + } + if (yyerrflag) goto yyinrecovery; - if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */ - yychar = -1; - goto yynewstate; /* try again in the same state */ + yyerror("syntax error"); - } +#ifdef lint + goto yyerrlab; +#endif - } +yyerrlab: + ++yynerrs; - /* reduction by production yyn */ +yyinrecovery: + if (yyerrflag < 3) + { + yyerrflag = 3; + for (;;) + { + if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, error recovery shifting\ + to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); +#endif + if (yyssp >= yysslim && yygrowstack()) + { + goto yyoverflow; + } + *++yyssp = yystate = yytable[yyn]; + *++yyvsp = yylval; + goto yyloop; + } + else + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: error recovery discarding state %d\n", + YYPREFIX, *yyssp); +#endif + if (yyssp <= yyss) goto yyabort; + --yyssp; + --yyvsp; + } + } + } + else + { + if (yychar == 0) goto yyabort; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, error recovery discards token %d (%s)\n", + YYPREFIX, yystate, yychar, yys); + } +#endif + yychar = YYEMPTY; + goto yyloop; + } - if( yydebug ) printf("reduce %d\n",yyn); - yyps -= yyr2[yyn]; - yypvt = yypv; - yypv -= yyr2[yyn]; - yyval = yypv[1]; - yym=yyn; - /* consult goto table to find next state */ - yyn = yyr1[yyn]; - yyj = yypgo[yyn] + *yyps + 1; - if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]]; - switch(yym){ - +yyreduce: +#if YYDEBUG + if (yydebug) + printf("%sdebug: state %d, reducing by rule %d (%s)\n", + YYPREFIX, yystate, yyn, yyrule[yyn]); +#endif + yym = yylen[yyn]; + if (yym) + yyval = yyvsp[1-yym]; + else + memset(&yyval, 0, sizeof yyval); + switch (yyn) + { case 1: +#line 76 "grammar.y" { /* printf("IDENTIFIER\n"); */ if ((work = findvar(last_ident,var_tab)) == -1) if ((work = findvar(last_ident,ext_tab)) == -1) { @@ -388,13 +813,17 @@ case 1: work |= EXTERNAL; if (!efetch(work)) return(1); - } break; + } +break; case 2: +#line 91 "grammar.y" { /*printf("CONSTANT\n"); */ if (!econst(kk)) return(1); - } break; + } +break; case 5: +#line 101 "grammar.y" { /* printf("FCALL\n"); */ popid(func_ident,func_stack,&func_off); /* note ptr to off */ if ((work = findvar(func_ident,func_tab)) == -1) { @@ -404,8 +833,10 @@ case 5: } if(!efcall(work)) return(1); - } break; + } +break; case 6: +#line 112 "grammar.y" { /* printf("FCALL\n"); */ popid(func_ident,func_stack,&func_off); /* note ptr to off */ if ((work = findvar(func_ident,func_tab)) == -1) { @@ -415,8 +846,10 @@ case 6: } if (!efcall(work)) return(1); - } break; + } +break; case 7: +#line 123 "grammar.y" { /* printf("POSTFIX-INC\n"); */ /* this is wrong! same as infix increment */ postfix++; @@ -430,8 +863,10 @@ case 7: work |= EXTERNAL; if(!estore(work,ADD_ASSIGN)) return(1); - } break; + } +break; case 8: +#line 138 "grammar.y" { /* printf("POSTFIX-DEC\n"); */ /* this is wrong! same as infix decrement */ postfix++; @@ -445,14 +880,18 @@ case 8: work |= EXTERNAL; if (!estore(work,SUB_ASSIGN)) return(1); - } break; + } +break; case 9: +#line 156 "grammar.y" { /* printf("FCALL-START\n"); */ stackid(last_ident,func_stack,&func_off); /* note ptr to off */ if (!eframe()) return(1); - } break; + } +break; case 13: +#line 171 "grammar.y" { /* printf("INFIX-INC\n"); */ if (!econst(1L)) return(1); @@ -464,8 +903,10 @@ case 13: work |= EXTERNAL; if (!estore(work,ADD_ASSIGN)) return(1); - } break; + } +break; case 14: +#line 184 "grammar.y" { /* printf("INFIX-DEC\n"); */ if (!econst(1L)) return(1); @@ -477,8 +918,10 @@ case 14: work |= EXTERNAL; if (!estore(work,SUB_ASSIGN)) return(1); - } break; + } +break; case 15: +#line 197 "grammar.y" { /* printf("UNARY-OP\n"); */ /* note special tokens defined only to pass to interpreter */ un_op = *(op_stack + op_off); @@ -499,113 +942,157 @@ case 15: if (!ebinop(U_ONES)) return(1); } - } break; + } +break; case 16: +#line 222 "grammar.y" { /* printf("UNARY-OP\n"); */ op_off++; *(op_stack + op_off) = '-'; - } break; + } +break; case 17: +#line 227 "grammar.y" { op_off++; *(op_stack + op_off) = '!'; - } break; + } +break; case 18: +#line 232 "grammar.y" { op_off++; *(op_stack + op_off) = '~'; - } break; + } +break; case 22: +#line 246 "grammar.y" { /* printf("MULTIPLY\n"); */ if (!ebinop('*')) return(1); - } break; + } +break; case 23: +#line 251 "grammar.y" { /*printf("DIVIDE\n"); */ if (!ebinop('/')) return(1); - } break; + } +break; case 24: +#line 256 "grammar.y" { /* printf("MOD\n"); */ if (!ebinop('%')) return(1); - } break; + } +break; case 26: +#line 265 "grammar.y" { /* printf("ADD\n"); */ if (!ebinop('+')) return(1); - } break; + } +break; case 27: +#line 270 "grammar.y" { /* printf("SUBTRACT\n"); */ if (!ebinop('-')) return(1); - } break; + } +break; case 29: +#line 279 "grammar.y" { /* printf("SHIFT-LEFT\n"); */ if (!ebinop(LEFT_OP)) return(1); - } break; + } +break; case 30: +#line 284 "grammar.y" { /* printf("SHIFT-RIGHT\n"); */ if (!ebinop(RIGHT_OP)) return(1); - } break; + } +break; case 32: +#line 293 "grammar.y" { /* printf("LESS-THAN\n"); */ if (!ebinop('<')) return(1); - } break; + } +break; case 33: +#line 298 "grammar.y" { /* printf("GREATER-THAN\n"); */ if (!ebinop('>')) return(1); - } break; + } +break; case 34: +#line 303 "grammar.y" { /*printf("LESS-EQUAL\n"); */ if (!ebinop(LE_OP)) return(1); - } break; + } +break; case 35: +#line 308 "grammar.y" { /* printf("GREATER-EQUAL\n"); */ if (!ebinop(GE_OP)) return(1); - } break; + } +break; case 37: +#line 317 "grammar.y" { /* printf("EQUAL\n"); */ if (!ebinop(EQ_OP)) return(1); - } break; + } +break; case 38: +#line 322 "grammar.y" { /* printf("NOT-EQUAL\n"); */ if (!ebinop(NE_OP)) return(1); - } break; + } +break; case 40: +#line 331 "grammar.y" { /* printf("AND\n"); */ if (!ebinop('&')) return(1); - } break; + } +break; case 42: +#line 340 "grammar.y" { /* printf("EXCLUSIVE-OR\n"); */ if (!ebinop('^')) return(1); - } break; + } +break; case 44: +#line 349 "grammar.y" { /* printf("INCLUSIVE-OR\n"); */ if (!ebinop('|')) return(1); - } break; + } +break; case 46: +#line 358 "grammar.y" { /* printf("LOGICAL-AND\n"); */ if (!ebinop(AND_OP)) return(1); - } break; + } +break; case 48: +#line 367 "grammar.y" { /* printf("LOGICAL-OR\n"); */ if (!ebinop(OR_OP)) return(1); - } break; + } +break; case 51: +#line 380 "grammar.y" { /* printf("ASSIGNMENT\n"); */ /* func_ident used as temp storage */ popid(func_ident,var_stack,&var_off); /* note ptr to off */ @@ -618,43 +1105,71 @@ case 51: if (!estore(work,*(op_stack + op_off))) return(1); op_off--; - } break; + } +break; case 52: +#line 397 "grammar.y" { /* printf("ASSIGNMENT-LVAL\n"); */ stackid(last_ident,var_stack,&var_off); /* note ptr to off */ op_off++; *(op_stack + op_off) = work; - } break; + } +break; case 53: -{ work = '=';} break; +#line 406 "grammar.y" +{ work = '=';} +break; case 54: -{ work = MUL_ASSIGN;} break; +#line 408 "grammar.y" +{ work = MUL_ASSIGN;} +break; case 55: -{ work = DIV_ASSIGN;} break; +#line 410 "grammar.y" +{ work = DIV_ASSIGN;} +break; case 56: -{ work = MOD_ASSIGN;} break; +#line 412 "grammar.y" +{ work = MOD_ASSIGN;} +break; case 57: -{ work = ADD_ASSIGN;} break; +#line 414 "grammar.y" +{ work = ADD_ASSIGN;} +break; case 58: -{ work = SUB_ASSIGN;} break; +#line 416 "grammar.y" +{ work = SUB_ASSIGN;} +break; case 59: -{ work = LEFT_ASSIGN;} break; +#line 418 "grammar.y" +{ work = LEFT_ASSIGN;} +break; case 60: -{ work = RIGHT_ASSIGN;} break; +#line 420 "grammar.y" +{ work = RIGHT_ASSIGN;} +break; case 61: -{ work = AND_ASSIGN;} break; +#line 422 "grammar.y" +{ work = AND_ASSIGN;} +break; case 62: -{ work = XOR_ASSIGN;} break; +#line 424 "grammar.y" +{ work = XOR_ASSIGN;} +break; case 63: -{ work = OR_ASSIGN;} break; +#line 426 "grammar.y" +{ work = OR_ASSIGN;} +break; case 74: +#line 453 "grammar.y" { /* printf("INITIALIZER\n"); */ fprintf(f_out,"\n**Warning** unsupported initializer\n"); /* get rid of constant placed on stack */ if (!echop()) return(1); - } break; + } +break; case 81: +#line 478 "grammar.y" { /* printf("VARIABLE-DECLARE\n"); */ if (in_func) { if (findvar(last_ident,var_tab) == -1) @@ -664,83 +1179,115 @@ case 81: if (findvar(last_ident,ext_tab) == -1) allocvar(last_ident,ext_tab); } - } break; + } +break; case 82: +#line 489 "grammar.y" { /* printf("FUNCTION-DECLARE\n"); */ if (new_func() == -1) return (1); /* exit the parser */ - } break; + } +break; case 83: +#line 494 "grammar.y" { /* printf("FUNCTION-DECLARE\n"); */ if (new_func() == -1) return (1); /* exit the parser */ - } break; + } +break; case 84: +#line 502 "grammar.y" { /* printf("FUNCTION-DEF-START\n"); */ strcpy(func_ident,last_ident); - } break; + } +break; case 87: +#line 514 "grammar.y" { /* printf("PARAMETER-DECLARE\n"); */ allocvar(last_ident,var_tab); num_parm++; - } break; + } +break; case 122: +#line 595 "grammar.y" { /* printf("CHOP\n"); */ if (!echop()) return(1); - } break; + } +break; case 125: +#line 608 "grammar.y" { /* printf("IF-THEN\n"); */ else_part(); close_if(); - } break; + } +break; case 126: +#line 616 "grammar.y" { /* printf("IF-THEN-ELSE\n"); */ close_if(); - } break; + } +break; case 127: +#line 623 "grammar.y" { /* printf("IF-CLAUSE\n"); */ if (!new_if()) return (1); /* exit parser */ - } break; + } +break; case 128: +#line 631 "grammar.y" { /* printf("ELSE-CLAUSE\n"); */ else_part(); - } break; + } +break; case 129: +#line 638 "grammar.y" { /* printf("WHILE\n"); */ close_while(); - } break; + } +break; case 130: +#line 645 "grammar.y" { /* printf("WHILE-TOKEN\n"); */ if (!new_while()) return (1); /* exit the parser */ - } break; + } +break; case 131: +#line 653 "grammar.y" { /* printf("WHILE-CLAUSE\n"); */ while_expr(); - } break; + } +break; case 132: +#line 660 "grammar.y" { /* printf("BREAK\n"); */ /* breaks can be handled by building a instruct chain */ /* as part of the while_nest structures and patching them */ /* on while_close. maybe later */ fprintf(f_out,"\n**Warning** unsupported break\n"); - } break; + } +break; case 133: +#line 667 "grammar.y" { /* printf("RETURN-NOEXPR\n"); */ /* all functions must return a value */ if (!econst(1L)) return(1); if (!eretsub()) return(1); - } break; + } +break; case 134: +#line 675 "grammar.y" { /* printf("RETURN\n"); */ if (!eretsub()) return(1); - } break; + } +break; case 137: +#line 688 "grammar.y" { /* printf("FUNCTION-DEFINITION\n"); */ /* all functions must return a value */ if (!econst(1L)) @@ -748,11 +1295,70 @@ case 137: if (!eretsub()) return(1); end_func(); - } break; + } +break; case 138: +#line 697 "grammar.y" { /* printf("EXTERNAL-DECLARE\n"); */ - } break; } - goto yystack; /* stack new state and value */ +break; +#line 1306 "y.tab.c" + } + yyssp -= yym; + yystate = *yyssp; + yyvsp -= yym; + yym = yylhs[yyn]; + if (yystate == 0 && yym == 0) + { +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state 0 to\ + state %d\n", YYPREFIX, YYFINAL); +#endif + yystate = YYFINAL; + *++yyssp = YYFINAL; + *++yyvsp = yyval; + if (yychar < 0) + { + if ((yychar = yylex()) < 0) yychar = 0; +#if YYDEBUG + if (yydebug) + { + yys = 0; + if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; + if (!yys) yys = "illegal-symbol"; + printf("%sdebug: state %d, reading %d (%s)\n", + YYPREFIX, YYFINAL, yychar, yys); + } +#endif + } + if (yychar == 0) goto yyaccept; + goto yyloop; + } + if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && + yyn <= YYTABLESIZE && yycheck[yyn] == yystate) + yystate = yytable[yyn]; + else + yystate = yydgoto[yym]; +#if YYDEBUG + if (yydebug) + printf("%sdebug: after reduction, shifting from state %d \ +to state %d\n", YYPREFIX, *yyssp, yystate); +#endif + if (yyssp >= yysslim && yygrowstack()) + { + goto yyoverflow; + } + *++yyssp = yystate; + *++yyvsp = yyval; + goto yyloop; + +yyoverflow: + yyerror("yacc stack overflow"); + +yyabort: + return (1); - } +yyaccept: + return (0); +} diff --git a/src/intrins.c b/src/intrins.c index 269b225..ba6b901 100644 --- a/src/intrins.c +++ b/src/intrins.c @@ -249,7 +249,7 @@ long c_loc_y() long c_rand() { int rand(); - int srand(); /* should be seeded elsewhere */ +/* int srand(); */ /* should be seeded elsewhere */ long limit; limit = pop(); diff --git a/src/lexanal.c b/src/lexanal.c index 2dd93c4..69856c4 100644 --- a/src/lexanal.c +++ b/src/lexanal.c @@ -1,30 +1,520 @@ -# include "stdio.h" -# define U(x) x -# define NLSTATE yyprevious=YYNEWLINE -# define BEGIN yybgin = yysvec + 1 + -# define INITIAL 0 -# define YYLERR yysvec -# define YYSTATE (yyestate-yysvec-1) -# define YYOPTIM 1 -# define YYLMAX 200 -# define output(c) putc(c,yyout) -# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar) -# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;} -# define yymore() (yymorfg=1) -# define ECHO fprintf(yyout, "%s",yytext) -# define REJECT { nstr = yyreject(); goto yyfussy;} -int yyleng; extern char yytext[]; -int yymorfg; -extern char *yysptr, yysbuf[]; -int yytchar; -FILE *yyin = {stdin}, *yyout = {stdout}; + +#line 3 "lex.yy.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + extern int yylineno; -struct yysvf { - struct yywork *yystoff; - struct yysvf *yyother; - int *yystops;}; -struct yysvf *yyestate; -extern struct yysvf yysvec[], *yybgin; + +int yylineno = 1; + +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 59 +#define YY_END_OF_BUFFER 60 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[105] = + { 0, + 0, 0, 0, 0, 60, 58, 57, 57, 46, 52, + 45, 42, 43, 50, 49, 40, 48, 44, 51, 16, + 37, 53, 41, 54, 15, 55, 15, 15, 15, 15, + 15, 15, 15, 15, 38, 56, 39, 47, 3, 59, + 3, 36, 23, 31, 24, 21, 29, 19, 30, 20, + 1, 22, 16, 28, 33, 35, 34, 27, 15, 25, + 15, 15, 15, 15, 15, 9, 15, 15, 15, 15, + 26, 32, 2, 18, 17, 15, 15, 15, 15, 8, + 10, 15, 15, 15, 15, 4, 15, 6, 15, 11, + 15, 15, 15, 5, 15, 15, 15, 14, 7, 15, + + 13, 15, 12, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 4, 1, 1, 1, 5, 6, 1, 7, + 8, 9, 10, 11, 12, 13, 14, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 1, 16, 17, + 18, 19, 1, 1, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 1, 1, 1, 21, 20, 1, 22, 23, 20, 20, + + 24, 25, 26, 27, 28, 20, 29, 30, 20, 31, + 32, 20, 20, 33, 34, 35, 36, 20, 37, 38, + 20, 20, 39, 40, 41, 42, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[43] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, + 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, + 1, 1 + } ; + +static yyconst flex_int16_t yy_base[107] = + { 0, + 0, 0, 40, 41, 112, 113, 113, 113, 93, 92, + 39, 113, 113, 91, 36, 113, 35, 113, 42, 93, + 113, 38, 89, 40, 0, 88, 69, 71, 31, 71, + 37, 70, 77, 73, 113, 30, 113, 113, 113, 113, + 85, 113, 113, 113, 113, 113, 113, 113, 113, 113, + 113, 113, 83, 79, 113, 113, 113, 78, 0, 113, + 60, 70, 59, 57, 58, 0, 55, 58, 37, 60, + 113, 113, 113, 113, 113, 55, 64, 61, 60, 0, + 0, 57, 54, 45, 50, 0, 50, 0, 45, 0, + 43, 43, 51, 0, 40, 32, 35, 0, 0, 41, + + 0, 31, 0, 113, 72, 50 + } ; + +static yyconst flex_int16_t yy_def[107] = + { 0, + 104, 1, 105, 105, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 106, 104, 106, 106, 106, 106, + 106, 106, 106, 106, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 106, 104, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 104, 104, 104, 104, 104, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, + + 106, 106, 106, 0, 104, 104 + } ; + +static yyconst flex_int16_t yy_nxt[156] = + { 0, + 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 25, 25, 31, 25, 32, + 25, 25, 33, 25, 25, 25, 34, 25, 35, 36, + 37, 38, 40, 40, 44, 47, 49, 71, 41, 41, + 51, 59, 50, 48, 54, 55, 45, 57, 58, 52, + 63, 66, 83, 103, 102, 101, 100, 67, 64, 72, + 99, 84, 39, 39, 98, 97, 96, 95, 94, 93, + 92, 91, 90, 89, 88, 87, 86, 85, 82, 81, + 80, 79, 78, 77, 76, 75, 74, 53, 73, 70, + + 69, 68, 65, 62, 61, 60, 56, 53, 46, 43, + 42, 104, 5, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104 + } ; + +static yyconst flex_int16_t yy_chk[156] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 3, 4, 11, 15, 17, 36, 3, 4, + 19, 106, 17, 15, 22, 22, 11, 24, 24, 19, + 29, 31, 69, 102, 100, 97, 96, 31, 29, 36, + 95, 69, 105, 105, 93, 92, 91, 89, 87, 85, + 84, 83, 82, 79, 78, 77, 76, 70, 68, 67, + 65, 64, 63, 62, 61, 58, 54, 53, 41, 34, + + 33, 32, 30, 28, 27, 26, 23, 20, 14, 10, + 9, 5, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, + 104, 104, 104, 104, 104 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "lexanal.l" +#line 6 "lexanal.l" /*****************************************************************************/ /* */ @@ -42,970 +532,1614 @@ extern struct yysvf yysvec[], *yybgin; #include "compiler.h" /* redefine i/o */ -#undef input -#define input() lexgetc() -#undef unput -#define unput(c) lexungetc(c) -#undef output -#define output(c) lexputc(c) #undef ECHO #define ECHO fprintf(f_out,"%s",yytext) long atol(); int count(); -# define YYNEWLINE 10 -yylex(){ -int nstr; extern int yyprevious; -while((nstr = yylook()) >= 0) -yyfussy: switch(nstr){ -case 0: -if(yywrap()) return(0); break; + +#line 543 "lex.yy.c" + +#define INITIAL 0 +#define C_COMMENT 1 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * out_str ); + +int yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + + static void yyunput (int c,char *buf_ptr ); + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + unsigned n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 34 "lexanal.l" + +#line 728 "lex.yy.c" + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 105 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 113 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + case 1: - { comment(); } -break; +YY_RULE_SETUP +#line 35 "lexanal.l" +{ BEGIN(C_COMMENT); } + YY_BREAK case 2: - { count(); return(AUTO); } -break; +YY_RULE_SETUP +#line 36 "lexanal.l" +{ BEGIN(INITIAL); } + YY_BREAK case 3: - { count(); return(BREAK); } -break; +YY_RULE_SETUP +#line 37 "lexanal.l" +{ } + YY_BREAK case 4: - { count(); return(ELSE); } -break; +YY_RULE_SETUP +#line 40 "lexanal.l" +{ count(); return(AUTO); } + YY_BREAK case 5: - { count(); return(EXTERN); } -break; +YY_RULE_SETUP +#line 41 "lexanal.l" +{ count(); return(BREAK); } + YY_BREAK case 6: - { count(); return(FOR); } -break; +YY_RULE_SETUP +#line 42 "lexanal.l" +{ count(); return(ELSE); } + YY_BREAK case 7: - { count(); return(IF); } -break; +YY_RULE_SETUP +#line 43 "lexanal.l" +{ count(); return(EXTERN); } + YY_BREAK case 8: - { count(); return(INT); } -break; +YY_RULE_SETUP +#line 44 "lexanal.l" +{ count(); return(FOR); } + YY_BREAK case 9: - { count(); return(LONG); } -break; +YY_RULE_SETUP +#line 45 "lexanal.l" +{ count(); return(IF); } + YY_BREAK case 10: - { count(); return(REGISTER); } -break; +YY_RULE_SETUP +#line 46 "lexanal.l" +{ count(); return(INT); } + YY_BREAK case 11: - { count(); return(RETURN); } -break; +YY_RULE_SETUP +#line 47 "lexanal.l" +{ count(); return(LONG); } + YY_BREAK case 12: - { count(); return(WHILE); } -break; +YY_RULE_SETUP +#line 48 "lexanal.l" +{ count(); return(REGISTER); } + YY_BREAK case 13: - { count(); +YY_RULE_SETUP +#line 49 "lexanal.l" +{ count(); return(RETURN); } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 50 "lexanal.l" +{ count(); return(WHILE); } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 52 "lexanal.l" +{ count(); strncpy(last_ident,yytext,ILEN-1); last_ident[ILEN-1] = '\0'; return(IDENTIFIER); } -break; -case 14: - { count(); + YY_BREAK +case 16: +YY_RULE_SETUP +#line 57 "lexanal.l" +{ count(); kk = atol(yytext); return(CONSTANT); } -break; -case 15: - { count(); return(RIGHT_ASSIGN); } -break; -case 16: - { count(); return(LEFT_ASSIGN); } -break; + YY_BREAK case 17: - { count(); return(ADD_ASSIGN); } -break; +YY_RULE_SETUP +#line 61 "lexanal.l" +{ count(); return(RIGHT_ASSIGN); } + YY_BREAK case 18: - { count(); return(SUB_ASSIGN); } -break; +YY_RULE_SETUP +#line 62 "lexanal.l" +{ count(); return(LEFT_ASSIGN); } + YY_BREAK case 19: - { count(); return(MUL_ASSIGN); } -break; +YY_RULE_SETUP +#line 63 "lexanal.l" +{ count(); return(ADD_ASSIGN); } + YY_BREAK case 20: - { count(); return(DIV_ASSIGN); } -break; +YY_RULE_SETUP +#line 64 "lexanal.l" +{ count(); return(SUB_ASSIGN); } + YY_BREAK case 21: - { count(); return(MOD_ASSIGN); } -break; +YY_RULE_SETUP +#line 65 "lexanal.l" +{ count(); return(MUL_ASSIGN); } + YY_BREAK case 22: - { count(); return(AND_ASSIGN); } -break; +YY_RULE_SETUP +#line 66 "lexanal.l" +{ count(); return(DIV_ASSIGN); } + YY_BREAK case 23: - { count(); return(XOR_ASSIGN); } -break; +YY_RULE_SETUP +#line 67 "lexanal.l" +{ count(); return(MOD_ASSIGN); } + YY_BREAK case 24: - { count(); return(OR_ASSIGN); } -break; +YY_RULE_SETUP +#line 68 "lexanal.l" +{ count(); return(AND_ASSIGN); } + YY_BREAK case 25: - { count(); return(RIGHT_OP); } -break; +YY_RULE_SETUP +#line 69 "lexanal.l" +{ count(); return(XOR_ASSIGN); } + YY_BREAK case 26: - { count(); return(LEFT_OP); } -break; +YY_RULE_SETUP +#line 70 "lexanal.l" +{ count(); return(OR_ASSIGN); } + YY_BREAK case 27: - { count(); return(INC_OP); } -break; +YY_RULE_SETUP +#line 71 "lexanal.l" +{ count(); return(RIGHT_OP); } + YY_BREAK case 28: - { count(); return(DEC_OP); } -break; +YY_RULE_SETUP +#line 72 "lexanal.l" +{ count(); return(LEFT_OP); } + YY_BREAK case 29: - { count(); return(AND_OP); } -break; +YY_RULE_SETUP +#line 73 "lexanal.l" +{ count(); return(INC_OP); } + YY_BREAK case 30: - { count(); return(OR_OP); } -break; +YY_RULE_SETUP +#line 74 "lexanal.l" +{ count(); return(DEC_OP); } + YY_BREAK case 31: - { count(); return(LE_OP); } -break; +YY_RULE_SETUP +#line 75 "lexanal.l" +{ count(); return(AND_OP); } + YY_BREAK case 32: - { count(); return(GE_OP); } -break; +YY_RULE_SETUP +#line 76 "lexanal.l" +{ count(); return(OR_OP); } + YY_BREAK case 33: - { count(); return(EQ_OP); } -break; +YY_RULE_SETUP +#line 77 "lexanal.l" +{ count(); return(LE_OP); } + YY_BREAK case 34: - { count(); return(NE_OP); } -break; +YY_RULE_SETUP +#line 78 "lexanal.l" +{ count(); return(GE_OP); } + YY_BREAK case 35: - { count(); return(';'); } -break; +YY_RULE_SETUP +#line 79 "lexanal.l" +{ count(); return(EQ_OP); } + YY_BREAK case 36: - { count(); return('{'); } -break; +YY_RULE_SETUP +#line 80 "lexanal.l" +{ count(); return(NE_OP); } + YY_BREAK case 37: - { count(); return('}'); } -break; +YY_RULE_SETUP +#line 81 "lexanal.l" +{ count(); return(';'); } + YY_BREAK case 38: - { count(); return(','); } -break; +YY_RULE_SETUP +#line 82 "lexanal.l" +{ count(); return('{'); } + YY_BREAK case 39: - { count(); return('='); } -break; +YY_RULE_SETUP +#line 83 "lexanal.l" +{ count(); return('}'); } + YY_BREAK case 40: - { count(); return('('); } -break; +YY_RULE_SETUP +#line 84 "lexanal.l" +{ count(); return(','); } + YY_BREAK case 41: - { count(); return(')'); } -break; +YY_RULE_SETUP +#line 85 "lexanal.l" +{ count(); return('='); } + YY_BREAK case 42: - { count(); return('.'); } -break; +YY_RULE_SETUP +#line 86 "lexanal.l" +{ count(); return('('); } + YY_BREAK case 43: - { count(); return('&'); } -break; +YY_RULE_SETUP +#line 87 "lexanal.l" +{ count(); return(')'); } + YY_BREAK case 44: - { count(); return('!'); } -break; +YY_RULE_SETUP +#line 88 "lexanal.l" +{ count(); return('.'); } + YY_BREAK case 45: - { count(); return('~'); } -break; +YY_RULE_SETUP +#line 89 "lexanal.l" +{ count(); return('&'); } + YY_BREAK case 46: - { count(); return('-'); } -break; +YY_RULE_SETUP +#line 90 "lexanal.l" +{ count(); return('!'); } + YY_BREAK case 47: - { count(); return('+'); } -break; +YY_RULE_SETUP +#line 91 "lexanal.l" +{ count(); return('~'); } + YY_BREAK case 48: - { count(); return('*'); } -break; +YY_RULE_SETUP +#line 92 "lexanal.l" +{ count(); return('-'); } + YY_BREAK case 49: - { count(); return('/'); } -break; +YY_RULE_SETUP +#line 93 "lexanal.l" +{ count(); return('+'); } + YY_BREAK case 50: - { count(); return('%'); } -break; +YY_RULE_SETUP +#line 94 "lexanal.l" +{ count(); return('*'); } + YY_BREAK case 51: - { count(); return('<'); } -break; +YY_RULE_SETUP +#line 95 "lexanal.l" +{ count(); return('/'); } + YY_BREAK case 52: - { count(); return('>'); } -break; +YY_RULE_SETUP +#line 96 "lexanal.l" +{ count(); return('%'); } + YY_BREAK case 53: - { count(); return('^'); } -break; +YY_RULE_SETUP +#line 97 "lexanal.l" +{ count(); return('<'); } + YY_BREAK case 54: - { count(); return('|'); } -break; +YY_RULE_SETUP +#line 98 "lexanal.l" +{ count(); return('>'); } + YY_BREAK case 55: - { count(); } -break; +YY_RULE_SETUP +#line 99 "lexanal.l" +{ count(); return('^'); } + YY_BREAK case 56: - { /* ignore bad characters */ } -break; -case -1: -break; -default: -fprintf(yyout,"bad switch yylook %d",nstr); -} return(0); } -/* end of yylex */ +YY_RULE_SETUP +#line 100 "lexanal.l" +{ count(); return('|'); } + YY_BREAK +case 57: +/* rule 57 can match eol */ +YY_RULE_SETUP +#line 102 "lexanal.l" +{ count(); } + YY_BREAK +case 58: +YY_RULE_SETUP +#line 103 "lexanal.l" +{ /* ignore bad characters */ } + YY_BREAK +case 59: +YY_RULE_SETUP +#line 105 "lexanal.l" +ECHO; + YY_BREAK +#line 1112 "lex.yy.c" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(C_COMMENT): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } -yywrap() -{ - return(1); -} + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } -comment() -{ - char c, c1; + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } - output('/'); - output('*'); + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } -loop: - while ((c = input()) != '*' && c != 0) - output(c); + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } - if ((c1 = input()) != '/' && c != 0) - { - unput(c1); - goto loop; - } + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; - if (c != 0) { - output('*'); - output(c1); - } -} + yy_current_state = yy_get_previous_state( ); + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; -count() + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) { - int i; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } - for (i = 0; yytext[i] != '\0'; i++) - if (yytext[i] == '\n') - column = 0; - else if (yytext[i] == '\t') - column += 8 - (column % 8); else - column++; + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } - ECHO; -} + /* Try to read more data. */ + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; -/* the i/o routines depend on f_in and f_out to be opened elsewhere */ + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; -int lexgetc() + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), (size_t) num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) { - int c; - c = fgetc(f_in); - return ((c == EOF) ? 0 : c); + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 105 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; } -lexungetc(c) -int c; +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { - ungetc(c,f_in); + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 105 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 104); + + return yy_is_jam ? 0 : yy_current_state; } -lexputc(c) -int c; + static void yyunput (int c, register char * yy_bp ) { - fputc(c,f_out); + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; } -/* these two dummy routines for lex's debug options */ -allprint() {} +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif -sprint() {} +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; -int yyvstop[] = { -0, + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } -56, -0, + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } -55, -56, -0, + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); -55, -0, + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } -44, -56, -0, + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} -50, -56, -0, +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } -43, -56, -0, + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); -40, -56, -0, + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} -41, -56, -0, +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} -48, -56, -0, +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); -47, -56, -0, + b->yy_buf_size = size; -38, -56, -0, + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); -46, -56, -0, + b->yy_is_our_buffer = 1; -42, -56, -0, + yy_init_buffer(b,file ); -49, -56, -0, + return b; +} -14, -56, -0, +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; -35, -56, -0, + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; -51, -56, -0, + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); -39, -56, -0, + yyfree((void *) b ); +} -52, -56, -0, +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) -13, -56, -0, +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} -53, -56, -0, +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; -13, -56, -0, + b->yy_n_chars = 0; -13, -56, -0, + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; -13, -56, -0, + b->yy_buf_pos = &b->yy_ch_buf[0]; -13, -56, -0, + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; -13, -56, -0, + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} -13, -56, -0, +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } -13, -56, -0, + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; -13, -55, -56, -0, + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} -13, -56, -0, +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; -36, -56, -0, + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); -54, -56, -0, + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} -37, -56, -0, +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } -45, -56, -0, + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ -34, -0, + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; -21, -0, + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); -29, -0, + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} -22, -0, +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} -19, -0, +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,strlen(yystr) ); +} -27, -0, +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = _yybytes_len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); -17, -0, + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; -28, -0, + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; -18, -0, + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); -1, -0, + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; -20, -0, + return b; +} -14, -0, +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif -26, -0, +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} -31, -0, +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} -33, -0, +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} -32, -0, +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} -25, -0, +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} -13, -0, +/** Get the current token. + * + */ -23, -0, +char *yyget_text (void) +{ + return yytext; +} -13, -0, +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} -13, -0, +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} -13, -0, +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} -13, -0, +int yyget_debug (void) +{ + return yy_flex_debug; +} -13, -0, +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} -7, -13, -0, +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = 0; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = (char *) 0; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = (FILE *) 0; + yyout = (FILE *) 0; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} -13, -0, +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } -13, -0, + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; -13, -0, + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); -13, -0, + return 0; +} -24, -0, +/* + * Internal utility routines. + */ -30, -0, +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif -16, -0, +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; -15, -0, + return n; +} +#endif -13, -0, +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} -13, -0, +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} -13, -0, +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} -13, -0, +#define YYTABLES_NAME "yytables" -6, -13, -0, +#line 105 "lexanal.l" -8, -13, -0, -13, -0, -13, -0, +yywrap() +{ + return(1); +} -13, -0, -13, -0, -2, -13, -0, - -13, -0, - -4, -13, -0, - -13, -0, - -9, -13, -0, - -13, -0, - -13, -0, - -13, -0, - -3, -13, -0, - -13, -0, - -13, -0, - -13, -0, - -12, -13, -0, - -5, -13, -0, - -13, -0, - -11, -13, -0, - -13, -0, - -10, -13, -0, -0}; -# define YYTYPE char -struct yywork { YYTYPE verify, advance; } yycrank[] = { -0,0, 0,0, 1,3, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 1,4, 1,5, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 1,6, 0,0, -0,0, 0,0, 1,7, 1,8, -0,0, 1,9, 1,10, 1,11, -1,12, 1,13, 1,14, 1,15, -1,16, 1,17, 8,39, 12,42, -14,44, 16,46, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -1,18, 1,19, 1,20, 1,21, -6,37, 7,38, 1,22, 11,41, -14,45, 12,43, 19,49, 19,50, -16,47, 8,40, 17,48, 17,48, -17,48, 17,48, 17,48, 17,48, -17,48, 17,48, 17,48, 17,48, -20,51, 21,52, 21,53, 23,55, -34,66, 49,68, 53,69, 0,0, -0,0, 0,0, 0,0, 1,23, -0,0, 0,0, 1,24, 1,25, -0,0, 0,0, 1,26, 1,27, -28,61, 30,64, 1,28, 32,65, -57,71, 1,29, 26,58, 0,0, -28,62, 27,60, 29,63, 1,30, -25,57, 58,72, 56,70, 1,31, -1,32, 24,56, 26,59, 59,73, -1,33, 1,34, 1,35, 1,36, -2,6, 60,74, 62,75, 63,76, -2,7, 2,8, 64,77, 2,9, -2,10, 2,11, 2,12, 2,13, -2,14, 2,15, 2,16, 65,79, -70,80, 71,81, 72,82, 64,78, -73,83, 76,84, 77,85, 34,67, -78,86, 79,87, 2,18, 2,19, -2,20, 2,21, 81,88, 83,89, -85,90, 86,91, 87,92, 89,93, -90,94, 91,95, 94,96, 96,97, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 0,0, -0,0, 2,23, 0,0, 0,0, -2,24, 2,25, 0,0, 0,0, -2,26, 2,27, 0,0, 0,0, -2,28, 0,0, 0,0, 2,29, -0,0, 0,0, 0,0, 0,0, -0,0, 2,30, 0,0, 0,0, -0,0, 0,0, 2,32, 0,0, -0,0, 0,0, 2,33, 2,34, -2,35, 2,36, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -0,0, 0,0, 0,0, 0,0, -0,0, 0,0, 0,0, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 0,0, 0,0, 0,0, -0,0, 22,54, 0,0, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 22,54, 22,54, 22,54, -22,54, 0,0, 0,0, 0,0, -0,0}; -struct yysvf yysvec[] = { -0, 0, 0, -yycrank+-1, 0, 0, -yycrank+-95, yysvec+1, 0, -yycrank+0, 0, yyvstop+1, -yycrank+0, 0, yyvstop+3, -yycrank+0, 0, yyvstop+6, -yycrank+3, 0, yyvstop+8, -yycrank+4, 0, yyvstop+11, -yycrank+12, 0, yyvstop+14, -yycrank+0, 0, yyvstop+17, -yycrank+0, 0, yyvstop+20, -yycrank+6, 0, yyvstop+23, -yycrank+8, 0, yyvstop+26, -yycrank+0, 0, yyvstop+29, -yycrank+7, 0, yyvstop+32, -yycrank+0, 0, yyvstop+35, -yycrank+11, 0, yyvstop+38, -yycrank+26, 0, yyvstop+41, -yycrank+0, 0, yyvstop+44, -yycrank+10, 0, yyvstop+47, -yycrank+23, 0, yyvstop+50, -yycrank+24, 0, yyvstop+53, -yycrank+174, 0, yyvstop+56, -yycrank+26, 0, yyvstop+59, -yycrank+4, yysvec+22, yyvstop+62, -yycrank+2, yysvec+22, yyvstop+65, -yycrank+2, yysvec+22, yyvstop+68, -yycrank+2, yysvec+22, yyvstop+71, -yycrank+2, yysvec+22, yyvstop+74, -yycrank+3, yysvec+22, yyvstop+77, -yycrank+4, yysvec+22, yyvstop+80, -yycrank+0, yysvec+22, yyvstop+83, -yycrank+3, yysvec+22, yyvstop+87, -yycrank+0, 0, yyvstop+90, -yycrank+27, 0, yyvstop+93, -yycrank+0, 0, yyvstop+96, -yycrank+0, 0, yyvstop+99, -yycrank+0, 0, yyvstop+102, -yycrank+0, 0, yyvstop+104, -yycrank+0, 0, yyvstop+106, -yycrank+0, 0, yyvstop+108, -yycrank+0, 0, yyvstop+110, -yycrank+0, 0, yyvstop+112, -yycrank+0, 0, yyvstop+114, -yycrank+0, 0, yyvstop+116, -yycrank+0, 0, yyvstop+118, -yycrank+0, 0, yyvstop+120, -yycrank+0, 0, yyvstop+122, -yycrank+0, yysvec+17, yyvstop+124, -yycrank+28, 0, yyvstop+126, -yycrank+0, 0, yyvstop+128, -yycrank+0, 0, yyvstop+130, -yycrank+0, 0, yyvstop+132, -yycrank+29, 0, yyvstop+134, -yycrank+0, yysvec+22, yyvstop+136, -yycrank+0, 0, yyvstop+138, -yycrank+2, yysvec+22, yyvstop+140, -yycrank+7, yysvec+22, yyvstop+142, -yycrank+2, yysvec+22, yyvstop+144, -yycrank+7, yysvec+22, yyvstop+146, -yycrank+15, yysvec+22, yyvstop+148, -yycrank+0, yysvec+22, yyvstop+150, -yycrank+14, yysvec+22, yyvstop+153, -yycrank+21, yysvec+22, yyvstop+155, -yycrank+31, yysvec+22, yyvstop+157, -yycrank+38, yysvec+22, yyvstop+159, -yycrank+0, 0, yyvstop+161, -yycrank+0, 0, yyvstop+163, -yycrank+0, 0, yyvstop+165, -yycrank+0, 0, yyvstop+167, -yycrank+33, yysvec+22, yyvstop+169, -yycrank+48, yysvec+22, yyvstop+171, -yycrank+45, yysvec+22, yyvstop+173, -yycrank+47, yysvec+22, yyvstop+175, -yycrank+0, yysvec+22, yyvstop+177, -yycrank+0, yysvec+22, yyvstop+180, -yycrank+46, yysvec+22, yyvstop+183, -yycrank+45, yysvec+22, yyvstop+185, -yycrank+35, yysvec+22, yyvstop+187, -yycrank+45, yysvec+22, yyvstop+189, -yycrank+0, yysvec+22, yyvstop+191, -yycrank+51, yysvec+22, yyvstop+194, -yycrank+0, yysvec+22, yyvstop+196, -yycrank+45, yysvec+22, yyvstop+199, -yycrank+0, yysvec+22, yyvstop+201, -yycrank+45, yysvec+22, yyvstop+204, -yycrank+47, yysvec+22, yyvstop+206, -yycrank+61, yysvec+22, yyvstop+208, -yycrank+0, yysvec+22, yyvstop+210, -yycrank+53, yysvec+22, yyvstop+213, -yycrank+48, yysvec+22, yyvstop+215, -yycrank+55, yysvec+22, yyvstop+217, -yycrank+0, yysvec+22, yyvstop+219, -yycrank+0, yysvec+22, yyvstop+222, -yycrank+65, yysvec+22, yyvstop+225, -yycrank+0, yysvec+22, yyvstop+227, -yycrank+53, yysvec+22, yyvstop+230, -yycrank+0, yysvec+22, yyvstop+232, -0, 0, 0}; -struct yywork *yytop = yycrank+296; -struct yysvf *yybgin = yysvec+1; -char yymatch[] = { -00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , -01 ,011 ,012 ,01 ,011 ,01 ,01 ,01 , -01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , -01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , -011 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , -01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 , -'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' , -'0' ,'0' ,01 ,01 ,01 ,01 ,01 ,01 , -01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' , -'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' , -'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' , -'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,'A' , -01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' , -'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' , -'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'v' ,'A' , -'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,01 , -0}; -char yyextra[] = { -0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0, -0}; -int yylineno =1; -# define YYU(x) x -# define NLSTATE yyprevious=YYNEWLINE -char yytext[YYLMAX]; -struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp; -char yysbuf[YYLMAX]; -char *yysptr = yysbuf; -int *yyfnd; -extern struct yysvf *yyestate; -int yyprevious = YYNEWLINE; -yylook(){ - register struct yysvf *yystate, **lsp; - register struct yywork *yyt; - struct yysvf *yyz; - int yych, yyfirst; - struct yywork *yyr; - int debug; - char *yylastch; - /* start off machines */ - debug = 0; - yyfirst=1; - if (!yymorfg) - yylastch = yytext; - else { - yymorfg=0; - yylastch = yytext+yyleng; - } - for(;;){ - lsp = yylstate; - yyestate = yystate = yybgin; - if (yyprevious==YYNEWLINE) yystate++; - for (;;){ - if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1); - yyt = yystate->yystoff; - if(yyt == yycrank && !yyfirst){ /* may not be any transitions */ - yyz = yystate->yyother; - if(yyz == 0)break; - if(yyz->yystoff == yycrank)break; - } - *yylastch++ = yych = input(); - yyfirst=0; - tryagain: - if(debug){ - fprintf(yyout,"char "); - allprint(yych); - putchar('\n'); - } - yyr = yyt; - if ( (int)yyt > (int)yycrank){ - yyt = yyr + yych; - if (yyt <= yytop && yyt->verify+yysvec == yystate){ - if(yyt->advance+yysvec == YYLERR) /* error transitions */ - {unput(*--yylastch);break;} - *lsp++ = yystate = yyt->advance+yysvec; - goto contin; - } - } - else if((int)yyt < (int)yycrank) { /* r < yycrank */ - yyt = yyr = yycrank+(yycrank-yyt); - if(debug)fprintf(yyout,"compressed state\n"); - yyt = yyt + yych; - if(yyt <= yytop && yyt->verify+yysvec == yystate){ - if(yyt->advance+yysvec == YYLERR) /* error transitions */ - {unput(*--yylastch);break;} - *lsp++ = yystate = yyt->advance+yysvec; - goto contin; - } - yyt = yyr + YYU(yymatch[yych]); - if(debug){ - fprintf(yyout,"try fall back character "); - allprint(YYU(yymatch[yych])); - putchar('\n'); - } - if(yyt <= yytop && yyt->verify+yysvec == yystate){ - if(yyt->advance+yysvec == YYLERR) /* error transition */ - {unput(*--yylastch);break;} - *lsp++ = yystate = yyt->advance+yysvec; - goto contin; - } - } - if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){ - if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1); - goto tryagain; - } - else - {unput(*--yylastch);break;} - contin: - if(debug){ - fprintf(yyout,"state %d char ",yystate-yysvec-1); - allprint(yych); - putchar('\n'); - } - ; - } - if(debug){ - fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1); - allprint(yych); - putchar('\n'); - } - while (lsp-- > yylstate){ - *yylastch-- = 0; - if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){ - yyolsp = lsp; - if(yyextra[*yyfnd]){ /* must backup */ - while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){ - lsp--; - unput(*yylastch--); - } - } - yyprevious = YYU(*yylastch); - yylsp = lsp; - yyleng = yylastch-yytext+1; - yytext[yyleng] = 0; - if(debug){ - fprintf(yyout,"\nmatch "); - sprint(yytext); - fprintf(yyout," action %d\n",*yyfnd); - } - return(*yyfnd++); - } - unput(*yylastch); - } - if (yytext[0] == 0 /* && feof(yyin) */) - { - yysptr=yysbuf; - return(0); - } - yyprevious = yytext[0] = input(); - if (yyprevious>0) - output(yyprevious); - yylastch=yytext; - if(debug)putchar('\n'); - } - } -yyback(p, m) - int *p; +count() { -if (p==0) return(0); -while (*p) - { - if (*p++ == m) - return(1); - } -return(0); + int i; + + for (i = 0; yytext[i] != '\0'; i++) + if (yytext[i] == '\n') + column = 0; + else if (yytext[i] == '\t') + column += 8 - (column % 8); + else + column++; + + ECHO; } - /* the following are only used in the lex library */ -yyinput(){ - return(input()); - } -yyoutput(c) - int c; { - output(c); - } -yyunput(c) - int c; { - unput(c); - } + + +/* the i/o routines depend on f_in and f_out to be opened elsewhere */ + + +/* these two dummy routines for lex's debug options */ +allprint() {} + +sprint() {} + + diff --git a/src/lexanal.h b/src/lexanal.h new file mode 100644 index 0000000..f2b0322 --- /dev/null +++ b/src/lexanal.h @@ -0,0 +1,317 @@ +#ifndef yyHEADER_H +#define yyHEADER_H 1 +#define yyIN_HEADER 1 + +#line 6 "lexanal.h" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) + +#define YY_USE_CONST + +#endif /* defined (__STDC__) */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +/* Begin user sect3 */ + +extern int yylineno; + +extern char *yytext; +#define yytext_ptr yytext + +#ifdef YY_HEADER_EXPORT_START_CONDITIONS +#define INITIAL 0 +#define C_COMMENT 1 + +#endif + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * out_str ); + +int yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL +#endif + +#line 105 "lexanal.l" + + +#line 316 "lexanal.h" +#undef yyIN_HEADER +#endif /* yyHEADER_H */ diff --git a/src/lexanal.l b/src/lexanal.l index 89af704..0013fd1 100644 --- a/src/lexanal.l +++ b/src/lexanal.l @@ -1,6 +1,7 @@ D [0-9] L [a-zA-Z_] + %{ /*****************************************************************************/ @@ -19,12 +20,6 @@ L [a-zA-Z_] #include "compiler.h" /* redefine i/o */ -#undef input -#define input() lexgetc() -#undef unput -#define unput(c) lexungetc(c) -#undef output -#define output(c) lexputc(c) #undef ECHO #define ECHO fprintf(f_out,"%s",yytext) @@ -33,8 +28,14 @@ int count(); %} +%x C_COMMENT + + %% -"/*" { comment(); } +"/*" { BEGIN(C_COMMENT); } +"*/" { BEGIN(INITIAL); } +. { } + "auto" { count(); return(AUTO); } "break" { count(); return(BREAK); } @@ -108,28 +109,6 @@ yywrap() return(1); } -comment() -{ - char c, c1; - - output('/'); - output('*'); - -loop: - while ((c = input()) != '*' && c != 0) - output(c); - - if ((c1 = input()) != '/' && c != 0) - { - unput(c1); - goto loop; - } - - if (c != 0) { - output('*'); - output(c1); - } -} count() @@ -150,24 +129,6 @@ count() /* the i/o routines depend on f_in and f_out to be opened elsewhere */ -int lexgetc() -{ - int c; - c = fgetc(f_in); - return ((c == EOF) ? 0 : c); -} - -lexungetc(c) -int c; -{ - ungetc(c,f_in); -} - -lexputc(c) -int c; -{ - fputc(c,f_out); -} /* these two dummy routines for lex's debug options */ allprint() {} diff --git a/src/main.c b/src/main.c index dd682bd..13c1c7e 100644 --- a/src/main.c +++ b/src/main.c @@ -51,7 +51,8 @@ char *argv[]; long time(); long atol(); long cur_time; - int srand(); +/* bj no longer needed */ +/* int srand(); */ /* print version, copyright notice, GPL notice */ @@ -613,8 +614,8 @@ char *f; robots[1].status = ACTIVE; cur_robot = &robots[0]; - - fprintf("\n\nReady to debug, use `d' to dump robot info, `q' to quit.\n\n"); + /* bj stdout missing */ + fprintf(stdout,"\n\nReady to debug, use `d' to dump robot info, `q' to quit.\n\n"); while (c) { cycle(); diff --git a/src/rook.r b/src/rook.r index 299b532..4acca5a 100644 --- a/src/rook.r +++ b/src/rook.r @@ -1,6 +1,3 @@ -/* rook.r - scans the battlefield like a rook, i.e., only 0,90,180,270 */ -/* move horizontally only, but looks horz and vertically */ - int course; int boundary; int d; diff --git a/src/tokens.h b/src/tokens.h index 62451f0..72a9ad0 100644 --- a/src/tokens.h +++ b/src/tokens.h @@ -1,36 +1,36 @@ -# define IDENTIFIER 257 -# define CONSTANT 258 -# define INC_OP 259 -# define DEC_OP 260 -# define LEFT_OP 261 -# define RIGHT_OP 262 -# define LE_OP 263 -# define GE_OP 264 -# define EQ_OP 265 -# define NE_OP 266 -# define AND_OP 267 -# define OR_OP 268 -# define MUL_ASSIGN 269 -# define DIV_ASSIGN 270 -# define MOD_ASSIGN 271 -# define ADD_ASSIGN 272 -# define SUB_ASSIGN 273 -# define LEFT_ASSIGN 274 -# define RIGHT_ASSIGN 275 -# define AND_ASSIGN 276 -# define XOR_ASSIGN 277 -# define OR_ASSIGN 278 -# define EXTERN 279 -# define AUTO 280 -# define REGISTER 281 -# define INT 282 -# define LONG 283 -# define IF 284 -# define ELSE 285 -# define WHILE 286 -# define FOR 287 -# define RETURN 288 -# define BREAK 289 -# define U_NEGATIVE 290 -# define U_NOT 291 -# define U_ONES 292 +#define IDENTIFIER 257 +#define CONSTANT 258 +#define INC_OP 259 +#define DEC_OP 260 +#define LEFT_OP 261 +#define RIGHT_OP 262 +#define LE_OP 263 +#define GE_OP 264 +#define EQ_OP 265 +#define NE_OP 266 +#define AND_OP 267 +#define OR_OP 268 +#define MUL_ASSIGN 269 +#define DIV_ASSIGN 270 +#define MOD_ASSIGN 271 +#define ADD_ASSIGN 272 +#define SUB_ASSIGN 273 +#define LEFT_ASSIGN 274 +#define RIGHT_ASSIGN 275 +#define AND_ASSIGN 276 +#define XOR_ASSIGN 277 +#define OR_ASSIGN 278 +#define EXTERN 279 +#define AUTO 280 +#define REGISTER 281 +#define INT 282 +#define LONG 283 +#define IF 284 +#define ELSE 285 +#define WHILE 286 +#define FOR 287 +#define RETURN 288 +#define BREAK 289 +#define U_NEGATIVE 290 +#define U_NOT 291 +#define U_ONES 292 From ce0d9d9a0e4ad34d8504bcc848c62678276b2489 Mon Sep 17 00:00:00 2001 From: misterunix Date: Tue, 9 Dec 2014 09:58:58 -0600 Subject: [PATCH 2/3] short int refs fixed - runs now. More cleanup needed on code to remove warnings. --- src/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Makefile b/src/Makefile index 1d33a89..a871439 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,3 +1,4 @@ +CC = gcc # makefile for crobots OBJS = main.o grammar.o lexanal.o compiler.o cpu.o intrins.o display.o screen.o motion.o @@ -10,7 +11,7 @@ DOSA = main.c grammar.c lexanal.c compiler.c cpu.c intrins.c display.c screena.c # Xenix cc flags: optimize(O), omit stack checking(K), separate text and data(i) -CFLAGS = -O2 -DUNIX +CFLAGS = -O2 -Wall -DUNIX -g LIBS = -lm -lcurses # note - grammar.c and lexanal.c: both yacc (grammar.y) and lex (lexanal.l) @@ -21,7 +22,7 @@ LIBS = -lm -lcurses # confused when '#ifdef symbol .... #endif' are nested. crobots: $(OBJS) - cc -s $(CFLAGS) $(OBJS) -o crobots $(LIBS) + cc $(CFLAGS) $(OBJS) -o crobots $(LIBS) main.o: crobots.h main.c cc $(CFLAGS) -c main.c @@ -58,11 +59,11 @@ motion.o: crobots.h motion.c cc $(CFLAGS) -c motion.c dos: - cc -s -dos -K -i -O -DDOS $(DOS) -o crobotsx.exe -lm + cc -dos -K -i -O -DDOS $(DOS) -o crobotsx.exe -lm /bin/rm *.o dosa: - cc -s -dos -K -i -O -DDOS $(DOSA) -o crobotsa.exe -lm + cc -dos -K -i -O -DDOS $(DOSA) -o crobotsa.exe -lm /bin/rm *.o print: pr -t $(SOURCES) | lpr From a21d07a2e498a54f5b57426b2b8c9dc0cba22d8f Mon Sep 17 00:00:00 2001 From: misterunix Date: Tue, 9 Dec 2014 11:54:12 -0600 Subject: [PATCH 3/3] Final - works - fairly clean compile. No plans to continue working on this branch. --- src/Makefile | 2 +- src/compiler.c | 143 +++++++++++--------------------------- src/cpu.c | 57 +++++++-------- src/crobots.h | 89 +++++++++++++++++++----- src/display.c | 6 +- src/grammar.c | 183 ++++++++++++++++++++++++++++--------------------- src/grammar.y | 57 ++++++++++----- src/intrins.c | 27 ++++---- src/lexanal.c | 144 ++++++++++++++++++-------------------- src/lexanal.h | 2 +- src/lexanal.l | 16 ++--- src/main.c | 52 ++++---------- src/motion.c | 13 ++-- src/screen.c | 28 +++----- src/screena.c | 4 +- src/screend.c | 4 +- 16 files changed, 399 insertions(+), 428 deletions(-) diff --git a/src/Makefile b/src/Makefile index a871439..ea29265 100644 --- a/src/Makefile +++ b/src/Makefile @@ -11,7 +11,7 @@ DOSA = main.c grammar.c lexanal.c compiler.c cpu.c intrins.c display.c screena.c # Xenix cc flags: optimize(O), omit stack checking(K), separate text and data(i) -CFLAGS = -O2 -Wall -DUNIX -g +CFLAGS = -O2 -Wall -DUNIX LIBS = -lm -lcurses # note - grammar.c and lexanal.c: both yacc (grammar.y) and lex (lexanal.l) diff --git a/src/compiler.c b/src/compiler.c index e4a4417..9ac4f00 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -23,8 +23,7 @@ /* yyerror - simple error message on parser failure */ -yyerror(s) -char *s; +void yyerror( char *s ) { int i; r_flag = 1; @@ -42,7 +41,7 @@ char *s; /* init_comp - initializes the compiler for one file */ /* assumes robot structure allocated and pointed to by cur->robot */ -init_comp() +void init_comp( void ) { register int i; @@ -102,7 +101,7 @@ init_comp() /* reset_comp - resets the compiler for another file */ /* completes the robot structure */ -reset_comp() +int reset_comp( void ) { int i, j; int found = 0; @@ -204,7 +203,7 @@ reset_comp() /* new_func - reset the compiler for a new function within the same file */ -new_func() +int new_func( void ) { register int i; @@ -238,7 +237,7 @@ new_func() /* end_func - cleanup the end of a function */ -end_func() +void end_func( void ) { register int i; @@ -272,10 +271,7 @@ end_func() /* allocvar - allocates a variable in a pool, returns offset */ -allocvar(s,pool) - -char s[]; -char *pool; +int allocvar(char *s, char *pool) { register int i; @@ -296,10 +292,7 @@ char *pool; /* findvar - returns offset of variable in a pool */ -findvar(s,pool) - -char s[]; -char *pool; +int findvar(char *s, char *pool) { register int i; @@ -313,12 +306,7 @@ char *pool; /* stackid - stacks an identifier, note pointer to stack offset */ - -stackid(id,stack,ptr) - -char id[]; -char *stack; -int *ptr; +int stackid( char *id, char *stack, int *ptr ) { if (*ptr < MAXSYM - 1) { (*ptr)++; /* the ptr itself is incremented */ @@ -334,12 +322,7 @@ int *ptr; /* popid - unstacks an identifier, note pointer to stack offset */ - -popid(id,stack,ptr) - -char id[]; -char *stack; -int *ptr; +int popid( char *id, char *stack, int *ptr ) { if (*ptr > 0) { strcpy(id,stack + (*ptr * ILEN)); @@ -357,10 +340,7 @@ int *ptr; /* poolsize - returns the size of a pool */ - -poolsize(pool) - -char *pool; +int poolsize( char *pool ) { register int i; @@ -378,10 +358,7 @@ char *pool; /* dumpoff - print a table of names and offsets in a symbol pool */ - -dumpoff(pool) - -char *pool; +void dumpoff( char *pool ) { register int i; int count = 0; @@ -402,9 +379,7 @@ char *pool; /* efetch - emit a fetch instruction */ -efetch(offset) - -int offset; +int efetch( int offset ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -421,10 +396,7 @@ int offset; /* estore - emit a store instruction */ -estore(offset, operator) - -int offset; -int operator; +int estore( int offset, int operator ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -441,14 +413,12 @@ int operator; /* econst - emit a constant instruction */ - -econst(c) - -long c; +int econst( long c ) { - if (++num_instr == CODESPACE) { + if (++num_instr == CODESPACE) + { r_flag = 1; -printf("\n\n**econst*\n\n"); + printf("\n\n**econst*\n\n"); return (0); } instruct->ins_type = CONST; @@ -459,10 +429,7 @@ printf("\n\n**econst*\n\n"); /* ebinop - emit a binop instruction */ - -ebinop(c) - -int c; +int ebinop( int c ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -478,10 +445,7 @@ int c; /* efcall - emit a fcall instruction */ - -efcall (c) - -int c; +int efcall( int c ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -497,9 +461,7 @@ int c; /* eretsub - emit a retsub instruction */ - -eretsub() - +int eretsub( void ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -514,9 +476,7 @@ eretsub() /* ebranch - emit a branch instruction */ - -ebranch() - +int ebranch( void ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -532,9 +492,7 @@ ebranch() /* echop - emit a chop instruction */ - -echop() - +int echop( void ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -549,9 +507,7 @@ echop() /* eframe - emit a stack frame instruction */ - -eframe() - +int eframe( void ) { if (++num_instr == CODESPACE) { r_flag = 1; @@ -566,9 +522,7 @@ eframe() /* new_if - start a nest for an if statement */ - -new_if() - +int new_if( void ) { if (if_nest == NESTLEVEL) { fprintf(f_out,"\n** Error ** 'if' nest level exceeded\n"); @@ -591,9 +545,7 @@ new_if() /* else_part - the else part of an if-then-else */ - -else_part() - +int else_part( void ) { /* setup a unconditional branch around the else part */ if (!econst(0L)) @@ -614,9 +566,7 @@ else_part() /* close_if - close out an if nest */ - -close_if() - +void close_if( void ) { /* fix the not-else branch saved in else_part() */ (ifs + if_nest)->fix_true->u.br = instruct; @@ -626,9 +576,7 @@ close_if() /* new_while - start a nest for a new while statement */ - -new_while() - +int new_while( void ) { if (while_nest == NESTLEVEL) { fprintf(f_out,"\n** Error ** 'while' nest level exceeded\n"); @@ -647,9 +595,7 @@ new_while() /* while_expr - while expression loop fix */ - -while_expr() - +int while_expr( void ) { if (!ebranch()) return (0); @@ -663,9 +609,7 @@ while_expr() /* close_while - close out the while nest */ - -close_while() - +int close_while( void ) { /* emit an unconditional branch */ if (!econst(0L)) @@ -687,10 +631,7 @@ close_while() /* decompile - print machine code */ - -decompile(code) - -struct instr *code; +void decompile( struct instr *code ) { while (code->ins_type != NOP) { @@ -702,26 +643,22 @@ struct instr *code; /* decinstr - print one instruct; watch out for pointer to long conversion! */ - -decinstr(code) - -struct instr *code; +void decinstr(struct instr *code) { fprintf(f_out,"%8ld : ",(long) code); /* this could be flakey */ switch (code->ins_type) { case FETCH: if (code->u.var1 & EXTERNAL) - fprintf(f_out,"fetch %d external\n",code->u.var1 & ~EXTERNAL); + fprintf(f_out,"fetch %hd external\n",code->u.var1 & ~EXTERNAL); else - fprintf(f_out,"fetch %d local\n",code->u.var1); + fprintf(f_out,"fetch %hd local\n",code->u.var1); break; case STORE: if (code->u.a.var2 & EXTERNAL) - fprintf(f_out,"store %d external, ", - code->u.a.var2 & ~EXTERNAL); + fprintf(f_out,"store %hd external, ",code->u.a.var2 & ~EXTERNAL); else - fprintf(f_out,"store %d local, ",code->u.a.var2); + fprintf(f_out,"store %hd local, ",code->u.a.var2); printop(code->u.a.a_op); fprintf(f_out,"\n"); break; @@ -734,7 +671,7 @@ struct instr *code; fprintf(f_out,"\n"); break; case FCALL: - fprintf(f_out,"fcall %d\n",code->u.var1); + fprintf(f_out,"fcall %hd\n",code->u.var1); break; case RETSUB: fprintf(f_out,"retsub\n"); @@ -757,9 +694,7 @@ struct instr *code; /* printop - print a binary operation code */ -printop(op) - -int op; +void printop( int op ) { switch (op) { @@ -805,7 +740,7 @@ int op; break; case '%': - fprintf(f_out,"%"); + fprintf(f_out,"%%"); break; case LEFT_OP: @@ -849,7 +784,7 @@ int op; break; case MOD_ASSIGN: - fprintf(f_out,"%="); + fprintf(f_out,"%%="); break; case ADD_ASSIGN: diff --git a/src/cpu.c b/src/cpu.c index 36af302..e233b11 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -18,9 +18,7 @@ /* push - basic stack push mechanism */ /* depends on cur_robot, set r_flag on overflow */ -long push(k) - -long k; +long push(long k) { /* increment stack and check for collistion into return ptrs */ if (++cur_robot->stackptr == cur_robot->retptr) { @@ -54,7 +52,7 @@ long pop() /* any errors (stack collision, missing functions, etc) cause the 'main' */ /* function to be restarted, with a clean stack; signal by r_flag = 1 */ -cycle() +void cycle( void ) { int j; int c; @@ -65,8 +63,8 @@ cycle() register char *n; struct instr **i; long **l; - long push(); - long pop(); +/* long push(); */ +/* long pop(); */ cur_instr = cur_robot->ip; @@ -79,9 +77,11 @@ cycle() case FETCH: /* push a value from a variable pool */ if (cur_instr->u.var1 & EXTERNAL) - push(*(cur_robot->external + (cur_instr->u.var1 & ~EXTERNAL))); + { + push(*(cur_robot->external + (short int)(cur_instr->u.var1 & ~EXTERNAL))); + } else - push(*(cur_robot->local + cur_instr->u.var1)); + push(*(cur_robot->local + (short int)cur_instr->u.var1)); cur_robot->ip++; break; @@ -89,10 +89,9 @@ cycle() case STORE: /* store tos in a variable pool */ binaryop(cur_instr->u.a.a_op); /* perform assignment operation */ - if (cur_instr->u.a.var2 & EXTERNAL) - *(cur_robot->external +(cur_instr->u.a.var2 & ~EXTERNAL)) = push(pop()); + if (cur_instr->u.a.var2 & EXTERNAL) * (cur_robot->external + (short int)(cur_instr->u.a.var2 & ~EXTERNAL)) = push(pop()); else - *(cur_robot->local + cur_instr->u.var1) = push(pop()); + *(cur_robot->local + (short int)cur_instr->u.var1) = push(pop()); cur_robot->ip++; break; @@ -282,16 +281,17 @@ cycle() printf("\t\t\t\ttos %ld: * %ld\n", (long)cur_robot->stackptr,*cur_robot->stackptr); printf("d,h,q,: "); - if ((c=getchar()) == 'd') { +/* if ((c=getchar()) == 'd') { */ + if( 1 ) { printf("\nexternals"); dumpvar(cur_robot->external,cur_robot->ext_count); printf("\nlocal stack"); dumpvar(cur_robot->local,cur_robot->stackptr - cur_robot->local + 1); - printf("\n\nx...........%7ld",cur_robot->x); - printf("\ty...........%7ld",cur_robot->y); - printf("\norg_x.......%7ld",cur_robot->org_x); - printf("\torg_y.......%7ld",cur_robot->org_y); - printf("\nrange.......%7ld",cur_robot->range); + printf("\n\nx...........%7d",cur_robot->x); + printf("\ty...........%7d",cur_robot->y); + printf("\norg_x.......%7d",cur_robot->org_x); + printf("\torg_y.......%7d",cur_robot->org_y); + printf("\nrange.......%7d",cur_robot->range); printf("\tspeed.......%7d",cur_robot->speed); printf("\nd_speed.....%7d",cur_robot->d_speed); printf("\theading.....%7d",cur_robot->heading); @@ -301,12 +301,12 @@ cycle() printf("\tmiss[1]stat.%7d",missiles[cur_robot-&robots[0]][1].stat); printf("\nmiss[0]head.%7d",missiles[cur_robot-&robots[0]][0].head); printf("\tmiss[1]head.%7d",missiles[cur_robot-&robots[0]][1].head); - printf("\nmiss[0]x....%7ld",missiles[cur_robot-&robots[0]][0].cur_x); - printf("\tmiss[1]y....%7ld",missiles[cur_robot-&robots[0]][1].cur_y); - printf("\nmiss[0]dist.%7ld",missiles[cur_robot-&robots[0]][0].curr_dist); - printf("\tmiss[1]dist.%7ld",missiles[cur_robot-&robots[0]][1].curr_dist); + printf("\nmiss[0]x....%7d",missiles[cur_robot-&robots[0]][0].cur_x); + printf("\tmiss[1]y....%7d",missiles[cur_robot-&robots[0]][1].cur_y); + printf("\nmiss[0]dist.%7d",missiles[cur_robot-&robots[0]][0].curr_dist); + printf("\tmiss[1]dist.%7d",missiles[cur_robot-&robots[0]][1].curr_dist); printf("\n\n"); - getchar(); + /* getchar(); */ } else { if (c == 'q') { /* quit debugging */ r_flag = 1; @@ -325,9 +325,7 @@ cycle() /* binaryop - pops 2 operands, performs operation, pushes result */ /* divide by zero handled by returning 0 */ -binaryop(op) - -int op; +void binaryop(int op) { long x,y; @@ -485,9 +483,7 @@ int op; /* robot_go - start the robot pointed to by r */ -robot_go(r) - -struct robot *r; +void robot_go(struct robot *r) { register struct func *f; register int i; @@ -510,10 +506,7 @@ struct robot *r; /* dumpvar - dump a variable pool or stack for length size */ -dumpvar(pool,size) - -long *pool; -int size; +void dumpvar(long *pool,int size) { register int i; diff --git a/src/crobots.h b/src/crobots.h index c93736f..94ae04a 100644 --- a/src/crobots.h +++ b/src/crobots.h @@ -162,21 +162,19 @@ int r_debug, /* debug switch */ #define NEAR_RANGE 20 #define FAR_RANGE 40 -/* declare the intrinsic functions, all must push a long value on the stack */ -/* these functions don't return a long, but declared long for notation */ -long c_scan(); /* scan(degree,res); >0 = robot distance, 0 = nothing */ -long c_cannon(); /* cannon(degree,dist); fire cannon */ -long c_drive(); /* drive(degree,speed); speed 0-100 in % */ -long c_damage(); /* damage(); = current damage in % */ -long c_speed(); /* speed(); = current speed */ -long c_loc_x(); /* loc_x(); = current x location */ -long c_loc_y(); /* loc_y(); = current y location */ -long c_rand(); /* rand(limit); = 0 -- limit (2**15)-1 */ -long c_sin(); /* sin(degree); = sin * 100000 */ -long c_cos(); /* cos(degree); = cos * 100000 */ -long c_tan(); /* tan(degree); = tan * 100000 */ -long c_atan(); /* atan(ratio); = degree */ -long c_sqrt(); /* sqrt(x); = square root */ +void c_scan( void ); +void c_cannon( void ); +void c_drive( void ); +void c_damage( void ); +void c_speed( void ); +void c_loc_x( void ); +void c_loc_y( void ); +void c_rand( void ); +void c_sin( void ); +void c_cos( void ); +void c_tan( void ); +void c_atan( void ); +void c_sqrt( void ); /* declare instrinsic function table */ #ifndef INIT @@ -184,12 +182,12 @@ extern #endif struct intrin { char *n; - long (*f)(); + void (*f)(void); } intrinsics[20] #ifdef INIT = { - {"*dummy*", (long (*)()) 0}, + {"*dummy*", (void (*)()) 0}, {"scan", c_scan}, {"cannon", c_cannon}, {"drive", c_drive}, @@ -203,9 +201,64 @@ struct intrin { {"tan", c_tan}, {"atan", c_atan}, {"sqrt", c_sqrt}, - {"", (long (*)()) 0} + {"", (void (*)()) 0} } #endif ; /* end of crobots.h header */ + +void robot_stat( int n ); +void decinstr(struct instr *code); +void binaryop(int op); +void dumpvar(long *pool,int size); +void robot_go(struct robot *r); +void rand_pos( int n ); +void end_disp( void ); +void draw_field( void ); +void plot_robot( int n ); +void plot_miss( int r, int n); +void plot_exp(int r, int n); +void show_cycle( long l ); +void init_disp( void ); +void update_disp( void ); +void count_miss( int i, int j ) ; +void init_comp( void ) ; +int reset_comp( void ) ; +int new_func( void ); +void end_func( void ) ; +int allocvar(char *s, char *pool); +int efetch( int offset ); +int estore( int offset, int operator ); +int econst( long c ); +void dumpoff( char *pool ); +int findvar(char *s, char *pool); +int stackid( char *id, char *stack, int *ptr ); +int popid( char *id, char *stack, int *ptr ); +int poolsize( char *pool ); +int ebinop( int c ); +int efcall( int c ); +int eretsub( void ); +int ebranch( void ); +int echop( void ); +int eframe( void ); +int new_if( void ); +int else_part( void ); +void close_if( void ); +int new_while( void ); +int while_expr( void ); +int close_while( void ); +void decompile( struct instr *code ); +void printop( int op ); +void yyerror( char *s ); +int yywrap( void ); +void count( void ); +void allprint( void ); +void sprint( void ); + +void cpu_trace( char *f ); +void catch_int( void ); + +void comp( char **f, int n ); +void play( char **f, int n ); +void match( int m, long l, char **f, int n ); diff --git a/src/display.c b/src/display.c index 5f0bb01..d863492 100644 --- a/src/display.c +++ b/src/display.c @@ -16,7 +16,7 @@ /* update_disp - update all robots and missiles */ -update_disp() +void update_disp( void ) { register int i, j; @@ -48,9 +48,7 @@ update_disp() /* count_miss - update the explosion counter */ -count_miss(i,j) - -int i, j; +void count_miss( int i, int j ) { if (missiles[i][j].count <= 0) missiles[i][j].stat = AVAIL; diff --git a/src/grammar.c b/src/grammar.c index 53d3083..b15bf8b 100644 --- a/src/grammar.c +++ b/src/grammar.c @@ -802,28 +802,32 @@ case 1: #line 76 "grammar.y" { /* printf("IDENTIFIER\n"); */ if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { - if (findvar(last_ident,func_tab) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { + if (findvar(last_ident,func_tab) == -1) + { /* printf("\n***undeclared %s***\n",last_ident); */ undeclared++; } work = allocvar(last_ident,var_tab); } - else + } else + { work |= EXTERNAL; - if (!efetch(work)) - return(1); + } + if (!efetch(work)) return(1); } break; case 2: -#line 91 "grammar.y" +#line 95 "grammar.y" { /*printf("CONSTANT\n"); */ if (!econst(kk)) return(1); } break; case 5: -#line 101 "grammar.y" +#line 105 "grammar.y" { /* printf("FCALL\n"); */ popid(func_ident,func_stack,&func_off); /* note ptr to off */ if ((work = findvar(func_ident,func_tab)) == -1) { @@ -836,7 +840,7 @@ case 5: } break; case 6: -#line 112 "grammar.y" +#line 116 "grammar.y" { /* printf("FCALL\n"); */ popid(func_ident,func_stack,&func_off); /* note ptr to off */ if ((work = findvar(func_ident,func_tab)) == -1) { @@ -849,41 +853,50 @@ case 6: } break; case 7: -#line 123 "grammar.y" +#line 127 "grammar.y" { /* printf("POSTFIX-INC\n"); */ /* this is wrong! same as infix increment */ postfix++; if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else - work |= EXTERNAL; + } + else + { + work |= EXTERNAL; + } if(!estore(work,ADD_ASSIGN)) return(1); } break; case 8: -#line 138 "grammar.y" +#line 147 "grammar.y" { /* printf("POSTFIX-DEC\n"); */ /* this is wrong! same as infix decrement */ postfix++; if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,SUB_ASSIGN)) return(1); } break; case 9: -#line 156 "grammar.y" +#line 169 "grammar.y" { /* printf("FCALL-START\n"); */ stackid(last_ident,func_stack,&func_off); /* note ptr to off */ if (!eframe()) @@ -891,37 +904,45 @@ case 9: } break; case 13: -#line 171 "grammar.y" +#line 184 "grammar.y" { /* printf("INFIX-INC\n"); */ if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,ADD_ASSIGN)) return(1); } break; case 14: -#line 184 "grammar.y" +#line 201 "grammar.y" { /* printf("INFIX-DEC\n"); */ if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,SUB_ASSIGN)) return(1); } break; case 15: -#line 197 "grammar.y" +#line 218 "grammar.y" { /* printf("UNARY-OP\n"); */ /* note special tokens defined only to pass to interpreter */ un_op = *(op_stack + op_off); @@ -945,170 +966,174 @@ case 15: } break; case 16: -#line 222 "grammar.y" +#line 243 "grammar.y" { /* printf("UNARY-OP\n"); */ op_off++; *(op_stack + op_off) = '-'; } break; case 17: -#line 227 "grammar.y" +#line 248 "grammar.y" { op_off++; *(op_stack + op_off) = '!'; } break; case 18: -#line 232 "grammar.y" +#line 253 "grammar.y" { op_off++; *(op_stack + op_off) = '~'; } break; case 22: -#line 246 "grammar.y" +#line 267 "grammar.y" { /* printf("MULTIPLY\n"); */ if (!ebinop('*')) return(1); } break; case 23: -#line 251 "grammar.y" +#line 272 "grammar.y" { /*printf("DIVIDE\n"); */ if (!ebinop('/')) return(1); } break; case 24: -#line 256 "grammar.y" +#line 277 "grammar.y" { /* printf("MOD\n"); */ if (!ebinop('%')) return(1); } break; case 26: -#line 265 "grammar.y" +#line 286 "grammar.y" { /* printf("ADD\n"); */ if (!ebinop('+')) return(1); } break; case 27: -#line 270 "grammar.y" +#line 291 "grammar.y" { /* printf("SUBTRACT\n"); */ if (!ebinop('-')) return(1); } break; case 29: -#line 279 "grammar.y" +#line 300 "grammar.y" { /* printf("SHIFT-LEFT\n"); */ if (!ebinop(LEFT_OP)) return(1); } break; case 30: -#line 284 "grammar.y" +#line 305 "grammar.y" { /* printf("SHIFT-RIGHT\n"); */ if (!ebinop(RIGHT_OP)) return(1); } break; case 32: -#line 293 "grammar.y" +#line 314 "grammar.y" { /* printf("LESS-THAN\n"); */ if (!ebinop('<')) return(1); } break; case 33: -#line 298 "grammar.y" +#line 319 "grammar.y" { /* printf("GREATER-THAN\n"); */ if (!ebinop('>')) return(1); } break; case 34: -#line 303 "grammar.y" +#line 324 "grammar.y" { /*printf("LESS-EQUAL\n"); */ if (!ebinop(LE_OP)) return(1); } break; case 35: -#line 308 "grammar.y" +#line 329 "grammar.y" { /* printf("GREATER-EQUAL\n"); */ if (!ebinop(GE_OP)) return(1); } break; case 37: -#line 317 "grammar.y" +#line 338 "grammar.y" { /* printf("EQUAL\n"); */ if (!ebinop(EQ_OP)) return(1); } break; case 38: -#line 322 "grammar.y" +#line 343 "grammar.y" { /* printf("NOT-EQUAL\n"); */ if (!ebinop(NE_OP)) return(1); } break; case 40: -#line 331 "grammar.y" +#line 352 "grammar.y" { /* printf("AND\n"); */ if (!ebinop('&')) return(1); } break; case 42: -#line 340 "grammar.y" +#line 361 "grammar.y" { /* printf("EXCLUSIVE-OR\n"); */ if (!ebinop('^')) return(1); } break; case 44: -#line 349 "grammar.y" +#line 370 "grammar.y" { /* printf("INCLUSIVE-OR\n"); */ if (!ebinop('|')) return(1); } break; case 46: -#line 358 "grammar.y" +#line 379 "grammar.y" { /* printf("LOGICAL-AND\n"); */ if (!ebinop(AND_OP)) return(1); } break; case 48: -#line 367 "grammar.y" +#line 388 "grammar.y" { /* printf("LOGICAL-OR\n"); */ if (!ebinop(OR_OP)) return(1); } break; case 51: -#line 380 "grammar.y" +#line 401 "grammar.y" { /* printf("ASSIGNMENT\n"); */ /* func_ident used as temp storage */ popid(func_ident,var_stack,&var_off); /* note ptr to off */ if ((work = findvar(func_ident,var_tab)) == -1) - if ((work = findvar(func_ident,ext_tab)) == -1) { + { + if ((work = findvar(func_ident,ext_tab)) == -1) + { work = allocvar(func_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,*(op_stack + op_off))) return(1); op_off--; } break; case 52: -#line 397 "grammar.y" +#line 422 "grammar.y" { /* printf("ASSIGNMENT-LVAL\n"); */ stackid(last_ident,var_stack,&var_off); /* note ptr to off */ op_off++; @@ -1116,51 +1141,51 @@ case 52: } break; case 53: -#line 406 "grammar.y" +#line 431 "grammar.y" { work = '=';} break; case 54: -#line 408 "grammar.y" +#line 433 "grammar.y" { work = MUL_ASSIGN;} break; case 55: -#line 410 "grammar.y" +#line 435 "grammar.y" { work = DIV_ASSIGN;} break; case 56: -#line 412 "grammar.y" +#line 437 "grammar.y" { work = MOD_ASSIGN;} break; case 57: -#line 414 "grammar.y" +#line 439 "grammar.y" { work = ADD_ASSIGN;} break; case 58: -#line 416 "grammar.y" +#line 441 "grammar.y" { work = SUB_ASSIGN;} break; case 59: -#line 418 "grammar.y" +#line 443 "grammar.y" { work = LEFT_ASSIGN;} break; case 60: -#line 420 "grammar.y" +#line 445 "grammar.y" { work = RIGHT_ASSIGN;} break; case 61: -#line 422 "grammar.y" +#line 447 "grammar.y" { work = AND_ASSIGN;} break; case 62: -#line 424 "grammar.y" +#line 449 "grammar.y" { work = XOR_ASSIGN;} break; case 63: -#line 426 "grammar.y" +#line 451 "grammar.y" { work = OR_ASSIGN;} break; case 74: -#line 453 "grammar.y" +#line 478 "grammar.y" { /* printf("INITIALIZER\n"); */ fprintf(f_out,"\n**Warning** unsupported initializer\n"); /* get rid of constant placed on stack */ @@ -1169,7 +1194,7 @@ case 74: } break; case 81: -#line 478 "grammar.y" +#line 503 "grammar.y" { /* printf("VARIABLE-DECLARE\n"); */ if (in_func) { if (findvar(last_ident,var_tab) == -1) @@ -1182,86 +1207,86 @@ case 81: } break; case 82: -#line 489 "grammar.y" +#line 514 "grammar.y" { /* printf("FUNCTION-DECLARE\n"); */ if (new_func() == -1) return (1); /* exit the parser */ } break; case 83: -#line 494 "grammar.y" +#line 519 "grammar.y" { /* printf("FUNCTION-DECLARE\n"); */ if (new_func() == -1) return (1); /* exit the parser */ } break; case 84: -#line 502 "grammar.y" +#line 527 "grammar.y" { /* printf("FUNCTION-DEF-START\n"); */ strcpy(func_ident,last_ident); } break; case 87: -#line 514 "grammar.y" +#line 539 "grammar.y" { /* printf("PARAMETER-DECLARE\n"); */ allocvar(last_ident,var_tab); num_parm++; } break; case 122: -#line 595 "grammar.y" +#line 620 "grammar.y" { /* printf("CHOP\n"); */ if (!echop()) return(1); } break; case 125: -#line 608 "grammar.y" +#line 633 "grammar.y" { /* printf("IF-THEN\n"); */ else_part(); close_if(); } break; case 126: -#line 616 "grammar.y" +#line 641 "grammar.y" { /* printf("IF-THEN-ELSE\n"); */ close_if(); } break; case 127: -#line 623 "grammar.y" +#line 648 "grammar.y" { /* printf("IF-CLAUSE\n"); */ if (!new_if()) return (1); /* exit parser */ } break; case 128: -#line 631 "grammar.y" +#line 656 "grammar.y" { /* printf("ELSE-CLAUSE\n"); */ else_part(); } break; case 129: -#line 638 "grammar.y" +#line 663 "grammar.y" { /* printf("WHILE\n"); */ close_while(); } break; case 130: -#line 645 "grammar.y" +#line 670 "grammar.y" { /* printf("WHILE-TOKEN\n"); */ if (!new_while()) return (1); /* exit the parser */ } break; case 131: -#line 653 "grammar.y" +#line 678 "grammar.y" { /* printf("WHILE-CLAUSE\n"); */ while_expr(); } break; case 132: -#line 660 "grammar.y" +#line 685 "grammar.y" { /* printf("BREAK\n"); */ /* breaks can be handled by building a instruct chain */ /* as part of the while_nest structures and patching them */ @@ -1270,7 +1295,7 @@ case 132: } break; case 133: -#line 667 "grammar.y" +#line 692 "grammar.y" { /* printf("RETURN-NOEXPR\n"); */ /* all functions must return a value */ if (!econst(1L)) @@ -1280,14 +1305,14 @@ case 133: } break; case 134: -#line 675 "grammar.y" +#line 700 "grammar.y" { /* printf("RETURN\n"); */ if (!eretsub()) return(1); } break; case 137: -#line 688 "grammar.y" +#line 713 "grammar.y" { /* printf("FUNCTION-DEFINITION\n"); */ /* all functions must return a value */ if (!econst(1L)) @@ -1298,11 +1323,11 @@ case 137: } break; case 138: -#line 697 "grammar.y" +#line 722 "grammar.y" { /* printf("EXTERNAL-DECLARE\n"); */ } break; -#line 1306 "y.tab.c" +#line 1331 "y.tab.c" } yyssp -= yym; yystate = *yyssp; diff --git a/src/grammar.y b/src/grammar.y index cfc27f8..25708df 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -75,17 +75,21 @@ primary_expr : identifier { /* printf("IDENTIFIER\n"); */ if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { - if (findvar(last_ident,func_tab) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { + if (findvar(last_ident,func_tab) == -1) + { /* printf("\n***undeclared %s***\n",last_ident); */ undeclared++; } work = allocvar(last_ident,var_tab); } - else + } else + { work |= EXTERNAL; - if (!efetch(work)) - return(1); + } + if (!efetch(work)) return(1); } | CONSTANT { /*printf("CONSTANT\n"); */ @@ -126,11 +130,16 @@ postfix_expr if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else - work |= EXTERNAL; + } + else + { + work |= EXTERNAL; + } if(!estore(work,ADD_ASSIGN)) return(1); } @@ -141,11 +150,15 @@ postfix_expr if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,SUB_ASSIGN)) return(1); } @@ -172,11 +185,15 @@ unary_expr if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,ADD_ASSIGN)) return(1); } @@ -185,11 +202,15 @@ unary_expr if (!econst(1L)) return(1); if ((work = findvar(last_ident,var_tab)) == -1) - if ((work = findvar(last_ident,ext_tab)) == -1) { + { + if ((work = findvar(last_ident,ext_tab)) == -1) + { work = allocvar(last_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,SUB_ASSIGN)) return(1); } @@ -381,11 +402,15 @@ assignment_expr /* func_ident used as temp storage */ popid(func_ident,var_stack,&var_off); /* note ptr to off */ if ((work = findvar(func_ident,var_tab)) == -1) - if ((work = findvar(func_ident,ext_tab)) == -1) { + { + if ((work = findvar(func_ident,ext_tab)) == -1) + { work = allocvar(func_ident,var_tab); } - else + }else + { work |= EXTERNAL; + } if (!estore(work,*(op_stack + op_off))) return(1); op_off--; diff --git a/src/intrins.c b/src/intrins.c index ba6b901..8621d6a 100644 --- a/src/intrins.c +++ b/src/intrins.c @@ -33,7 +33,7 @@ extern long pop(); /* c_scan - radar scanning function - note degrees instead of radians */ /* expects two agruments on stack, degree and resoultion */ -long c_scan() +void c_scan( void ) { register int i; long degree; @@ -117,7 +117,7 @@ long c_scan() /* c_cannon - fire a shot */ /* expects two agruments on stack, degree distance */ -long c_cannon() +void c_cannon( void ) { long degree; long distance; @@ -182,7 +182,7 @@ long c_cannon() /* c_drive - start the propulsion system */ /* expect two agruments, degrees & speed */ -long c_drive() +void c_drive( void ) { long degree; long speed; @@ -212,7 +212,7 @@ long c_drive() /* c_damage - report on damage sustained */ -long c_damage() +void c_damage( void ) { push((long) cur_robot->damage); } @@ -220,7 +220,7 @@ long c_damage() /* c_speed - report current speed */ -long c_speed() +void c_speed( void ) { push((long) cur_robot->speed); } @@ -228,7 +228,7 @@ long c_speed() /* c_loc_x - report current x location */ -long c_loc_x() +void c_loc_x( void ) { push((long) cur_robot->x / CLICK); } @@ -236,9 +236,8 @@ long c_loc_x() /* c_loc_y - report current y location */ -long c_loc_y() +void c_loc_y( void ) { - int y; push((long) cur_robot->y / CLICK); } @@ -246,7 +245,7 @@ long c_loc_y() /* c_rand - return a random number between 0 and limit */ /* expect one argument, limit */ -long c_rand() +void c_rand( void ) { int rand(); /* int srand(); */ /* should be seeded elsewhere */ @@ -264,7 +263,7 @@ long c_rand() /* c_sin - return sin(degrees) * SCALE */ /* expect one agrument, degrees */ -long c_sin() +void c_sin( void ) { long degree; long lsin(); @@ -279,7 +278,7 @@ long c_sin() /* c_cos - return cos(degrees) * SCALE */ /* expect one agrument, degrees */ -long c_cos() +void c_cos( void ) { long degree; long lcos(); @@ -294,7 +293,7 @@ long c_cos() /* c_tan - return tan(degrees) * SCALE */ /* expect one agrument, degrees */ -long c_tan() +void c_tan( void ) { long degree; @@ -308,7 +307,7 @@ long c_tan() /* c_atan - return atan(x) */ /* expect one agrument, ratio * SCALE */ -long c_atan() +void c_atan( void ) { long degree; long ratio; @@ -323,7 +322,7 @@ long c_atan() /* c_sqrt - return sqrt(x) */ /* expect one agrument, x */ -long c_sqrt() +void c_sqrt( void ) { long x; diff --git a/src/lexanal.c b/src/lexanal.c index 69856c4..53d7d87 100644 --- a/src/lexanal.c +++ b/src/lexanal.c @@ -536,10 +536,9 @@ char *yytext; #define ECHO fprintf(f_out,"%s",yytext) long atol(); -int count(); -#line 543 "lex.yy.c" +#line 542 "lex.yy.c" #define INITIAL 0 #define C_COMMENT 1 @@ -722,9 +721,9 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 34 "lexanal.l" +#line 33 "lexanal.l" -#line 728 "lex.yy.c" +#line 727 "lex.yy.c" if ( !(yy_init) ) { @@ -809,77 +808,77 @@ YY_DECL case 1: YY_RULE_SETUP -#line 35 "lexanal.l" +#line 34 "lexanal.l" { BEGIN(C_COMMENT); } YY_BREAK case 2: YY_RULE_SETUP -#line 36 "lexanal.l" +#line 35 "lexanal.l" { BEGIN(INITIAL); } YY_BREAK case 3: YY_RULE_SETUP -#line 37 "lexanal.l" +#line 36 "lexanal.l" { } YY_BREAK case 4: YY_RULE_SETUP -#line 40 "lexanal.l" +#line 39 "lexanal.l" { count(); return(AUTO); } YY_BREAK case 5: YY_RULE_SETUP -#line 41 "lexanal.l" +#line 40 "lexanal.l" { count(); return(BREAK); } YY_BREAK case 6: YY_RULE_SETUP -#line 42 "lexanal.l" +#line 41 "lexanal.l" { count(); return(ELSE); } YY_BREAK case 7: YY_RULE_SETUP -#line 43 "lexanal.l" +#line 42 "lexanal.l" { count(); return(EXTERN); } YY_BREAK case 8: YY_RULE_SETUP -#line 44 "lexanal.l" +#line 43 "lexanal.l" { count(); return(FOR); } YY_BREAK case 9: YY_RULE_SETUP -#line 45 "lexanal.l" +#line 44 "lexanal.l" { count(); return(IF); } YY_BREAK case 10: YY_RULE_SETUP -#line 46 "lexanal.l" +#line 45 "lexanal.l" { count(); return(INT); } YY_BREAK case 11: YY_RULE_SETUP -#line 47 "lexanal.l" +#line 46 "lexanal.l" { count(); return(LONG); } YY_BREAK case 12: YY_RULE_SETUP -#line 48 "lexanal.l" +#line 47 "lexanal.l" { count(); return(REGISTER); } YY_BREAK case 13: YY_RULE_SETUP -#line 49 "lexanal.l" +#line 48 "lexanal.l" { count(); return(RETURN); } YY_BREAK case 14: YY_RULE_SETUP -#line 50 "lexanal.l" +#line 49 "lexanal.l" { count(); return(WHILE); } YY_BREAK case 15: YY_RULE_SETUP -#line 52 "lexanal.l" +#line 51 "lexanal.l" { count(); strncpy(last_ident,yytext,ILEN-1); last_ident[ILEN-1] = '\0'; @@ -887,228 +886,228 @@ YY_RULE_SETUP YY_BREAK case 16: YY_RULE_SETUP -#line 57 "lexanal.l" +#line 56 "lexanal.l" { count(); kk = atol(yytext); return(CONSTANT); } YY_BREAK case 17: YY_RULE_SETUP -#line 61 "lexanal.l" +#line 60 "lexanal.l" { count(); return(RIGHT_ASSIGN); } YY_BREAK case 18: YY_RULE_SETUP -#line 62 "lexanal.l" +#line 61 "lexanal.l" { count(); return(LEFT_ASSIGN); } YY_BREAK case 19: YY_RULE_SETUP -#line 63 "lexanal.l" +#line 62 "lexanal.l" { count(); return(ADD_ASSIGN); } YY_BREAK case 20: YY_RULE_SETUP -#line 64 "lexanal.l" +#line 63 "lexanal.l" { count(); return(SUB_ASSIGN); } YY_BREAK case 21: YY_RULE_SETUP -#line 65 "lexanal.l" +#line 64 "lexanal.l" { count(); return(MUL_ASSIGN); } YY_BREAK case 22: YY_RULE_SETUP -#line 66 "lexanal.l" +#line 65 "lexanal.l" { count(); return(DIV_ASSIGN); } YY_BREAK case 23: YY_RULE_SETUP -#line 67 "lexanal.l" +#line 66 "lexanal.l" { count(); return(MOD_ASSIGN); } YY_BREAK case 24: YY_RULE_SETUP -#line 68 "lexanal.l" +#line 67 "lexanal.l" { count(); return(AND_ASSIGN); } YY_BREAK case 25: YY_RULE_SETUP -#line 69 "lexanal.l" +#line 68 "lexanal.l" { count(); return(XOR_ASSIGN); } YY_BREAK case 26: YY_RULE_SETUP -#line 70 "lexanal.l" +#line 69 "lexanal.l" { count(); return(OR_ASSIGN); } YY_BREAK case 27: YY_RULE_SETUP -#line 71 "lexanal.l" +#line 70 "lexanal.l" { count(); return(RIGHT_OP); } YY_BREAK case 28: YY_RULE_SETUP -#line 72 "lexanal.l" +#line 71 "lexanal.l" { count(); return(LEFT_OP); } YY_BREAK case 29: YY_RULE_SETUP -#line 73 "lexanal.l" +#line 72 "lexanal.l" { count(); return(INC_OP); } YY_BREAK case 30: YY_RULE_SETUP -#line 74 "lexanal.l" +#line 73 "lexanal.l" { count(); return(DEC_OP); } YY_BREAK case 31: YY_RULE_SETUP -#line 75 "lexanal.l" +#line 74 "lexanal.l" { count(); return(AND_OP); } YY_BREAK case 32: YY_RULE_SETUP -#line 76 "lexanal.l" +#line 75 "lexanal.l" { count(); return(OR_OP); } YY_BREAK case 33: YY_RULE_SETUP -#line 77 "lexanal.l" +#line 76 "lexanal.l" { count(); return(LE_OP); } YY_BREAK case 34: YY_RULE_SETUP -#line 78 "lexanal.l" +#line 77 "lexanal.l" { count(); return(GE_OP); } YY_BREAK case 35: YY_RULE_SETUP -#line 79 "lexanal.l" +#line 78 "lexanal.l" { count(); return(EQ_OP); } YY_BREAK case 36: YY_RULE_SETUP -#line 80 "lexanal.l" +#line 79 "lexanal.l" { count(); return(NE_OP); } YY_BREAK case 37: YY_RULE_SETUP -#line 81 "lexanal.l" +#line 80 "lexanal.l" { count(); return(';'); } YY_BREAK case 38: YY_RULE_SETUP -#line 82 "lexanal.l" +#line 81 "lexanal.l" { count(); return('{'); } YY_BREAK case 39: YY_RULE_SETUP -#line 83 "lexanal.l" +#line 82 "lexanal.l" { count(); return('}'); } YY_BREAK case 40: YY_RULE_SETUP -#line 84 "lexanal.l" +#line 83 "lexanal.l" { count(); return(','); } YY_BREAK case 41: YY_RULE_SETUP -#line 85 "lexanal.l" +#line 84 "lexanal.l" { count(); return('='); } YY_BREAK case 42: YY_RULE_SETUP -#line 86 "lexanal.l" +#line 85 "lexanal.l" { count(); return('('); } YY_BREAK case 43: YY_RULE_SETUP -#line 87 "lexanal.l" +#line 86 "lexanal.l" { count(); return(')'); } YY_BREAK case 44: YY_RULE_SETUP -#line 88 "lexanal.l" +#line 87 "lexanal.l" { count(); return('.'); } YY_BREAK case 45: YY_RULE_SETUP -#line 89 "lexanal.l" +#line 88 "lexanal.l" { count(); return('&'); } YY_BREAK case 46: YY_RULE_SETUP -#line 90 "lexanal.l" +#line 89 "lexanal.l" { count(); return('!'); } YY_BREAK case 47: YY_RULE_SETUP -#line 91 "lexanal.l" +#line 90 "lexanal.l" { count(); return('~'); } YY_BREAK case 48: YY_RULE_SETUP -#line 92 "lexanal.l" +#line 91 "lexanal.l" { count(); return('-'); } YY_BREAK case 49: YY_RULE_SETUP -#line 93 "lexanal.l" +#line 92 "lexanal.l" { count(); return('+'); } YY_BREAK case 50: YY_RULE_SETUP -#line 94 "lexanal.l" +#line 93 "lexanal.l" { count(); return('*'); } YY_BREAK case 51: YY_RULE_SETUP -#line 95 "lexanal.l" +#line 94 "lexanal.l" { count(); return('/'); } YY_BREAK case 52: YY_RULE_SETUP -#line 96 "lexanal.l" +#line 95 "lexanal.l" { count(); return('%'); } YY_BREAK case 53: YY_RULE_SETUP -#line 97 "lexanal.l" +#line 96 "lexanal.l" { count(); return('<'); } YY_BREAK case 54: YY_RULE_SETUP -#line 98 "lexanal.l" +#line 97 "lexanal.l" { count(); return('>'); } YY_BREAK case 55: YY_RULE_SETUP -#line 99 "lexanal.l" +#line 98 "lexanal.l" { count(); return('^'); } YY_BREAK case 56: YY_RULE_SETUP -#line 100 "lexanal.l" +#line 99 "lexanal.l" { count(); return('|'); } YY_BREAK case 57: /* rule 57 can match eol */ YY_RULE_SETUP -#line 102 "lexanal.l" +#line 101 "lexanal.l" { count(); } YY_BREAK case 58: YY_RULE_SETUP -#line 103 "lexanal.l" +#line 102 "lexanal.l" { /* ignore bad characters */ } YY_BREAK case 59: YY_RULE_SETUP -#line 105 "lexanal.l" +#line 104 "lexanal.l" ECHO; YY_BREAK -#line 1112 "lex.yy.c" +#line 1111 "lex.yy.c" case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(C_COMMENT): yyterminate(); @@ -2107,18 +2106,16 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 105 "lexanal.l" +#line 104 "lexanal.l" -yywrap() +int yywrap(void ) { return(1); } - - -count() +void count( void ) { int i; @@ -2133,13 +2130,8 @@ count() ECHO; } - -/* the i/o routines depend on f_in and f_out to be opened elsewhere */ - - /* these two dummy routines for lex's debug options */ -allprint() {} - -sprint() {} +void allprint( void ) {} +void sprint( void ) {} diff --git a/src/lexanal.h b/src/lexanal.h index f2b0322..f415de9 100644 --- a/src/lexanal.h +++ b/src/lexanal.h @@ -309,7 +309,7 @@ extern int yylex (void); #undef YY_DECL #endif -#line 105 "lexanal.l" +#line 104 "lexanal.l" #line 316 "lexanal.h" diff --git a/src/lexanal.l b/src/lexanal.l index 0013fd1..5af0ad2 100644 --- a/src/lexanal.l +++ b/src/lexanal.l @@ -24,7 +24,6 @@ L [a-zA-Z_] #define ECHO fprintf(f_out,"%s",yytext) long atol(); -int count(); %} @@ -104,14 +103,12 @@ int count(); %% -yywrap() +int yywrap( void ) { return(1); } - - -count() +void count( void ) { int i; @@ -126,12 +123,7 @@ count() ECHO; } - -/* the i/o routines depend on f_in and f_out to be opened elsewhere */ - - /* these two dummy routines for lex's debug options */ -allprint() {} - -sprint() {} +void allprint( void ) {} +void sprint( void ) {} diff --git a/src/main.c b/src/main.c index 13c1c7e..0b179f9 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,6 @@ #ifdef UNIX #include -extern int catch_int(); #endif #ifdef LATTICE int _stack = 6000; /* Lattice C: give more stack than default of 2048 */ @@ -34,9 +33,7 @@ char *version = "CROBOTS - version 1.1, December, 1985\n"; char *copyright = "Copyright 1985 by Tom Poindexter, All rights reserved.\n"; -main(argc,argv) -int argc; -char *argv[]; +int main( int argc, char **argv ) { long limit = CYCLE_LIMIT; int matches = 0; @@ -54,7 +51,7 @@ char *argv[]; /* bj no longer needed */ /* int srand(); */ - + /* print version, copyright notice, GPL notice */ fprintf(stderr,"\n"); @@ -157,7 +154,7 @@ char *argv[]; /* debug the first robot listed */ if (debug_only) { - trace(files[0]); /* trace only first source */ + cpu_trace(files[0]); /* trace only first source */ } else @@ -190,11 +187,7 @@ char *argv[]; /* comp - only compile the files with full info */ - -comp(f,n) - -char *f[]; -int n; +void comp( char **f, int n ) { int i; @@ -229,10 +222,7 @@ int n; /* play - watch the robots compete */ -play(f,n) - -char *f[]; -int n; +void play( char **f, int n ) { int num_robots = 0; int robotsleft; @@ -290,8 +280,8 @@ int n; #ifdef UNIX /* catch interrupt */ - if (signal(SIGINT,SIG_IGN) != SIG_IGN) - signal(SIGINT,catch_int); +/* if (signal(SIGINT,SIG_IGN) != SIG_IGN) + signal(SIGINT,catch_int); */ #endif rand_pos(num_robots); @@ -371,12 +361,7 @@ int n; /* match - run a series of matches */ -match(m,l,f,n) - -int m; -long l; -char *f[]; -int n; +void match( int m, long l, char **f, int n ) { int num_robots = 0; int robotsleft; @@ -545,9 +530,7 @@ int n; /* dependent on MAXROBOTS <= 4 */ /* put robots in separate quadrant */ -rand_pos(n) - -int n; +void rand_pos( int n ) { int i, k; int quad[4]; @@ -568,20 +551,15 @@ int n; } quad[k] = 1; } - robots[i].org_x = robots[i].x = - (rand() % (MAX_X * CLICK / 2)) + ((MAX_X * CLICK / 2) * (k%2)); - robots[i].org_y = robots[i].y = - (rand() % (MAX_Y * CLICK / 2)) + ((MAX_Y * CLICK / 2) * (k<2)); + robots[i].org_x = robots[i].x = (rand() % (MAX_X * CLICK / 2)) + ((MAX_X * CLICK / 2) * (k%2)); + robots[i].org_y = robots[i].y = (rand() % (MAX_Y * CLICK / 2)) + ((MAX_Y * CLICK / 2) * (k<2)); } } /* trace - compile and run the robot in debug mode */ - -trace(f) - -char *f; +void cpu_trace( char *f ) { int c = 1; @@ -605,8 +583,8 @@ char *f; robot_go(&robots[0]); /* randomly place robot */ - robots[0].x = rand() % MAX_X * 100; - robots[0].y = rand() % MAX_Y * 100; + robots[0].x = rand() % MAX_X * CLICK; + robots[0].y = rand() % MAX_Y * CLICK; /* setup a dummy robot at the center */ robots[1].x = MAX_X / 2 * 100; @@ -700,7 +678,7 @@ int i; #ifdef UNIX /* catch_int - catch the interrupt signal and die, cleaning screen */ -catch_int() +void catch_int( void ) { int i; /* diff --git a/src/motion.c b/src/motion.c index 0af9049..0148337 100644 --- a/src/motion.c +++ b/src/motion.c @@ -182,8 +182,7 @@ struct { /* move_robots - update the postion of all robots */ /* parm 'displ' controls call to field display */ -move_robots(displ) -int displ; +void move_robots(int displ) { register int i, n; long lsin(), lcos(); @@ -235,10 +234,9 @@ int displ; /* update distance traveled on this heading, x & y */ if (robots[i].speed > 0) { robots[i].range += (robots[i].speed / CLICK) * ROBOT_SPEED; - robots[i].x = (int) (robots[i].org_x + (int) - (lcos(robots[i].heading) * (long)(robots[i].range/CLICK) / 10000L)); - robots[i].y = (int) (robots[i].org_y + (int) - (lsin(robots[i].heading) * (long)(robots[i].range/CLICK) / 10000L)); + /* BJ CHECK THIS OUT! */ + robots[i].x = (int) (robots[i].org_x + (int)(lcos(robots[i].heading) * (long)(robots[i].range/CLICK) / 10000L)); + robots[i].y = (int) (robots[i].org_y + (int)(lsin(robots[i].heading) * (long)(robots[i].range/CLICK) / 10000L)); /* check for collision into another robot, less than 1 meter apart */ for (n = 0; n < MAXROBOTS; n++) { @@ -293,8 +291,7 @@ int displ; /* move_miss - updates all missile positions */ /* parm 'displ' control display */ -move_miss(displ) -int displ; +void move_miss(int displ) { register int r, i; int n, j; diff --git a/src/screen.c b/src/screen.c index 997abe7..35c0716 100644 --- a/src/screen.c +++ b/src/screen.c @@ -60,7 +60,7 @@ static int col_3; /* column for cpu cycle count*/ /* init_disp - initialize display */ -init_disp() +void init_disp( void ) { initscr(); clear(); @@ -73,7 +73,7 @@ init_disp() /* end_disp - cleanup and end display */ -end_disp() +void end_disp( void ) { nocrmode(); echo(); @@ -85,7 +85,7 @@ end_disp() /* draw_field - draws the playing field and status boxes */ -draw_field() +void draw_field( void ) { int i, j; @@ -152,9 +152,7 @@ draw_field() /* plot_robot - plot the robot position */ -plot_robot(n) - -int n; +void plot_robot( int n ) { int i, k; register int new_x, new_y; @@ -194,10 +192,7 @@ int n; /* plot_miss - plot the missile position */ -plot_miss(r,n) - -int r; -int n; +void plot_miss( int r, int n) { int i, k; register int new_x, new_y; @@ -242,10 +237,7 @@ int n; /* plot_exp - plot the missile exploding */ -plot_exp(r,n) - -int r; -int n; +void plot_exp(int r, int n) { int c, i, p, hold_x, hold_y, k; register int new_x, new_y; @@ -312,9 +304,7 @@ int n; /* robot_stat - update status info */ -robot_stat(n) - -int n; +void robot_stat( int n ) { int changed = 0; @@ -355,9 +345,7 @@ int n; } -show_cycle(l) - -long l; +void show_cycle( long l ) { move(LINES-1,col_3); printw("%7ld",l); diff --git a/src/screena.c b/src/screena.c index b1fea1d..3dd91c4 100644 --- a/src/screena.c +++ b/src/screena.c @@ -334,9 +334,7 @@ int n; /* robot_stat - update status info */ -robot_stat(n) - -int n; +void robot_stat( int n ) { int changed = 0; diff --git a/src/screend.c b/src/screend.c index 6471965..cd43dd3 100644 --- a/src/screend.c +++ b/src/screend.c @@ -369,9 +369,7 @@ int n; /* robot_stat - update status info */ -robot_stat(n) - -int n; +void robot_stat( int n ) { int changed = 0;