From 3a33cc0f88a1a0d40679e96bad22e0183cff7ddb Mon Sep 17 00:00:00 2001 From: Scarlett Date: Sun, 4 May 2025 17:33:59 -0400 Subject: [PATCH] include lex --- a.out | Bin 464 -> 0 bytes src/codegen.h~ | 2 -- src/grammar.y | 14 ++++++++++++++ src/lexicalStructure.lex | 2 ++ src/typedefs.h | 3 ++- tests/sprint1/test/sp1_include.alpha | 4 ++++ 6 files changed, 22 insertions(+), 3 deletions(-) delete mode 100644 a.out delete mode 100644 src/codegen.h~ create mode 100644 tests/sprint1/test/sp1_include.alpha diff --git a/a.out b/a.out deleted file mode 100644 index 8540d49290617f7498e8df1dc190587a92561a76..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 464 zcmb<-^>JfjWMqH=Mg}_u1P><4z%T*9WN-kp9T->{SQw7G{$U1kkGuY00#jc&fK<2Z z5B~M8Upiesbi4lPcKyJ3q0{wEx9giu*B1lX*gfr5Zs{n+dVSqHOU L2E;)E==K8uL2Dw) diff --git a/src/codegen.h~ b/src/codegen.h~ deleted file mode 100644 index 2d4c660..0000000 --- a/src/codegen.h~ +++ /dev/null @@ -1,2 +0,0 @@ -/* Code Generation File - Contains functions to generate assembly code */ - diff --git a/src/grammar.y b/src/grammar.y index 9d5d5a3..a29ae39 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -87,6 +87,7 @@ %token RESERVE 613 %token RELEASE 614 %token COMMENT 700 +%token INCLUDE 901 //precedence order %left ASSIGN @@ -106,6 +107,7 @@ program: prototype_or_definition_list + | include_list prototype_or_definition_list ; @@ -123,7 +125,19 @@ prototype_or_definition_list: prototype: L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID + ; + + +include_list: + include_statement SEMI_COLON include_list + | include_statement + ; + + + +include_statement: + INCLUDE C_STRING SEMI_COLON ; diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index 7034997..a8bd8af 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -19,6 +19,8 @@ SCHAR \\n|\\t|\\\"|[^\"\n\\] %% +"#include" { if(tok_flag != NULL) {print_tok(INCLUDE);} incr(line_number,column_number,INCLUDE); return INCLUDE; } + "integer" { if(tok_flag != NULL) {print_tok(T_INTEGER);} incr(line_number,column_number,T_INTEGER); yylval.tn = integ; return T_INTEGER; } "address" { if(tok_flag != NULL) {print_tok(T_ADDRESS);} incr(line_number,column_number,T_ADDRESS); yylval.tn = addr; return T_ADDRESS; } "Boolean" { if(tok_flag != NULL) {print_tok(T_INTEGER);} incr(line_number,column_number,T_INTEGER); yylval.tn = boo; return T_BOOLEAN; } diff --git a/src/typedefs.h b/src/typedefs.h index 3b75b3a..15fe996 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -56,4 +56,5 @@ // comments #define COMMENT 700 //Additional tokens -#define ACCESS 801 \ No newline at end of file +#define ACCESS 801 +#define INCLUDE 901 \ No newline at end of file diff --git a/tests/sprint1/test/sp1_include.alpha b/tests/sprint1/test/sp1_include.alpha new file mode 100644 index 0000000..190d02c --- /dev/null +++ b/tests/sprint1/test/sp1_include.alpha @@ -0,0 +1,4 @@ +(* TEST: [-tok -asc -tc] *) +#include "alpha.h"; +#include "alpha.h"; +#include "alpha.h"; \ No newline at end of file