From 5171e4bc8649356ce90d3e961a6bae48f2039263 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Thu, 20 Feb 2025 14:30:18 -0500 Subject: [PATCH 1/5] Makefile updated t#30 --- Makefile | 3 ++- Makefile.save | 43 ------------------------------------------- 2 files changed, 2 insertions(+), 44 deletions(-) delete mode 100644 Makefile.save diff --git a/Makefile b/Makefile index 90bdaca..6fb4421 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ EXE := alpha CFLAGS := -std=c99 -Wall CPPFLAGS := -build: lex.yy.c runner.o runner +compiler: lex.yy.c runner.o runner lex.yy.c: lexicalStructure.lex $(FLEX) -o lex.yy.c $(LEX) @@ -38,6 +38,7 @@ test: ./$(EXE) -tok ./tests/test_simpleLiterals.alpha ./$(EXE) -tok ./tests/test_real_alpha_file.alpha ./$(EXE) -tok ./tests/test_real_alpha_2.alpha + clean: rm -f *.o rm -f lex.yy.c diff --git a/Makefile.save b/Makefile.save deleted file mode 100644 index 668af54..0000000 --- a/Makefile.save +++ /dev/null @@ -1,43 +0,0 @@ -CC := gcc -FLEX := flex -LEX := lexicalStructure.lex -EXE := runner -CFLAGS := -std=c99 -Wall -CPPFLAGS := - -runner: flex.o runner.o - $(CC) -o runner runner.o flex.o - -debug: CFLAGS += -DDEBUG=true -debug: clean runner - -runner.o: runner.c runner.h flex.h - $(CC) $(CFLAGS) -o runner.o -c runner.c - -flex.o: lex.yy.c typedefs.h - $(CC) $(CFLAGS) -o flex.o -c lex.yy.c - -lex.yy.c: lexicalStructure.lex - $(FLEX) -o lex.yy.c $(LEX) - -test: - ./$(EXE) ./tests/test_comments.alpha - ./$(EXE) ./tests/test_generalTokenTest.alpha - ./$(EXE) ./tests/test_keywords.alpha - ./$(EXE) ./tests/test_operators.alpha - ./$(EXE) ./tests/test_otherpunc.alpha - ./$(EXE) ./tests/test_simpleIntTest.alpha - ./$(EXE) ./tests/test_simpleLiterals.alpha - ./$(EXE) -tok ./tests/test_comments.alpha - ./$(EXE) -tok ./tests/test_generalTokenTest.alpha - ./$(EXE) -tok ./tests/test_keywords.alpha - ./$(EXE) -tok ./tests/test_operators.alpha - ./$(EXE) -tok ./tests/test_otherpunc.alpha - ./$(EXE) -tok ./tests/test_simpleIntTest.alpha - ./$(EXE) -tok ./tests/test_simpleLiterals.alpha -clean: - rm -f *.o - rm -f lex.yy.c - rm -f $(EXE) - rm -f flex.h - rm -f *.tok From eb3452fec9afd4a71c97adfd83ecc34903a7ed7a Mon Sep 17 00:00:00 2001 From: Partho Bhattacharya Date: Fri, 21 Feb 2025 15:25:21 -0500 Subject: [PATCH 2/5] added code to print out positions of incorrect tokens --- lexicalStructure.lex | 4 +++- runner.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lexicalStructure.lex b/lexicalStructure.lex index 7857730..64b2863 100644 --- a/lexicalStructure.lex +++ b/lexicalStructure.lex @@ -81,6 +81,8 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\] {ID} {if(DEBUG) {printf( "ID: %s (%d)\n", yytext, ID);} else {return ID;}} \n {line_number++; column_number = 1;} -. {column_number++;} +\t {column_number++;} +" " {column_number++;} +. {column_number++; return 1999;} %% diff --git a/runner.c b/runner.c index 85e8214..a87df49 100644 --- a/runner.c +++ b/runner.c @@ -79,6 +79,9 @@ int run(FILE *alpha) { } continue; } + if(token == 1999){ + printf("On line number %d and column number %d we have an invalid character:%s\n",line_number,column_number,yytext); + } column_number += yyleng; } From 5505d11d2133ab7eb9779e55eb49e409346c67cb Mon Sep 17 00:00:00 2001 From: Scarlett Date: Fri, 21 Feb 2025 16:18:38 -0500 Subject: [PATCH 3/5] Completed task1 objectives t#30 --- .gitignore | 2 ++ Makefile | 12 ++++++++---- README.MD | 17 +++++++++++++++++ grammar.y | 18 ++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 README.MD create mode 100644 grammar.y diff --git a/.gitignore b/.gitignore index 47f37f6..b927c65 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.o alpha flex.h +grammar.tab.c +grammar.tab.h \ No newline at end of file diff --git a/Makefile b/Makefile index 6fb4421..a6d045b 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,7 @@ CC := gcc FLEX := flex LEX := lexicalStructure.lex EXE := alpha -CFLAGS := -std=c99 -Wall -CPPFLAGS := +CFLAGS := compiler: lex.yy.c runner.o runner @@ -14,10 +13,13 @@ runner.o: runner.c runner.h flex.h $(CC) $(CFLAGS) -o runner.o -c runner.c runner: lex.yy.c runner.o - $(CC) -o $(EXE) runner.o lex.yy.c + $(CC) $(CFLAGS) -o $(EXE) runner.o lex.yy.c + +bison: grammar.y + bison -d grammar.y debug: CFLAGS += -DDEBUG=1 -debug: clean runner +debug: clean compiler test: ./$(EXE) ./tests/test_comments.alpha @@ -45,3 +47,5 @@ clean: rm -f $(EXE) rm -f flex.h rm -f *.tok + rm -f grammar.tab.c + rm -f grammar.tab.h diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..525582f --- /dev/null +++ b/README.MD @@ -0,0 +1,17 @@ +# The Translators α Compiler +#### Members: Annie Slenker, Meyer Simon, Partho Bhattacharya, & Scarlett Kadan + +## Lexical Analyzer +* **Undefined Behavior:** + * Spaces are not required between tokens. For instance, an INTEGER and an ID are valid even if there is no space between them +``` +Input: *5variable* +Output: 2 14 301 "5" + 1 1 101 "variable" +``` + +## Syntax Analyzer +* *Incomplete* + +## Symbol Table +* *TODO: Create diagram.* \ No newline at end of file diff --git a/grammar.y b/grammar.y new file mode 100644 index 0000000..4a1c8a4 --- /dev/null +++ b/grammar.y @@ -0,0 +1,18 @@ +/* Syntax Analyzer with Bison (3.8.1) */ +/* (referenced Bison manual for file boilerplate [3.1]) */ + +// Prologue +%{ + #include +%} + +// Declarations + + +// Grammar Rules +%% +semicolon.opt: + %empty +| ";" +; +%% \ No newline at end of file From e86edb324b6ead099ee1b7074ee2665ce6e8e480 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Fri, 21 Feb 2025 16:26:37 -0500 Subject: [PATCH 4/5] Fix the conflicts t#29 --- runner.c | 6 +++--- runner.h | 4 ++-- symbol_table.c | 2 ++ test | Bin 16088 -> 0 bytes 4 files changed, 7 insertions(+), 5 deletions(-) delete mode 100755 test diff --git a/runner.c b/runner.c index dd096aa..d183b52 100644 --- a/runner.c +++ b/runner.c @@ -1,4 +1,4 @@ -#include "symbol_table.h" +//#include "symbol_table.h" #include "symbol_table.c" #include "runner.h" @@ -94,7 +94,7 @@ int run(FILE *alpha) { if (yyin != NULL) { fclose(yyin); } - + if (tok_flag != NULL) { fclose(tok_flag); } @@ -139,7 +139,7 @@ int new_file(char *arg, char *alpha) { strcat(file_name, "."); strcat(file_name, arg + 1); - + if (strcmp(arg, "-tok") == 0) { tok_flag = fopen(file_name, "w"); } else if (strcmp(arg, "-st") == 0) { diff --git a/runner.h b/runner.h index e7a8194..73c94f2 100644 --- a/runner.h +++ b/runner.h @@ -20,9 +20,9 @@ int arg; SymbolTable * top; SymbolTable * curr; -int main(int argc, char* argv[]); +// int main(int argc, char* argv[]); char *is_tok(int argc, char* argv[]); -int is_alpha_file(char *file, int file_len); +// int is_alpha_file(char *file, int file_len); void enter_scope(int, int); void exit_scope(void); diff --git a/symbol_table.c b/symbol_table.c index e5d1366..a8592eb 100644 --- a/symbol_table.c +++ b/symbol_table.c @@ -69,6 +69,7 @@ TableNode * look_up(SymbolTable * table, char * x){ //uncomment the below main function along with the headers above for a simple standalone test of table and entry creation +/* int main(){ char* String = "STRING"; char* X = "X"; @@ -79,3 +80,4 @@ int main(){ printf("The type of the first entry is %s\n",First_Entry->theType); return 0; } + */ diff --git a/test b/test deleted file mode 100755 index 4941bf240c8f2f1ec1cf50ca112b79be646ae11c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16088 zcmeHOZ)_Y#6(2iI>d+*RbH+whpg^sB8Z9&Wm?6-bGFe+m>sY=3lyD7HsX}iyVkJ}}BucpX%3%r!MX2I_5N;tU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hS=Xo=l+1UdRq6p$s9m|=ME+H6zpA{SU*wOYQZ4@Z`t>92XQleydhswv ztND3W+ux{y04VJr6m>AGCiNa;wsX<}O0Mp^AKQE#(>C0)hKN9qP|{&Cx9Oy2tyHju$_o zAjo@#fq`hhn%fuecxk7fcE;ynnaDavQrW(E%1LF;DQAnpp0P%4SEWHZT{7AYln?iWlmXEj`r}N;heH~86{&olZ z^4ss)ziVGt8^kys;dI!nwc8IWXV2aPyLat%4s>=N>gaKLcJ1EV0Yvb)Kuk^tT;)VS zTh5JpZU_BrsT?;E_u@+Ti;o+W-OwQeNU@4yUZ*i#tK3rWOGN7`+@k#J`g_m0$+}9MldZpe z2n?-da69WV-+3-pm)B>)Z$rh851#9y-^2Yyo{J)*?@K>kzORK^V#qXz|1{)pVJ#%_ z%X(3$v@d5)Wc?*>!6gt6%6eHzM@UpH;LPkpr!OQwosH{g}qDwIUpM#Xv zdV-hroltqaO8jCc^g-Zh?I^sgAB8rVW_6DJ@v~T+K!tKDcv;U1onS+0KiL0oF@87O z$@;iVeR#@Q5dVG1C@%3|{yyQ3%XCqb-9_x1Nd$>5GwZb z;l~5`!we8=36QDy6Z(??ev}nLFUr6K@Zy&C7W(@y>mH%~iO z3ta@TAFpC;+GMD-BMt;7JpIQ>GHGAdg%QRF?Wrw)Sn x*x?f#*axAcrL4pw&tH1ali2 Date: Fri, 21 Feb 2025 16:28:53 -0500 Subject: [PATCH 5/5] switched -st to call print_symbol_table --- runner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner.c b/runner.c index 85e8214..4560da4 100644 --- a/runner.c +++ b/runner.c @@ -84,7 +84,7 @@ int run(FILE *alpha) { if (st_flag != NULL) { //output symbol table, file pointer is - fprintf(st_flag, "just checking that this works \n"); + print_symbol_table(curr,st_flag); } if (yyin != NULL) {