From 100832ec16c4cb7c4dc50e0e8946f72b6fca4c05 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Sat, 13 Jul 2019 14:05:19 -0400 Subject: Replace pc.c with mypc.c pc.c is written over by bison. --- mypc.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pc.c | 121 ---------------------------------------------------------- 2 files changed, 134 insertions(+), 121 deletions(-) create mode 100644 mypc.c delete mode 100644 pc.c diff --git a/mypc.c b/mypc.c new file mode 100644 index 0000000..e8deeb1 --- /dev/null +++ b/mypc.c @@ -0,0 +1,134 @@ +#include +#include +#include + +#include "y.tab.h" +#include "pc.h" + +extern char *yytext; +extern int line_num; + +char* pretty_type(t) +int t; +{ + if (t == ARRAY) { + return "ARRAY"; + } else if (t == INT - ARRAY) { + return "ARRAY of INT"; + } else if (t == INT - ARRAY) { + return "ARRAY of INT"; + } else if (t == INT) { + return "INT"; + } else if (t == REAL) { + return "REAL"; + } else if (t == BOOL) { + return "BOOL"; + } else if (t == -1) { + return "NO TYPE"; + } else { + return "Unknown type"; + } +} + +void debug_print(d, y) +int d; +union YYSTYPE* y; +{ +#ifdef DEBUG + if (d == PROG){ + fprintf(stderr, "[PROG]"); + } else if (d == VAR){ + fprintf(stderr, "[VAR]"); + } else if (d == PROC){ + fprintf(stderr, "[PROC]"); + } else if (d == FUNC){ + fprintf(stderr, "[FUNC]"); + } else if (d == BEG){ + fprintf(stderr, "[BEG]"); + } else if (d == END){ + fprintf(stderr, "[END]"); + } else if (d == ARRAY){ + fprintf(stderr, "[ARRAY]"); + } else if (d == OF){ + fprintf(stderr, "[OF]"); + } else if (d == INT){ + fprintf(stderr, "[INT]"); + } else if (d == REAL){ + fprintf(stderr, "[REAL]"); + } else if (d == IF){ + fprintf(stderr, "[IF]"); + } else if (d == THEN){ + fprintf(stderr, "[THEN]"); + } else if (d == ELSE){ + fprintf(stderr, "[ELSE]"); + } else if (d == WHILE){ + fprintf(stderr, "[WHILE]"); + } else if (d == DO){ + fprintf(stderr, "[DO]"); + } else if (d == NOT){ + fprintf(stderr, "[NOT]"); + } else if (d == DOTS){ + fprintf(stderr, "[ .. ]"); + } else if (d == ASSIGNOP){ + fprintf(stderr, "[ASSIGN]"); + } else if (d == RELOP){ + fprintf(stderr, "[RELOP:"); + if (y->opval == EQ){ + fprintf(stderr, "EQ"); + } else if (y->opval == NE){ + fprintf(stderr, "NE"); + } else if (y->opval == LT){ + fprintf(stderr, "LT"); + } else if (y->opval == LE){ + fprintf(stderr, "LE"); + } else if (y->opval == GT){ + fprintf(stderr, "GT"); + } else if (y->opval == GE){ + fprintf(stderr, "GE"); + } else if (y->opval == ADD){ + fprintf(stderr, "ADD"); + } else if (y->opval == SUB){ + fprintf(stderr, "SUB"); + } else if (y->opval == OR){ + fprintf(stderr, "OR"); + } else if (y->opval == MUL){ + fprintf(stderr, "MUL"); + } else if (y->opval == DIV){ + fprintf(stderr, "DIV"); + } else if (y->opval == AND){ + fprintf(stderr, "AND"); + } + fprintf(stderr,"]"); + } else if (d == INUM) { + fprintf(stderr, "[INUM: %d]", y->ival); + } else if (d == RNUM) { + fprintf(stderr, "[INUM: %f]", y->rval); + } else if (d == ID) { + fprintf(stderr, "[ID: %s]", y->sval); + } else if (d == '\n') { + fprintf(stderr, "\n"); + } else { + fprintf(stderr, "{%c}", d); + } + fprintf(stderr, " "); +#endif + return; +} + +int yyerror(msg) +char* msg; +{ + fprintf(stderr, "\nError, line %d: %s\n", line_num, msg); +#ifdef DEBUG + fprintf(stderr, "%s\n", yytext); + exit(1); +#endif + return 0; +} + +int main() +{ + yyparse(); + + return 0; +} diff --git a/pc.c b/pc.c deleted file mode 100644 index 19a7767..0000000 --- a/pc.c +++ /dev/null @@ -1,121 +0,0 @@ -#include -#include -#include - -char* pretty_type(t) -int t; -{ - if (t == ARRAY) { - return "ARRAY"; - } else if (t == INT - ARRAY) { - return "ARRAY of INT"; - } else if (t == INT - ARRAY) { - return "ARRAY of INT"; - } else if (t == INT) { - return "INT"; - } else if (t == REAL) { - return "REAL"; - } else if (t == BOOL) { - return "BOOL"; - } else if (t == -1) { - return "NO TYPE"; - } else { - return "Unknown type"; - } -} - -void debug_print(d, y) -int d; -union YYSTYPE* y; -{ -#ifdef DEBUG - if (d == PROG){ - fprintf(stderr, "[PROG]"); - } else if (d == VAR){ - fprintf(stderr, "[VAR]"); - } else if (d == PROC){ - fprintf(stderr, "[PROC]"); - } else if (d == FUNC){ - fprintf(stderr, "[FUNC]"); - } else if (d == BEG){ - fprintf(stderr, "[BEG]"); - } else if (d == END){ - fprintf(stderr, "[END]"); - } else if (d == ARRAY){ - fprintf(stderr, "[ARRAY]"); - } else if (d == OF){ - fprintf(stderr, "[OF]"); - } else if (d == INT){ - fprintf(stderr, "[INT]"); - } else if (d == REAL){ - fprintf(stderr, "[REAL]"); - } else if (d == IF){ - fprintf(stderr, "[IF]"); - } else if (d == THEN){ - fprintf(stderr, "[THEN]"); - } else if (d == ELSE){ - fprintf(stderr, "[ELSE]"); - } else if (d == WHILE){ - fprintf(stderr, "[WHILE]"); - } else if (d == DO){ - fprintf(stderr, "[DO]"); - } else if (d == NOT){ - fprintf(stderr, "[NOT]"); - } else if (d == DOTS){ - fprintf(stderr, "[ .. ]"); - } else if (d == ASSIGNOP){ - fprintf(stderr, "[ASSIGN]"); - } else if (d == RELOP){ - fprintf(stderr, "[RELOP:"); - if (y->opval == EQ){ - fprintf(stderr, "EQ"); - } else if (y->opval == NE){ - fprintf(stderr, "NE"); - } else if (y->opval == LT){ - fprintf(stderr, "LT"); - } else if (y->opval == LE){ - fprintf(stderr, "LE"); - } else if (y->opval == GT){ - fprintf(stderr, "GT"); - } else if (y->opval == GE){ - fprintf(stderr, "GE"); - } else if (y->opval == ADD){ - fprintf(stderr, "ADD"); - } else if (y->opval == SUB){ - fprintf(stderr, "SUB"); - } else if (y->opval == OR){ - fprintf(stderr, "OR"); - } else if (y->opval == MUL){ - fprintf(stderr, "MUL"); - } else if (y->opval == DIV){ - fprintf(stderr, "DIV"); - } else if (y->opval == AND){ - fprintf(stderr, "AND"); - } - fprintf(stderr,"]"); - } else if (d == INUM) { - fprintf(stderr, "[INUM: %d]", y->ival); - } else if (d == RNUM) { - fprintf(stderr, "[INUM: %f]", y->rval); - } else if (d == ID) { - fprintf(stderr, "[ID: %s]", y->sval); - } else if (d == '\n') { - fprintf(stderr, "\n"); - } else { - fprintf(stderr, "{%c}", d); - } - fprintf(stderr, " "); -#endif - return; -} - -int yyerror(msg) -char* msg; -{ - fprintf(stderr, "\nError, line %d: %s\n", line_num, msg); -#ifdef DEBUG - fprintf(stderr, "%s\n", yytext); - exit(1); -#endif - return 0; -} -- cgit v1.1