diff --git a/Makefile b/Makefile index 4b92e65..0f7f411 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ debug: clean compiler test: chmod +x ./check.sh chmod +x ./test.sh - $(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) -debug || true);) + $(foreach test, $(TESTS-S1), (./$(EXE) -tok -debug $(test) || true);) ./test.sh sp2 ./test.sh sp3 ./test.sh sp4 @@ -46,7 +46,7 @@ test: test-s1: chmod +x ./check.sh chmod +x ./test.sh - $(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) -debug || true);) + $(foreach test, $(TESTS-S1), (./$(EXE) -tok -debug $(test) || true);) ./check.sh sp1 test-s2: diff --git a/src/runner.c b/src/runner.c index 578fa22..3fdb399 100644 --- a/src/runner.c +++ b/src/runner.c @@ -6,10 +6,10 @@ int main(int argc, char *argv[]) { // if last argument is debug then set to true and ignore it for the rest // of this file - if (argc > 1 && strcmp(argv[argc - 1], "-debug") == 0) { - DEBUG = true; - argc--; - } + //if (argc > 1 && strcmp(argv[argc - 1], "-debug") == 0) { + // DEBUG = true; + // argc--; + // } if (argc == 1) { fprintf(stderr, INVALID); @@ -61,6 +61,14 @@ int check_flag(char *arg, char *alpha) { } fprintf(stderr, "FLAGS REPEAT\n"); return -1; + + } else if (strcmp("-tc", arg) == 0) { + if (tc_flag == NULL) { + return new_file(arg, alpha); + } + } else if (strcmp("-debug", arg) == 0) { + DEBUG = true; + return 0; } else { fprintf(stderr, "INVALID FLAG: Use -help for valid inputs\n"); return -1; @@ -151,6 +159,10 @@ int run(FILE *alpha) { return 0; } + if (tc_flag != NULL) { + //SCARLETT NEEDS TO ADD THIS FUNCTIONALITY + } + yyparse(); FILE *f = fdopen(1, "w"); @@ -194,7 +206,9 @@ int new_file(char *arg, char *alpha) { type_len = TOK_LEN; } else if (strcmp(arg, "-st") == 0) { type_len = ST_LEN; - } else { + } else if (strcmp(arg, "-tc") == 0){ + type_len = TC_LEN; + }else { fprintf(stderr, "INVALID FLAG: Use -help to view valid inputs\n"); return -1; @@ -214,6 +228,9 @@ int new_file(char *arg, char *alpha) { tok_flag = fopen(file_name, "w"); } else if (strcmp(arg, "-st") == 0) { st_flag = fopen(file_name, "w"); + + } else if (strcmp(arg, "-tc") == 0) { + tc_flag = fopen(file_name, "w"); } return 0; } @@ -224,4 +241,4 @@ int is_alpha_file(char *alpha, int file_len) { return -1; // not alpha file } return 0; // is alpha file -} \ No newline at end of file +} diff --git a/src/runner.h b/src/runner.h index cc573c5..0483e12 100644 --- a/src/runner.h +++ b/src/runner.h @@ -4,16 +4,18 @@ #define ALPHA_OFFSET 6 #define TOK_LEN 3 #define ST_LEN 2 +#define TC_LEN 2 #define HELP \ "HELP:\nHow to run the alpha compiler:\n./alpha [options] " \ "program\nValid " \ - "options:\n-tok output the token number, token, line number, and " \ + "options:\n-tok output the token number, token, line number, and " \ "column " \ - "number for each of the tokens to the .tok file\n-st output the " \ + "number for each of the tokens to the .tok file\n-st output the " \ "symbol " \ - "table for the program to the .st file\n-help print this message " \ + "table for the program to the .st file\n-help print this message " \ "and exit " \ - "the alpha compiler\n" + "the alpha compiler\n-debug print debugging messages in grammar rules \n" + #define SET_FLAG 1 // Used to set flags for arg types #define INVALID \ "INVALID INPUT: Include a .alpha file or use -help for more inputs \n" @@ -39,6 +41,7 @@ SymbolTable *cur; FILE *alpha_file; FILE *tok_flag = NULL; FILE *st_flag = NULL; +FILE *tc_flag = NULL; bool DEBUG = false; int no_flag = 0; int arg; @@ -77,4 +80,4 @@ char *COLOR_YELLOW = "\033[1;33m"; char *COLOR_LIGHTBLUE = "\033[1;34m"; char *COLOR_LIGHTPURPLE = "\033[1;35m"; char *COLOR_LIGHTCYAN = "\033[1;36m"; -char *COLOR_WHITE = "\033[1;37m"; \ No newline at end of file +char *COLOR_WHITE = "\033[1;37m"; diff --git a/test.sh b/test.sh index 9c32bed..8443215 100755 --- a/test.sh +++ b/test.sh @@ -48,7 +48,7 @@ if [ $# -eq 0 ]; then if [ -f "$file" ]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi @@ -60,7 +60,7 @@ if [ $# -eq 0 ]; then if [ -f "$file" ]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi @@ -72,7 +72,7 @@ if [ $# -eq 0 ]; then if [ -f "$file" ]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi @@ -84,7 +84,7 @@ if [ $# -eq 0 ]; then if [ -f "$file" ]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n${WHITE}" switchfunc fi @@ -106,7 +106,7 @@ else if [ -f "$1" ]; then filename=$(basename -- "$1") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$1" -debug + ./alpha -st -debug "$1" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}" exit 1 else @@ -121,7 +121,7 @@ else if [[ "$file" == *"$1"* ]]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi @@ -132,7 +132,7 @@ else if [[ "$file" == *"$1"* ]]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi @@ -143,7 +143,7 @@ else if [[ "$file" == *"$1"* ]]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi @@ -154,7 +154,7 @@ else if [[ "$file" == *"$1"* ]]; then filename=$(basename -- "$file") echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" - ./alpha -st "$file" -debug + ./alpha -st -debug "$file" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" switchfunc fi @@ -163,4 +163,4 @@ else echo -e "${RED}[ERROR] ${YELLOW}Invalid prefix $1!${WHITE}" exit 1 fi -fi \ No newline at end of file +fi