From bd8d410c0be8ad69ea0da8182bb373e42ad1f470 Mon Sep 17 00:00:00 2001 From: Annie Date: Fri, 7 Feb 2025 16:30:55 -0500 Subject: [PATCH 1/3] Adding macros and function to detect -tok input --- runner.c | 26 ++++++++++++++++++++++++++ runner.h | 8 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 runner.h diff --git a/runner.c b/runner.c index e69de29..eee0d2b 100644 --- a/runner.c +++ b/runner.c @@ -0,0 +1,26 @@ +#include runner.h + +int main(int argc, char *argv[]) { + char *check_input; + + //check_input can be compared to INVALID_ARG and DIFF_ARG to determine if -tok and holds the generated file name if it is + check_input = is_tok(argc, argv); + + return 0; //not sure what to do yet +} + +char *is_tok(int argc, char *argv[]) { + if (argc == 3 && strcmp("-tok", argv[1])) { + char *input_prog = argv[2]; + int file_len = strlen(input); + //check that input program is a .alpha file + if (strcmp(".alpha", input_prog[file_len - ALPHA_OFFSET]) != 0) { + return INVALID_ARG; + } + char *FILE_tok[file_len - ALPHA_OFFSET + TOK_LEN]; + strncpy(input, FILE_tok, file_len - ALPHA_OFFSET); //copy name of prog before .alpha + strcpy(".tok", FILE_tok[file_len - ALPHA_OFFSET]); //add .tok to end of file name + return FILE_tok; + } + return DIFF_ARG; +} diff --git a/runner.h b/runner.h new file mode 100644 index 0000000..dff315f --- /dev/null +++ b/runner.h @@ -0,0 +1,8 @@ +#define ALPHA_OFFSET 5 +#define TOK_LEN 3 +#define INVALID_ARG "invalid" +#define DIFF_ARG "diff" +#include + +int main(int argc, char* argv); +char *is_tok(int argc, char* argv); From f0f96dec8d13e4f835ef7e2c667bca12b3064572 Mon Sep 17 00:00:00 2001 From: Annie Date: Mon, 10 Feb 2025 11:05:30 -0500 Subject: [PATCH 2/3] moved runner.h contents to runner.c --- runner.c | 10 +++++++++- runner.h | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/runner.c b/runner.c index eee0d2b..af078f9 100644 --- a/runner.c +++ b/runner.c @@ -1,4 +1,12 @@ -#include runner.h +#define ALPHA_OFFSET 5 +#define TOK_LEN 3 +#define INVALID_ARG "invalid" +#define DIFF_ARG "diff" +#include + +int main(int argc, char* argv); +char *is_tok(int argc, char* argv); + int main(int argc, char *argv[]) { char *check_input; diff --git a/runner.h b/runner.h index dff315f..e69de29 100644 --- a/runner.h +++ b/runner.h @@ -1,8 +0,0 @@ -#define ALPHA_OFFSET 5 -#define TOK_LEN 3 -#define INVALID_ARG "invalid" -#define DIFF_ARG "diff" -#include - -int main(int argc, char* argv); -char *is_tok(int argc, char* argv); From a1c7aaadb1942ebf2c60433c9ba3b4431e152e27 Mon Sep 17 00:00:00 2001 From: Annie Date: Mon, 10 Feb 2025 13:22:01 -0500 Subject: [PATCH 3/3] Added code to print to file with -tok input and created header file --- runner.c | 24 ++++++++++++++---------- runner.h | 13 +++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/runner.c b/runner.c index af078f9..3d467b8 100644 --- a/runner.c +++ b/runner.c @@ -1,20 +1,24 @@ -#define ALPHA_OFFSET 5 -#define TOK_LEN 3 -#define INVALID_ARG "invalid" -#define DIFF_ARG "diff" -#include - -int main(int argc, char* argv); -char *is_tok(int argc, char* argv); +#include "runner.h" int main(int argc, char *argv[]) { char *check_input; - + int token; //check_input can be compared to INVALID_ARG and DIFF_ARG to determine if -tok and holds the generated file name if it is check_input = is_tok(argc, argv); + FILE * output = fopen(check_input, "w"); - return 0; //not sure what to do yet + if (check_input == INVALID_ARG) { + return -1; + } + + while (0 != (token = yylex())) { + if (check_input != DIFF_ARG) { + fprintf(output, "%d %d %3d \"%s\"\n", line_number, column_number, token, yytext); + } + } + + return 0; } char *is_tok(int argc, char *argv[]) { diff --git a/runner.h b/runner.h index e69de29..080d5c1 100644 --- a/runner.h +++ b/runner.h @@ -0,0 +1,13 @@ +#define ALPHA_OFFSET 5 +#define TOK_LEN 3 +#define INVALID_ARG "invalid" +#define DIFF_ARG "diff" +#include +#include +#include "lex.yy.c" + +extern int line_number, column_number; +extern char *yytext; + +int main(int argc, char* argv); +char *is_tok(int argc, char* argv);#define ALPHA_OFFSET 5