From fd39afc9e0db6327c9b461265c89fa97a4e15579 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Thu, 27 Mar 2025 15:28:30 -0400 Subject: [PATCH 01/10] Added the files to the repo #t51 --- src/intermediate_code.c | 0 src/intermediate_code.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/intermediate_code.c create mode 100644 src/intermediate_code.h diff --git a/src/intermediate_code.c b/src/intermediate_code.c new file mode 100644 index 0000000..e69de29 diff --git a/src/intermediate_code.h b/src/intermediate_code.h new file mode 100644 index 0000000..e69de29 From 03be62dc1946e5951256fd99b14af6bc50fba783 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Thu, 27 Mar 2025 16:08:31 -0400 Subject: [PATCH 02/10] Added structs enums and stubs #t51 --- src/intermediate_code.c | 13 +++++++++++++ src/intermediate_code.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/intermediate_code.c b/src/intermediate_code.c index e69de29..f32b966 100644 --- a/src/intermediate_code.c +++ b/src/intermediate_code.c @@ -0,0 +1,13 @@ + + void emit_binary_op(char* result, char* op, char* arg1, char* arg2){ + return; + } + void emit_unary_op(char* result, char* op, char* arg){ + return; + } + void emit_assignment(char* target, char* source){ + return; + } +void emit_as_file(FILE * out_file, Instruction * instr_arr){ + return; +} diff --git a/src/intermediate_code.h b/src/intermediate_code.h index e69de29..c2aa796 100644 --- a/src/intermediate_code.h +++ b/src/intermediate_code.h @@ -0,0 +1,37 @@ +// Track 1: Core Infrastructure & Basic Expressions +// * Create intermediate_code.h/.c defining the instruction structure: +// - Struct with fields for: opcode, result, operand1, operand2, label +// - Enum for all operation types (ADD, SUB, MUL, DIV, etc.) +// * Implement temp variable generator function that produces unique names (t1, t2, etc.) +// * Create specific code emission functions: +// - emit_binary_op(char* result, char* op, char* arg1, char* arg2) +// - emit_unary_op(char* result, char* op, char* arg) +// - emit_assignment(char* target, char* source) +// * Add Bison actions for arithmetic expressions: +// - Addition: $$ = new_temp(); emit_binary_op($$, "ADD", $1, $3); +// - Subtraction, multiplication, division, modulo +#include "symbol_table.h" + +typedef enum {ADD, SUB, MUL, DIV} Op; // TODO: add all the instructions +typedef struct { + Op opcode; + TableNode * result; + TableNode * operand1; + TableNode * operand2; + int label; +} Instruction; + +void emit_binary_op(char* result, char* op, char* arg1, char* arg2); +void emit_unary_op(char* result, char* op, char* arg); +void emit_assignment(char* target, char* source); +// TODO: Find out what these are suposed to do. Guess is create an entry in +// the list of instructions + + +// * Implement integer/boolean/character specific operation handling +// TODO: Find out what this means + +// * Create output function to write instructions to file with line formatting +void emit_as_file(FILE * out_file, Instruction * instr_arr); + +// * Implement instruction array storage for backpatching From 666e0a4159249676b4490e378e481c15f873b007 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Thu, 27 Mar 2025 17:28:16 -0400 Subject: [PATCH 03/10] No change #t51 --- src/intermediate_code.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/intermediate_code.h b/src/intermediate_code.h index c2aa796..446f4c4 100644 --- a/src/intermediate_code.h +++ b/src/intermediate_code.h @@ -25,11 +25,11 @@ void emit_binary_op(char* result, char* op, char* arg1, char* arg2); void emit_unary_op(char* result, char* op, char* arg); void emit_assignment(char* target, char* source); // TODO: Find out what these are suposed to do. Guess is create an entry in -// the list of instructions +// the list of instructions. Guess is that its suposed to ret a struct ptr // * Implement integer/boolean/character specific operation handling -// TODO: Find out what this means +// TODO: Find out what this means. // * Create output function to write instructions to file with line formatting void emit_as_file(FILE * out_file, Instruction * instr_arr); From 24caa0e9a7217ad7272ef1828e9e4176dae1c63c Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Fri, 28 Mar 2025 10:18:18 -0400 Subject: [PATCH 04/10] Updeated the contents of st to Dev #t51 --- src/symbol_table.c | 89 ++++++++++++++++++++++++++++++++++++++-------- src/symbol_table.h | 4 +-- 2 files changed, 77 insertions(+), 16 deletions(-) diff --git a/src/symbol_table.c b/src/symbol_table.c index 205bcbe..4ce220b 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -27,23 +27,23 @@ typedef enum { // TYPE_BOOLEAN, // TYPE_ADDRESS, // Type String is an array of char enclosed in double quotes per lexer - TYPE_STRING, + TYPE_STRING = 1, // Array can be multidimensional. Information should be stored here - TYPE_ARRAY, + TYPE_ARRAY = 2, // Record is user defined types - TYPE_RECORD, + TYPE_RECORD = 3, // Declaring what type a particular function is without as - TYPE_FUNCTION_DECLARATION, + TYPE_FUNCTION_DECLARATION = 4, // Declaring what type a particular function is with as // TYPE_AS_FUNCTION_DECLARATION, // Declaring what type a function is (what the parameters and output // are) - TYPE_FUNCTION_TYPE, + TYPE_FUNCTION_TYPE = 5, // The Type being pointed to by the first 4 above that only stores the // size - TYPE_PRIMITIVE, + TYPE_PRIMITIVE = 6, //likely NULL - TYPE_ALL_ELSE + TYPE_ALL_ELSE = 7 } types; @@ -153,12 +153,12 @@ TableNode *getArrType(TableNode *definition) { // order, of what make up that type in an array. Unfortunately this second part // should probably instead be replaced by a reference to a scope in which those // elements are found. -AdInfo *CreateRecordInfo(int length, TableNode *typesarray) { +AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) { AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); info->RecAdInfo = (record_info *)malloc(sizeof(record_info)); info->RecAdInfo->numofelements = length; // replace below with reference to a scope, not an array - info->RecAdInfo->listoftypes = typesarray; + info->RecAdInfo->recordScope = recordScope; return info; } // This gets the number of elements that make up a record. @@ -172,13 +172,13 @@ int getRecLength(TableNode *definition) { return definition->additionalinfo->RecAdInfo->numofelements; } // This gets the array. Needs to up be updated to get the scope instead -TableNode *getRecList(TableNode *definition) { +SymbolTable *getRecList(TableNode *definition) { if (strcmp(getType(definition), "record") != 0) { printf("not checking the list of types of a record -- invalid " "op\n"); return NULL; } - return definition->additionalinfo->RecAdInfo->listoftypes; + return definition->additionalinfo->RecAdInfo->recordScope; } // below function takes a bool to see if parameter should be decomposed or not @@ -379,8 +379,34 @@ TableNode* boo; TableNode* recprime; TableNode* funtypeprime; */ +TableNode* populateTypeAndInfo(TableNode* tn, TableNode* type, AdInfo* info){ + if(tn == NULL){ + printf("passed in an invalid table node to modify (NULL).\n"); + return NULL; + } + if(type == NULL){ + printf("passed in a NULL type reference to populate a table node. Invalid.\n"); + return NULL; + } + if(info == NULL){ + printf("passed in a NULL info reference to populate a table node. Invalid.\n"); + return NULL; + } + tn->theType = type; + tn->additionalinfo = info; + //returning reference to modified table node + return tn; + } int getAdInfoType(TableNode* tn){ + if(tn == NULL){ + printf("passing in NULL table entry. Invalid\n"); + return -1; + } + if(tn->theType == NULL){ + printf("Entry being passed in has a null reference for theType. Invalid.\n"); + return -1; + } if(strcmp(getType(tn),getName(integ))==0){ return TYPE_PRIMITIVE; } @@ -443,11 +469,41 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, } } -char *getType(TableNode *tn) { return tn->theType->theName; } +char *getType(TableNode *tn) { + if(tn == NULL){ + printf("passed a NULL table entry to getType\n"); + return ""; + } + if(tn->theType == NULL){ + printf("type of entry is currently NULL, undefined type \n"); + return ""; + } + return tn->theType->theName; } char *getName(TableNode *tn) { return tn->theName; } int getLine(SymbolTable *st) { return st->Line_Number; } int getColumn(SymbolTable *st) { return st->Column_Number; } +TableNode* addName(TableNode *tn, char* str){ + if(tn == NULL){ + printf("passed a Null table node to the addName function. Invalid./n"); + return tn; + } +} +SymbolTable* setLineNumber(SymbolTable *st,int line){ + if(st == NULL){ + printf("passed a Null Symbol Table to the setLineNumber function. Invalid./n"); + return st; + } + st->Line_Number = line; + } + +SymbolTable* setColumnNumber(SymbolTable *st,int column){ + if(st == NULL){ + printf("passed a Null Symbol Table to the setColumnNumber function. Invalid./n"); + return st; + } + st->Line_Number = column; + } /* //we use false for type defs and true for functions for parameter of typeOf TableNode* Define(SymbolTable* table, bool typeOf, char* id) { @@ -483,6 +539,7 @@ names\n"); return NULL; } */ +//only check table that is given TableNode *table_lookup(SymbolTable *table, char *x) { TableNode *entrie = table->entries; for (; entrie != NULL; entrie = entrie->next) { @@ -492,6 +549,7 @@ TableNode *table_lookup(SymbolTable *table, char *x) { } return NULL; } +//check current table and all parents TableNode *look_up(SymbolTable *table, char *x) { if (table == NULL) { return NULL; @@ -504,6 +562,8 @@ TableNode *look_up(SymbolTable *table, char *x) { } void print_symbol_table(SymbolTable *table, FILE *file_ptr) { + + return; if (table->Parent_Scope == NULL) { fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation"); @@ -526,7 +586,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", current_scope, parant_scope, "", "Empty Scope"); } - for (; entrie != NULL; entrie = entrie->next) { + for (entrie != NULL; entrie = entrie->next;) { if (parant_scope == 0) { /*have to update*/ if (strcmp(entrie->theType->theName, "function primitive") || @@ -555,7 +615,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { "----------------------\n"); } } - +//get top most symbol table SymbolTable *getAncestor(SymbolTable *table) { if (table->Parent_Scope == NULL) { // if table has no parent, return itself @@ -594,6 +654,7 @@ SymbolTable *removeEntry(SymbolTable *scope, char *search) { return scope; } +//almost certainly don't need to use the below function since type checking happens by passing types up the grammar bool typeCheck(char *firstID, char *secondID) { TableNode *entry1 = look_up(cur, firstID); diff --git a/src/symbol_table.h b/src/symbol_table.h index 84b3e5a..de37098 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h @@ -30,7 +30,7 @@ typedef struct { // similar to above we define a record to hold the number of elements // and an array of tablenodes (types) that it contains in the > int numofelements; - struct TableNode *listoftypes; + struct SymbolTable *recordScope; } record_info; typedef struct { @@ -91,7 +91,7 @@ int getPrimSize(TableNode *definition); int getNumArrDim(TableNode *definition); TableNode *getArrType(TableNode *definition); int getRecLength(TableNode *definition); -TableNode *getRecList(TableNode *definition); +SymbolTable *getRecList(TableNode *definition); int getStartLine(TableNode *definition); bool getAsKeyword(TableNode *definition); TableNode *getParameter(TableNode *definition); From 05b641a32e52d2dca43570cc8256ede128bea551 Mon Sep 17 00:00:00 2001 From: Meyer Simon Date: Tue, 1 Apr 2025 12:53:31 -0400 Subject: [PATCH 05/10] Added stubs for all emit funcs and added the 3 fields discussed in the library t#51 --- src/intermediate_code.c | 51 +++++++++++++++++++++++++++++++++++++++++ src/intermediate_code.h | 22 ++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/intermediate_code.c b/src/intermediate_code.c index f32b966..2d50a34 100644 --- a/src/intermediate_code.c +++ b/src/intermediate_code.c @@ -1,4 +1,12 @@ + + +// TODO: this is here to bring your attention to the comment bellow. +// check if start is NULL if it is assign it to the start globle variable +// otherwise make it next of current and set cur to your instruction. + + + void emit_binary_op(char* result, char* op, char* arg1, char* arg2){ return; } @@ -11,3 +19,46 @@ void emit_as_file(FILE * out_file, Instruction * instr_arr){ return; } + + +void emit_label(char* label){ + return; +} +void emit_jump(char* label){ + return; +} +void emit_conditional_jump(char* condition, char* label){ + return; +} + + + +void emit_function_start(char* name){ + return; +} +void emit_parameter(char* param){ + return; +} +void emit_function_call(char* result, char* name){ + return; +} +void emit_return(char* value){ + return; +} +void emit_reserve(char* result, char* type_name, int size){ + return; +} +void emit_release(char* pointer){ + return; +} + + +void emit_field_access(char* result, char* record, char* field){ + return; +} +void emit_array_access(char* result, char* array, char* index, char* dimension){ + return; +} +void emit_bounds_check(char* index, char* size, char* error_label){ + return; +} diff --git a/src/intermediate_code.h b/src/intermediate_code.h index 446f4c4..1ccd389 100644 --- a/src/intermediate_code.h +++ b/src/intermediate_code.h @@ -19,8 +19,14 @@ typedef struct { TableNode * operand1; TableNode * operand2; int label; + int instruction; + Instruction * prev; + Instruction * next; } Instruction; +Instruction * start = NULL; +Instruction * current = NULL; + void emit_binary_op(char* result, char* op, char* arg1, char* arg2); void emit_unary_op(char* result, char* op, char* arg); void emit_assignment(char* target, char* source); @@ -35,3 +41,19 @@ void emit_assignment(char* target, char* source); void emit_as_file(FILE * out_file, Instruction * instr_arr); // * Implement instruction array storage for backpatching + +void emit_label(char* label); +void emit_jump(char* label); +void emit_conditional_jump(char* condition, char* label); + +void emit_function_start(char* name); +void emit_parameter(char* param); +void emit_function_call(char* result, char* name); +void emit_return(char* value); +void emit_reserve(char* result, char* type_name, int size); +void emit_release(char* pointer); + + +void emit_field_access(char* result, char* record, char* field); +void emit_array_access(char* result, char* array, char* index, char* dimension); +void emit_bounds_check(char* index, char* size, char* error_label); From 4e862d54a4285d856dd53ba880b83b6d9e54674a Mon Sep 17 00:00:00 2001 From: Scarlett Date: Thu, 3 Apr 2025 18:29:43 -0400 Subject: [PATCH 06/10] Header files updated --- src/grammar.y | 29 +---- src/lexicalStructure.lex | 2 +- src/runner.c | 13 +-- src/runner.h | 46 ++++++-- src/symbol_table.c | 235 +-------------------------------------- src/symbol_table.h | 118 ++++++++++++++------ 6 files changed, 132 insertions(+), 311 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index b3f2334..63f2034 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -11,35 +11,16 @@ // 4️⃣ Rule end-markers (;, |) should always be 4 spaces in. // 5️⃣ C-blocks should always be clearly defined and follow clang formatting rules. // 6️⃣ 1-line if/for/while statements must be wrapped in curly braces. -// 7️⃣ DO NOT USE TABS. EVER. +// 7️⃣ Comments should always be above rules +// 8️⃣ DO NOT USE TABS. EVER. // Please ask Scarlett if you are unsure of how to format something. Thanks! 😀 %{ - #include #include "../src/symbol_table.c" - #include - extern int yylex(void); + void yyerror(const char *err); - extern char* yytext; - extern int yyleng; - extern int yychar; - extern SymbolTable * cur; - //char* cur_value; - //char* cur_type; int token_tracker; - extern int line_number; - extern int column_number; - extern FILE * yyin; - extern TableNode* funprime; - extern TableNode* arrayprim; - extern TableNode* recprime; - extern TableNode* funtypeprime; - extern TableNode* integ; - extern TableNode* addr; - extern TableNode* chara; - extern TableNode* stri; - extern TableNode* boo; TableNode * tn; %} @@ -144,7 +125,7 @@ definition: printdebug("Currently see a record definition for %s", $2); tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0))); if (table_lookup(getAncestor(cur), $2) == undefined) { - printdebug("rec not found "); + printdebug("rec not found"); } } dblock @@ -196,7 +177,7 @@ definition: } if (node == undefined) { printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column); - } else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) { + } else if (getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) { printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column); } else { setStartLine(node, @1.first_line); diff --git a/src/lexicalStructure.lex b/src/lexicalStructure.lex index 920cdc4..00b5a4d 100644 --- a/src/lexicalStructure.lex +++ b/src/lexicalStructure.lex @@ -4,8 +4,8 @@ %option noyywrap %option header-file="flex.h" %option yylineno + %{ - #include #include "../tmp/grammar.tab.h" #include "../src/symbol_table.h" #ifndef DEBUG diff --git a/src/runner.c b/src/runner.c index c6f94a3..5f903c3 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2,17 +2,6 @@ /* The Translators - Spring 2025 */ #include "runner.h" -extern TableNode *funprime; -extern TableNode *arrayprim; -extern TableNode *integ; -extern TableNode *addr; -extern TableNode *chara; -extern TableNode *stri; -extern TableNode *boo; -extern bool DEBUG; -extern char *COLOR_YELLOW; -extern char *COLOR_BLUE; -extern char *COLOR_WHITE; int main(int argc, char *argv[]) { // if last argument is debug then set to true and ignore it for the rest @@ -91,10 +80,12 @@ void incr(int lnum, int cnum, int tok) { // column_number += yyleng; // } } + void print_tok(int tok) { fprintf(tok_flag, "%d %d %3d \"%s\"\n", line_number, column_number, tok, yytext); } + int run(FILE *alpha) { int token; top = cur = init(CreateScope(NULL, 1, 1)); diff --git a/src/runner.h b/src/runner.h index 9678609..cc573c5 100644 --- a/src/runner.h +++ b/src/runner.h @@ -25,30 +25,56 @@ #include #include "../tmp/flex.h" -#include "symbol_table.h" -// #include "typedefs.h" #include "../tmp/grammar.tab.h" +#include "symbol_table.h" extern int line_number, column_number; extern char *yytext; extern FILE *yyin; -int arg; +extern bool DEBUG; SymbolTable *top; SymbolTable *cur; -// int main(int argc, char* argv[]); -char *is_tok(int argc, char *argv[]); -// int is_alpha_file(char *file, int file_len); - FILE *alpha_file; FILE *tok_flag = NULL; FILE *st_flag = NULL; +bool DEBUG = false; int no_flag = 0; +int arg; + +TableNode *funprime; +TableNode *arrayprim; +TableNode *integ; +TableNode *addr; +TableNode *chara; +TableNode *stri; +TableNode *boo; +TableNode *recprime; +TableNode *funtypeprime; +TableNode *undefined; int main(int argc, char *argv[]); +int check_flag(char *arg, char *alpha); +void incr(int lnum, int cnum, int tok); +void print_tok(int tok); +int run(FILE *alpha); +bool is_help(char *input); int new_file(char *arg, char *alpha); int is_alpha_file(char *alpha, int file_len); -bool is_help(char *input); -int run(FILE *alpha); -int check_flag(char *arg, char *alpha); + +char *COLOR_RED = "\033[0;31m"; +char *COLOR_GREEN = "\033[0;32m"; +char *COLOR_ORANGE = "\033[0;33m"; +char *COLOR_BLUE = "\033[0;34m"; +char *COLOR_PURPLE = "\033[0;35m"; +char *COLOR_CYAN = "\033[0;36m"; +char *COLOR_LIGHTGRAY = "\033[0;37m"; +char *COLOR_DARKGRAY = "\033[1;30m"; +char *COLOR_LIGHTRED = "\033[1;31m"; +char *COLOR_LIGHTGREEN = "\033[1;32m"; +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 diff --git a/src/symbol_table.c b/src/symbol_table.c index 97b4eac..f458769 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -3,44 +3,6 @@ #include "symbol_table.h" -#include -#include -#include -#include -char *typey = "type"; -char *funy = "function"; -TableNode *funprime; -TableNode *arrayprim; -extern SymbolTable *cur; -TableNode *integ; -TableNode *addr; -TableNode *chara; -TableNode *stri; -TableNode *boo; -TableNode *recprime; -TableNode *funtypeprime; -TableNode *undefined; - -char *COLOR_RED = "\033[0;31m"; -char *COLOR_GREEN = "\033[0;32m"; -char *COLOR_ORANGE = "\033[0;33m"; -char *COLOR_BLUE = "\033[0;34m"; -char *COLOR_PURPLE = "\033[0;35m"; -char *COLOR_CYAN = "\033[0;36m"; -char *COLOR_LIGHTGRAY = "\033[0;37m"; -char *COLOR_DARKGRAY = "\033[1;30m"; -char *COLOR_LIGHTRED = "\033[1;31m"; -char *COLOR_LIGHTGREEN = "\033[1;32m"; -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"; - -bool DEBUG = false; - -void printdebug_impl(char *file, int line, const char *format, ...); - void printdebug_impl(char *file, int line, const char *format, ...) { if (DEBUG) { printf("%s<%s> [%d]%s ", COLOR_DARKGRAY, file, line, @@ -53,87 +15,6 @@ void printdebug_impl(char *file, int line, const char *format, ...) { } } -#define printdebug(format, ...) \ - printdebug_impl(__FILE__, __LINE__, format, ##__VA_ARGS__) - -// AdInfo *Undefined_function_type_info; -typedef enum { - // First 4 below are primitive types that are all encapsulated in - // primitive type - // TYPE_INTEGER, - // TYPE_CHARACTER, - // TYPE_BOOLEAN, - // TYPE_ADDRESS, - // Type String is an array of char enclosed in double quotes per lexer - TYPE_STRING = 1, - // Array can be multidimensional. Information should be stored here. - // This is the type of the array - TYPE_ARRAY_TYPE = 2, - // Record is user defined types - TYPE_RECORD_TYPE = 3, - // Declaring what type a particular function is without as - TYPE_FUNCTION_DECLARATION = 4, - // Declaring what type a particular function is with as - // TYPE_AS_FUNCTION_DECLARATION, - // Declaring what type a function is (what the parameters and output - // are) - TYPE_FUNCTION_TYPE = 5, - // The Type being pointed to by the first 4 above that only stores the - // size - TYPE_PRIMITIVE = 6, - // likely NULL - TYPE_ALL_ELSE = 7, - TYPE_UNDEFINED = 8, - TYPE_RECORD = 9, - TYPE_ARRAY = 10 - -} types; - -/* put in symbol_table.h -typedef struct{ - int size; if(strcmp(getType(tn),getName(integ))==0){ - return - } -}primitive_info; - -typedef struct{ - int length; - char* location; -}string_info; - -typedef struct{ - int numofdimensions; - //the above value tells you how long the below array is. For example if num -of dimensions is 5, I can store 1,3,2,5,9 to define > int* sizesofdimensions; - TableNode* typeofarray; -}array_info; - -typedef struct{ - //similar to above we define a record to hold the number of elements and an -array of tablenodes (types) that it contains in the order specified by the user - int numofelements; - TableNode* listoftypes; -}record_info; - -typedef struct{ - int startlinenumber; - bool regularoras; -}function_declaration_info; - -typedef struct{ - TableNode* parameter; - TableNode* returntype; -}function_type_info; - -typedef union { - PrimAdInfo* primitive_info; - ArrayAdInfo* array_info; - RecAdInfo* record_info; - StringAdInfo* string_info; - FunDecAdInfo* func_dec_info; - FunTypeAdInfo* func_type_info; - }AdInfo; -*/ // primitive additional info only stores the size of that type AdInfo *CreatePrimitiveInfo(int size) { @@ -167,19 +48,10 @@ int getPrimSize(TableNode *definition) { return definition->additionalinfo->PrimAdInfo->size; } -// probably don't need the below structure since can create from an array -/*string_info* CreateStringInfo(int length, char* loc){ - string_info* stringy = (string_info*)malloc(sizeof(string_info)); - stringy.length=length; - char* location = loc; - return stringy; -} -*/ - // Only information stored in array info is the number of dimensions and the // type stored in the array per professor, the actual size of the array is // calculated at runtime so bounds checking only needs to be done then -AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) { +AdInfo *CreateArrayInfo(int dim, TableNode *type) { if (type == NULL) { printdebug("passed a NULL reference to " "CreateArrayInfo. Invalid."); @@ -866,41 +738,7 @@ SymbolTable *setColumnNumber(SymbolTable *st, int column) { st->Line_Number = column; return st; } -/* -//we use false for type defs and true for functions for parameter of typeOf -TableNode* Define(SymbolTable* table, bool typeOf, char* id) { -if(table ==NULL || table->Parent_Scope != NULL){ - printdebug("No valid table given for header defs"); - return NULL; -} - - TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode)); - -//possible issues with referencing text instead of heap -if(typeOf == 0){ - newEntry->theType = typey; -} -if (typeOf == 1){ - newEntry->theType = funy; -} -if(table_lookup(table,id) != NULL){ - printdebug("already defined at the top level, can't define duplicate -names"); return NULL; -} - newEntry->theName = id; - if (table->entries == NULL) { - table->entries = newEntry; - return newEntry; - } else { - TableNode* oldEntry = table->entries; - table->entries = newEntry; - newEntry->next = oldEntry; - return newEntry; - } - -} -*/ // only check table that is given TableNode *table_lookup(SymbolTable *table, char *x) { if (table == NULL) { @@ -915,6 +753,7 @@ TableNode *table_lookup(SymbolTable *table, char *x) { } return undefined; } + // check current table and all parents TableNode *look_up(SymbolTable *table, char *x) { if (table == NULL) { @@ -931,60 +770,7 @@ TableNode *look_up(SymbolTable *table, char *x) { x, getLine(table), getColumn(table)); return look_up(table->Parent_Scope, x); } -/* -void print_symbol_table(SymbolTable *table, FILE *file_ptr) { - if (table->Parent_Scope == NULL) { - fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", - "SCOPE", "PARENT", "TYPE", "Extra annotation"); - } - TableNode *entrie = table->entries; - fprintf(file_ptr, "-----------------:--------:--------:----------------" - "------:---------" - "--------------------\n"); - int parant_scope = 0; - int current_scope = 0; - if (table->Parent_Scope != NULL) { - parant_scope = table->Parent_Scope->Line_Number * 1000 + - table->Parent_Scope->Column_Number; - current_scope = - table->Line_Number * 1000 + table->Column_Number; - } else { - current_scope = 1001; - } - if (entrie == NULL) { - fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", - current_scope, parant_scope, "", "Empty Scope"); - } - for (; entrie != NULL; entrie = entrie->next) { - if (parant_scope == 0) { - /*have to update if (strcmp(entrie->theType->theName, - "function primitive") || - strcmp(entrie->theType->theName, - "array")) { - } - fprintf(file_ptr, - "%-17s: %06d : : %-21s: %-28s\n", - entrie->theName, current_scope, - entrie->theType->theName, "Extra annotation"); - } else { - fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", - entrie->theName, current_scope, parant_scope, - entrie->theType->theName, "Extra annotation"); - } - } - if (table->Children_Scope != NULL) { - ListOfTable *node = table->Children_Scope; - for (; node != NULL; node = node->next) { - print_symbol_table(node->table, file_ptr); - } - } - if (table->Parent_Scope == NULL) { - fprintf(file_ptr, "-----------------:--------:--------:--------" - "--------------:-------" - "----------------------\n"); - } -}*/ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (table == NULL) { @@ -1286,20 +1072,3 @@ TableNode *getNextEntry(TableNode *tn) { } return tn->next; } - -// 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"; - SymbolTable* Second = CreateScope(NULL, 2,2); - printdebug("Line number is %d, Column number of scope is - %d",Second->Line_Number,Second->Column_Number); TableNode* First_Entry = - CreateEntry(Second,String,X); - - printdebug("The type of the first entry is %s",First_Entry->theType); - return 0; - } - */ \ No newline at end of file diff --git a/src/symbol_table.h b/src/symbol_table.h index de37098..5f87b5b 100644 --- a/src/symbol_table.h +++ b/src/symbol_table.h @@ -1,3 +1,4 @@ +#include #include #include #include @@ -9,26 +10,12 @@ typedef struct { int size; } primitive_info; -/*This structure can be subsumed into the structure below (1-d array of chars) -typedef struct{ - //shouldn't need to store any values since would be compiled at runtime - //int length; - //char* location; -}string_info; -*/ - typedef struct { int numofdimensions; - // the above value tells you how long the below array is. For example if - // num of dimensions is 5, I can store 1,3,2,5,9 to define > int* - // arr; shouldn't need to store any values (like sizes of dimenions or - // the location int* sizesofdimensions; do have to store type of array struct TableNode *typeofarray; } array_info; typedef struct { - // similar to above we define a record to hold the number of elements - // and an array of tablenodes (types) that it contains in the > int numofelements; struct SymbolTable *recordScope; } record_info; @@ -47,19 +34,16 @@ typedef union { primitive_info *PrimAdInfo; array_info *ArrayAdInfo; record_info *RecAdInfo; - // string_info* StringAdInfo; function_declaration_info *FunDecAdInfo; function_type_info *FunTypeAdInfo; } AdInfo; typedef struct ListOfTable { struct SymbolTable *table; - // struct ListOfTable* prev; struct ListOfTable *next; } ListOfTable; typedef struct TableNode { - // reference to the type entry that this is struct TableNode *theType; char *theName; AdInfo *additionalinfo; @@ -74,30 +58,100 @@ typedef struct SymbolTable { int Column_Number; } SymbolTable; +typedef enum { + TYPE_STRING = 1, + TYPE_ARRAY_TYPE = 2, + TYPE_RECORD_TYPE = 3, + TYPE_FUNCTION_DECLARATION = 4, + TYPE_FUNCTION_TYPE = 5, + TYPE_PRIMITIVE = 6, + TYPE_ALL_ELSE = 7, + TYPE_UNDEFINED = 8, + TYPE_RECORD = 9, + TYPE_ARRAY = 10 +} types; + +AdInfo *CreatePrimitiveInfo(int size); +int getPrimSize(TableNode *definition); +AdInfo *CreateArrayInfo(int dim, TableNode *type); +int getNumArrDim(TableNode *definition); +TableNode *getArrType(TableNode *definition); +AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope); +int getRecLength(TableNode *definition); +SymbolTable *getRecList(TableNode *definition); +TableNode *setRecSize(TableNode *tn, int n); +int getRecSize(SymbolTable *tn); +AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular); +int getStartLine(TableNode *definition); +TableNode *setStartLine(TableNode *tn, int start); +bool getAsKeyword(TableNode *definition); +TableNode *setAsKeyword(TableNode *tn, bool as); +AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype); +TableNode *getParameter(TableNode *definition); +TableNode *getReturn(TableNode *definition); SymbolTable *CreateScope(SymbolTable *ParentScope, int Line, int Column); +SymbolTable *init(SymbolTable *start); +TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info); +int getAdInfoType(TableNode *tn); +TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, + AdInfo *ad); +char *getType(TableNode *tn); +char *getName(TableNode *tn); +int getLine(SymbolTable *st); +int getColumn(SymbolTable *st); +TableNode *addName(TableNode *tn, char *str); +SymbolTable *setLineNumber(SymbolTable *st, int line); +SymbolTable *setColumnNumber(SymbolTable *st, int column); TableNode *table_lookup(SymbolTable *table, char *x); TableNode *look_up(SymbolTable *table, char *x); void print_symbol_table(SymbolTable *table, FILE *file_ptr); - SymbolTable *getAncestor(SymbolTable *table); +SymbolTable *removeEntry(SymbolTable *scope, char *search); +bool typeCheck(char *firstID, char *secondID); SymbolTable *getParent(SymbolTable *st); ListOfTable *getChildren(SymbolTable *st); SymbolTable *getFirstChild(ListOfTable *lt); ListOfTable *getRestOfChildren(ListOfTable *lt); TableNode *getFirstEntry(SymbolTable *st); TableNode *getNextEntry(TableNode *tn); -SymbolTable *init(SymbolTable *scope); -int getPrimSize(TableNode *definition); -int getNumArrDim(TableNode *definition); -TableNode *getArrType(TableNode *definition); -int getRecLength(TableNode *definition); -SymbolTable *getRecList(TableNode *definition); -int getStartLine(TableNode *definition); -bool getAsKeyword(TableNode *definition); -TableNode *getParameter(TableNode *definition); -TableNode *getReturn(TableNode *definition); -char *getType(TableNode *tn); -char *getName(TableNode *tn); -int getLine(SymbolTable *st); -int getColumn(SymbolTable *st); +void printdebug_impl(char *file, int line, const char *format, ...); +#define printdebug(format, ...) \ + printdebug_impl(__FILE__, __LINE__, format, ##__VA_ARGS__) + +extern int yylex(void); +extern char *yytext; +extern int yyleng; +extern int yychar; +extern SymbolTable *cur; +extern int line_number; +extern int column_number; +extern FILE *yyin; +extern bool DEBUG; + +extern TableNode *funprime; +extern TableNode *arrayprim; +extern TableNode *integ; +extern TableNode *addr; +extern TableNode *chara; +extern TableNode *stri; +extern TableNode *boo; +extern TableNode *recprime; +extern TableNode *funtypeprime; +extern TableNode *undefined; + +extern char *COLOR_RED; +extern char *COLOR_GREEN; +extern char *COLOR_ORANGE; +extern char *COLOR_BLUE; +extern char *COLOR_PURPLE; +extern char *COLOR_CYAN; +extern char *COLOR_LIGHTGRAY; +extern char *COLOR_DARKGRAY; +extern char *COLOR_LIGHTRED; +extern char *COLOR_LIGHTGREEN; +extern char *COLOR_YELLOW; +extern char *COLOR_LIGHTBLUE; +extern char *COLOR_LIGHTPURPLE; +extern char *COLOR_LIGHTCYAN; +extern char *COLOR_WHITE; \ No newline at end of file From d1aa7f7e0f570d7ac63e687039f8f0cb88e93fe7 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Fri, 4 Apr 2025 15:42:50 -0400 Subject: [PATCH 07/10] =?UTF-8?q?Ready=20for=20Dev!=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/grammar.y | 18 ++++++++-- src/runner.c | 14 ++++++-- src/symbol_table.c | 55 ++++++++++++++--------------- tests/sprint2/test/sp2_llnode.alpha | 1 + 4 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/grammar.y b/src/grammar.y index 63f2034..7b925f6 100644 --- a/src/grammar.y +++ b/src/grammar.y @@ -196,7 +196,7 @@ definition: printdebug("function defined with as, but parameter is type %s at line %d, column %d", getType(parameter),@1.first_line, @1.first_column); } else { for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)) { - CreateEntry(cur, entry, NULL, NULL); + CreateEntry(cur, entry->theType, NULL, NULL); } } } @@ -258,8 +258,11 @@ idlist: sblock: L_BRACE { - if (getLine(cur) != 0 && getColumn(cur)) { + if (getLine(cur) != 0) { cur = CreateScope(cur,@1.first_line,@1.first_column); + } else { + setLineNumber(cur, @1.first_line); + setColumnNumber(cur,@1.first_line); } } statement_list @@ -288,7 +291,16 @@ sblock: dblock: - L_BRACKET declaration_list R_BRACKET; + L_BRACKET + { + if(getLine(cur)==0) { + setLineNumber(cur, @1.first_line); + setColumnNumber(cur,@1.first_line); + } else { + cur = CreateScope(cur,@1.first_line,@1.first_column); + } + } + declaration_list R_BRACKET; diff --git a/src/runner.c b/src/runner.c index 5f903c3..578fa22 100644 --- a/src/runner.c +++ b/src/runner.c @@ -134,7 +134,16 @@ int run(FILE *alpha) { if (st_flag != NULL) { yyparse(); - print_symbol_table(getAncestor(cur), st_flag); + + if (cur == NULL) { + printdebug("%s[FATAL] cur is null", COLOR_LIGHTRED); + } + + if (top == NULL) { + printdebug("%s[FATAL] top is null", COLOR_LIGHTRED); + } + + print_symbol_table(top, st_flag); fclose(st_flag); if (yyin != NULL) { fclose(yyin); @@ -144,7 +153,8 @@ int run(FILE *alpha) { yyparse(); FILE *f = fdopen(1, "w"); - print_symbol_table(getAncestor(cur), f); + + print_symbol_table(top, f); fclose(f); if (yyin != NULL) { diff --git a/src/symbol_table.c b/src/symbol_table.c index f458769..f749b00 100644 --- a/src/symbol_table.c +++ b/src/symbol_table.c @@ -186,7 +186,7 @@ int getRecSize(SymbolTable *tn) { "passed in NULL SymbolTable for getRecSize. Invalid"); return -1; } - int s = 0; + int s = 1; TableNode *cur = getFirstEntry(tn); if (cur != NULL) { while (getNextEntry(cur) != NULL) { @@ -772,7 +772,6 @@ TableNode *look_up(SymbolTable *table, char *x) { } void print_symbol_table(SymbolTable *table, FILE *file_ptr) { - if (table == NULL) { printdebug( "%s[FATAL] passed in NULL table to print_symbol_table", @@ -781,14 +780,14 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } if (table->Parent_Scope == NULL) { - fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", + fprintf(file_ptr, "%-25s: %-6s : %-6s : %-25s: %-30s\n", "NAME", "SCOPE", "PARENT", "TYPE", "Extra annotation"); } TableNode *entrie = table->entries; - fprintf(file_ptr, "-----------------:--------:--------:----------------" - "------:---------" - "--------------------\n"); + fprintf(file_ptr, + "-------------------------:--------:--------:------------------" + "--------:------------------------------\n"); int parant_scope = 0; int current_scope = 0; if (table->Parent_Scope != NULL) { @@ -800,7 +799,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { current_scope = 1001; } if (entrie == NULL) { - fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", "", + fprintf(file_ptr, "%-25s: %06d : %06d : %-25s: %-30s\n", "", current_scope, parant_scope, "", "Empty Scope"); } for (; entrie != NULL; entrie = getNextEntry(entrie)) { @@ -808,8 +807,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : : %-21d -> " - "%-21s: %-28s\n", + "%-25s: %06d : : %d -> %-20s: " + "%-30s\n", entrie->theName, current_scope, entrie->additionalinfo->ArrayAdInfo ->numofdimensions, @@ -818,8 +817,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { "Type of Array"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21d -> %-21s: " - "%-28s\n", + "%-25s: %06d : : %d -> %-20s: " + "%-30s\n", entrie->theName, current_scope, parant_scope, entrie->additionalinfo->ArrayAdInfo @@ -833,16 +832,16 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : :%-21s: " - "elements-%-28d\n", + "%-25s: %06d : : %-25s: " + "elements-%-30d\n", entrie->theName, current_scope, "record", entrie->additionalinfo->RecAdInfo ->numofelements); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s: " - "elements-%-28d\n", + "%-25s: %06d : %06d : %-25s: " + "elements-%-30d\n", entrie->theName, current_scope, parant_scope, "record", entrie->additionalinfo->RecAdInfo @@ -854,14 +853,14 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { fprintf( file_ptr, - "%-17s: %06d : :%-21s: size-%-28d " + "%-25s: %06d : : %-25s: size-%d " "bytes\n", entrie->theName, current_scope, "Primitive", entrie->additionalinfo->PrimAdInfo->size); } else { fprintf( file_ptr, - "%-17s: %06d : %06d : %-21s: size-%-28d " + "%-25s: %06d : %06d : %-25s: size-%-30d " "bytes\n", entrie->theName, current_scope, parant_scope, "Primitive", @@ -872,8 +871,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : : %-21s -> " - "%-21s: %-28s\n", + "%-25s: %06d : : %-25s -> " + "%-25s: %-30s\n", entrie->theName, current_scope, entrie->additionalinfo->FunTypeAdInfo ->parameter->theName, @@ -882,8 +881,8 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { "Type of Function"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s -> %-21s: " - "%-28s\n", + "%-25s: %06d : %06d : %-25s -> %-21s: " + "%-30s\n", entrie->theName, current_scope, parant_scope, entrie->additionalinfo->FunTypeAdInfo @@ -897,12 +896,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : :%-21s: %-28s\n", + "%-25s: %06d : : %-25s: %-30s\n", entrie->theName, current_scope, getType(entrie), "User Defined"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s: %-28s\n", + "%-25s: %06d : %06d : %-25s: %-30s\n", entrie->theName, current_scope, parant_scope, getType(entrie), "User Defined"); @@ -912,12 +911,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { if (parant_scope == 0) { fprintf(file_ptr, - "%-17s: %06d : :%-21s: %-28s\n", + "%-25s: %06d : : %-25s: %-30s\n", entrie->theName, current_scope, "undefined", "undefined entry"); } else { fprintf(file_ptr, - "%-17s: %06d : %06d : %-21s: %-28s\n", + "%-25s: %06d : %06d : %-25s: %-30s\n", entrie->theName, current_scope, parant_scope, "undefined", "undefined entry"); @@ -940,9 +939,9 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) { } } if (getParent(table) == NULL) { - fprintf(file_ptr, "-----------------:--------:--------:--------" - "--------------:-------" - "----------------------\n"); + fprintf(file_ptr, + "-------------------------:--------:--------:----------" + "----------------:------------------------------\n"); } } // get top most symbol table diff --git a/tests/sprint2/test/sp2_llnode.alpha b/tests/sprint2/test/sp2_llnode.alpha index 6b4912e..43007ef 100644 --- a/tests/sprint2/test/sp2_llnode.alpha +++ b/tests/sprint2/test/sp2_llnode.alpha @@ -9,6 +9,7 @@ function foo : T1 function bar1 : T2 function bar2 : T2 function make_list : list + make_list(a) := { [integer:orig_a; address: ret; address: curr; address: temp] if (a < 0 | a = 0) then { From 376dfdf53de4f8fcfecc81f2b6cc0e757694495a Mon Sep 17 00:00:00 2001 From: Scarlett Date: Fri, 4 Apr 2025 18:08:59 -0400 Subject: [PATCH 08/10] ready for merge! --- .../expected/sp2_carls_mistake.expected | 31 +++++ .../expected/sp2_function_types.expected | 26 ++++ .../expected/sp2_integer_binary_op.expected | 17 +++ .../expected/sp2_invalid_recop.expected | 17 +++ .../expected/sp2_invalid_release.expected | 14 +++ tests/sprint2/expected/sp2_library.expected | 36 ++++++ tests/sprint2/expected/sp2_llnode.expected | 62 ++++++++++ tests/sprint2/expected/sp2_one_line.expected | 30 +++++ .../sprint2/expected/sp2_presidence.expected | 13 ++ tests/sprint2/expected/sp2_simple.expected | 12 ++ .../sp2_valid_assignable_and_mem.expected | 18 +++ tests/sprint2/test/sp2_carls_mistake.alpha | 42 ++++--- tests/sprint2/test/sp2_function_types.alpha | 18 +-- .../sprint2/test/sp2_integer_binary_op.alpha | 23 ++-- tests/sprint2/test/sp2_invalid_recop.alpha | 7 +- tests/sprint2/test/sp2_invalid_release.alpha | 10 +- tests/sprint2/test/sp2_library.alpha | 19 +-- tests/sprint2/test/sp2_llnode.alpha | 116 +++++++++--------- tests/sprint2/test/sp2_one_line.alpha | 2 +- tests/sprint2/test/sp2_presidence.alpha | 10 +- tests/sprint2/test/sp2_simple.alpha | 4 +- .../test/sp2_valid_assignable_and_mem.alpha | 12 +- .../sp3_boolean_binary_op_typecheck.expected | 17 +++ .../sp3_boolean_unary_op_typecheck.expected | 17 +++ .../sp3_carls_second_mistake.expected | 17 +++ .../sp3_integer_binary_op_typecheck.expected | 18 +++ .../sp3_integer_unary_op_typecheck.expected | 17 +++ .../sp3_boolean_binary_op_typecheck.alpha | 16 ++- .../test/sp3_boolean_unary_op_typecheck.alpha | 14 ++- .../test/sp3_carls_second_mistake.alpha | 9 +- .../sp3_integer_binary_op_typecheck.alpha | 22 ++-- .../test/sp3_integer_unary_op_typecheck.alpha | 12 +- 32 files changed, 564 insertions(+), 134 deletions(-) create mode 100644 tests/sprint2/expected/sp2_carls_mistake.expected create mode 100644 tests/sprint2/expected/sp2_function_types.expected create mode 100644 tests/sprint2/expected/sp2_integer_binary_op.expected create mode 100644 tests/sprint2/expected/sp2_invalid_recop.expected create mode 100644 tests/sprint2/expected/sp2_invalid_release.expected create mode 100644 tests/sprint2/expected/sp2_library.expected create mode 100644 tests/sprint2/expected/sp2_llnode.expected create mode 100644 tests/sprint2/expected/sp2_one_line.expected create mode 100644 tests/sprint2/expected/sp2_presidence.expected create mode 100644 tests/sprint2/expected/sp2_simple.expected create mode 100644 tests/sprint2/expected/sp2_valid_assignable_and_mem.expected create mode 100644 tests/sprint3/expected/sp3_boolean_binary_op_typecheck.expected create mode 100644 tests/sprint3/expected/sp3_boolean_unary_op_typecheck.expected create mode 100644 tests/sprint3/expected/sp3_carls_second_mistake.expected create mode 100644 tests/sprint3/expected/sp3_integer_binary_op_typecheck.expected create mode 100644 tests/sprint3/expected/sp3_integer_unary_op_typecheck.expected diff --git a/tests/sprint2/expected/sp2_carls_mistake.expected b/tests/sprint2/expected/sp2_carls_mistake.expected new file mode 100644 index 0000000..23a8694 --- /dev/null +++ b/tests/sprint2/expected/sp2_carls_mistake.expected @@ -0,0 +1,31 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +bar2 : 001001 : : T2 : User Defined +bar1 : 001001 : : T2 : User Defined +foo : 001001 : : T1 : User Defined +arr : 001001 : : 1 -> integer : Type of Array +T2 : 001001 : : primitive function type : User Defined +T1 : 001001 : : primitive function type : User Defined +rec : 001001 : : record : elements-2 +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +w : 026000 : 001001 : rec : User Defined +result : 026000 : 001001 : integer : User Defined +arg : 026000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +r : 021000 : 001001 : integer : User Defined +s : 021000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +a : 017000 : 001001 : rec : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +x : 013000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 004000 : 001001 : integer : User Defined +x : 004000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_function_types.expected b/tests/sprint2/expected/sp2_function_types.expected new file mode 100644 index 0000000..bd1d2ce --- /dev/null +++ b/tests/sprint2/expected/sp2_function_types.expected @@ -0,0 +1,26 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : string2integer : User Defined +integer2integer2integerFunc: 001001 : : integer2integer2integer : User Defined +released : 001001 : : address2integer : User Defined +reserved : 001001 : : integer2address : User Defined +printBoolean : 001001 : : Boolean2integer : User Defined +printCharacter : 001001 : : character2integer : User Defined +printInteger : 001001 : : integer2integer : User Defined +integer2integer2integer : 001001 : : primitive function type : User Defined +address2integer : 001001 : : primitive function type : User Defined +integer2address : 001001 : : primitive function type : User Defined +Boolean2Boolean2Boolean : 001001 : : primitive function type : User Defined +character2character2Boolean: 001001 : : primitive function type : User Defined +integer2integer2Boolean : 001001 : : primitive function type : User Defined +string2integer : 001001 : : primitive function type : User Defined +Boolean2integer : 001001 : : primitive function type : User Defined +character2integer : 001001 : : primitive function type : User Defined +integer2integer : 001001 : : primitive function type : User Defined +Boolean2Boolean : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_integer_binary_op.expected b/tests/sprint2/expected/sp2_integer_binary_op.expected new file mode 100644 index 0000000..299c09d --- /dev/null +++ b/tests/sprint2/expected/sp2_integer_binary_op.expected @@ -0,0 +1,17 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +b1 : 005000 : 001001 : Boolean : User Defined +b2 : 005000 : 001001 : Boolean : User Defined +arr2 : 005000 : 001001 : address : User Defined +arr : 005000 : 001001 : address : User Defined +x : 005000 : 001001 : integer : User Defined +arg : 005000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_invalid_recop.expected b/tests/sprint2/expected/sp2_invalid_recop.expected new file mode 100644 index 0000000..5274102 --- /dev/null +++ b/tests/sprint2/expected/sp2_invalid_recop.expected @@ -0,0 +1,17 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +rec : 001001 : : record : elements-2 +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +w : 007000 : 001001 : rec : User Defined +arg : 007000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 004000 : 001001 : integer : User Defined +x : 004000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_invalid_release.expected b/tests/sprint2/expected/sp2_invalid_release.expected new file mode 100644 index 0000000..de26852 --- /dev/null +++ b/tests/sprint2/expected/sp2_invalid_release.expected @@ -0,0 +1,14 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +rec : 001001 : : record : elements-2 +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +w : 004000 : 001001 : rec : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 001000 : 001001 : integer : User Defined +x : 001000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_library.expected b/tests/sprint2/expected/sp2_library.expected new file mode 100644 index 0000000..a1318bd --- /dev/null +++ b/tests/sprint2/expected/sp2_library.expected @@ -0,0 +1,36 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : string2integer : User Defined +printBoolean : 001001 : : Boolean2integer : User Defined +printCharacter : 001001 : : character2integer : User Defined +printInteger : 001001 : : integer2integer : User Defined +address2integer : 001001 : : primitive function type : User Defined +integer2address : 001001 : : primitive function type : User Defined +BooleanXBoolean2Boolean : 001001 : : primitive function type : User Defined +characterXcharacter2Boolean: 001001 : : primitive function type : User Defined +integerXinteger2Boolean : 001001 : : primitive function type : User Defined +integerXinteger2integer : 001001 : : primitive function type : User Defined +string2integer : 001001 : : primitive function type : User Defined +Boolean2integer : 001001 : : primitive function type : User Defined +character2integer : 001001 : : primitive function type : User Defined +integer2integer : 001001 : : primitive function type : User Defined +Boolean2Boolean : 001001 : : primitive function type : User Defined +integerXinteger : 001001 : : record : elements-2 +characterXcharacter : 001001 : : record : elements-2 +BooleanXBoolean : 001001 : : record : elements-2 +string : 001001 : : 1 -> character : Type of Array +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +y : 015000 : 001001 : integer : User Defined +x : 015000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 014000 : 001001 : character : User Defined +x : 014000 : 001001 : character : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 013000 : 001001 : Boolean : User Defined +x : 013000 : 001001 : Boolean : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_llnode.expected b/tests/sprint2/expected/sp2_llnode.expected new file mode 100644 index 0000000..dfe8d53 --- /dev/null +++ b/tests/sprint2/expected/sp2_llnode.expected @@ -0,0 +1,62 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +make_list : 001001 : : list : User Defined +bar2 : 001001 : : T2 : User Defined +bar1 : 001001 : : T2 : User Defined +foo : 001001 : : T1 : User Defined +list : 001001 : : primitive function type : User Defined +llnode : 001001 : : record : elements-3 +T2 : 001001 : : primitive function type : User Defined +T1 : 001001 : : primitive function type : User Defined +rec : 001001 : : record : elements-2 +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +li : 070000 : 001001 : llnode : User Defined +w : 070000 : 001001 : rec : User Defined +result : 070000 : 001001 : integer : User Defined +arg : 070000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +r : 054000 : 001001 : integer : User Defined +s : 054000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +x : 060009 : 054000 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ + : 062028 : 060009 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ + : 055021 : 054000 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ + : 056026 : 055021 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ +a : 050000 : 001001 : rec : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +x : 046000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +temp : 017000 : 001001 : address : User Defined +curr : 017000 : 001001 : address : User Defined +ret : 017000 : 001001 : address : User Defined +orig_a : 017000 : 001001 : integer : User Defined +a : 017000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ + : 021012 : 017000 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ + : 026023 : 021012 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ + : 035020 : 026023 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ + : 031034 : 026023 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ + : 019029 : 017000 : : Empty Scope +-------------------------:--------:--------:--------------------------:------------------------------ +next : 008000 : 001001 : llnode : User Defined +val : 008000 : 001001 : integer : User Defined +prev : 008000 : 001001 : llnode : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 004000 : 001001 : integer : User Defined +x : 004000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_one_line.expected b/tests/sprint2/expected/sp2_one_line.expected new file mode 100644 index 0000000..8dde170 --- /dev/null +++ b/tests/sprint2/expected/sp2_one_line.expected @@ -0,0 +1,30 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +bar2 : 001001 : : T2 : User Defined +bar1 : 001001 : : T2 : User Defined +foo : 001001 : : T1 : User Defined +T2 : 001001 : : primitive function type : User Defined +T1 : 001001 : : primitive function type : User Defined +rec : 001001 : : record : elements-2 +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +w : 001000 : 001001 : rec : User Defined +result : 001000 : 001001 : integer : User Defined +arg : 001000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +r : 001000 : 001001 : integer : User Defined +s : 001000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +a : 001000 : 001001 : rec : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +x : 001000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 001000 : 001001 : integer : User Defined +x : 001000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_presidence.expected b/tests/sprint2/expected/sp2_presidence.expected new file mode 100644 index 0000000..70d9f83 --- /dev/null +++ b/tests/sprint2/expected/sp2_presidence.expected @@ -0,0 +1,13 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +x : 005000 : 001001 : integer : User Defined +arg : 005000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_simple.expected b/tests/sprint2/expected/sp2_simple.expected new file mode 100644 index 0000000..8d55a97 --- /dev/null +++ b/tests/sprint2/expected/sp2_simple.expected @@ -0,0 +1,12 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +arg : 005000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/expected/sp2_valid_assignable_and_mem.expected b/tests/sprint2/expected/sp2_valid_assignable_and_mem.expected new file mode 100644 index 0000000..ab5cb2a --- /dev/null +++ b/tests/sprint2/expected/sp2_valid_assignable_and_mem.expected @@ -0,0 +1,18 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +T2 : 001001 : : primitive function type : User Defined +rec : 001001 : : record : elements-2 +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +w : 008000 : 001001 : rec : User Defined +arg : 008000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ +y : 004000 : 001001 : integer : User Defined +x : 004000 : 001001 : integer : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint2/test/sp2_carls_mistake.alpha b/tests/sprint2/test/sp2_carls_mistake.alpha index 2f4c1ef..eb9a6f0 100644 --- a/tests/sprint2/test/sp2_carls_mistake.alpha +++ b/tests/sprint2/test/sp2_carls_mistake.alpha @@ -1,28 +1,34 @@ +type main: string -> integer +function entry: main + type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer -type arr : 1 -> integer +type arr: 1 -> integer -function foo : T1 -function bar1 : T2 -function bar2 : T2 +function foo: T1 +function bar1: T2 +function bar2: T2 -foo(x) := { - return x * x; +foo (x) := { + return x * x; } -bar1(a) := { - return a.x * a.y; + +bar1 (a) := { + return a.x * a.y; } + bar2 as (r,s) := { - return r * s; + return r * s; } -entry(arg) := { - [ integer: result ; rec: w] - result := foo(5); - w := reserve w; (* see types.alpha – reserve returns a value of type address, which can be assigned to array and record variables*) - w.x := 5; - w.y := 7; - result := bar1(w); (* pass w (a rec type value) to bar1 *) - result := bar2(5,7); (* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *) - return 0; + +entry (arg) := { + [ integer: result ; rec: w] + result := foo(5); + w := reserve w; (* see types.alpha – reserve returns a value of type address, which can be assigned to array and record variables*) + w.x := 5; + w.y := 7; + result := bar1(w); (* pass w (a rec type value) to bar1 *) + result := bar2(5,7); (* implicitly build a rec type value, assign 5 and 7 to fields x and y, but call them r and s *) + return 0; } diff --git a/tests/sprint2/test/sp2_function_types.alpha b/tests/sprint2/test/sp2_function_types.alpha index 509de78..62711c3 100644 --- a/tests/sprint2/test/sp2_function_types.alpha +++ b/tests/sprint2/test/sp2_function_types.alpha @@ -3,15 +3,19 @@ type integer2integer: integer -> integer type character2integer: character -> integer type Boolean2integer: Boolean -> integer type string2integer: string -> integer -function integerXinteger2integer: integerXinteger (*-> integer -type integerXinteger2Boolean: integerXinteger -> Boolean -type characterXcharacter2Boolean: characterXcharacter -> Boolean -type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean + +type integer2integer2Boolean: integer2integer -> Boolean +type character2character2Boolean: character2character -> Boolean +type Boolean2Boolean2Boolean: Boolean2Boolean -> Boolean type integer2address: integer -> address type address2integer: address -> integer +type integer2integer2integer: integer2integer -> integer + external function printInteger: integer2integer external function printCharacter: character2integer external function printBoolean: Boolean2integer -external function reserve: integer2address -external function release: address2integer -function entry: string2integer*) \ No newline at end of file +external function reserved: integer2address +external function released: address2integer + +function integer2integer2integerFunc: integer2integer2integer +function entry: string2integer \ No newline at end of file diff --git a/tests/sprint2/test/sp2_integer_binary_op.alpha b/tests/sprint2/test/sp2_integer_binary_op.alpha index 39e00a6..856224f 100644 --- a/tests/sprint2/test/sp2_integer_binary_op.alpha +++ b/tests/sprint2/test/sp2_integer_binary_op.alpha @@ -1,12 +1,17 @@ -entry(arg) := { - [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] - x := 3 + 2 * 8; - x := 3 - 2 / 8; - x := 3 * 2 % 8; - x := 3 * 2 % 8; - x := 3 % 2 * 8; - x := 3 + 2 - 8; - arr2 := 1 * reserve x; +type main: string -> integer +function entry: main + +entry (arg) := { + [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] + + x := 3 + 2 * 8; + x := 3 - 2 / 8; + x := 3 * 2 % 8; + x := 3 * 2 % 8; + x := 3 % 2 * 8; + x := 3 + 2 - 8; + + arr2 := 1 * reserve x; arr2 := release x; b2 := 3 < 2; b1 := 1 = 2; diff --git a/tests/sprint2/test/sp2_invalid_recop.alpha b/tests/sprint2/test/sp2_invalid_recop.alpha index 5ea874d..41b3a55 100644 --- a/tests/sprint2/test/sp2_invalid_recop.alpha +++ b/tests/sprint2/test/sp2_invalid_recop.alpha @@ -1,10 +1,13 @@ +type main: string -> integer +function entry: main + type rec: [integer: x; integer: y] -entry(arg) := { +entry (arg) := { [rec: w] w := reserve w; w.x := 1; w.y := 2; w.z := 3; - return 0; + return 0; } \ No newline at end of file diff --git a/tests/sprint2/test/sp2_invalid_release.alpha b/tests/sprint2/test/sp2_invalid_release.alpha index 41fbd8a..2bd645a 100644 --- a/tests/sprint2/test/sp2_invalid_release.alpha +++ b/tests/sprint2/test/sp2_invalid_release.alpha @@ -1,8 +1,8 @@ type rec: [integer: x; integer: y] -entry(arg) := { - [rec: w] - w := reserve w; - w := release (w); - return 0; +entry (arg) := { + [rec: w] + w := reserve w; + w := release (w); + return 0; } \ No newline at end of file diff --git a/tests/sprint2/test/sp2_library.alpha b/tests/sprint2/test/sp2_library.alpha index 866857c..82120be 100644 --- a/tests/sprint2/test/sp2_library.alpha +++ b/tests/sprint2/test/sp2_library.alpha @@ -1,11 +1,14 @@ -(* At compiler start-up your program should create symbol table entries for the four primitive types: - Boolean (1 byte) - character (1 byte) - integer (4 bytes) - address (8 bytes) -You should #include this file at the start of your alpha file. -Some useful types are defined below. +(* + At compiler start-up your program should create symbol table entries for the four primitive types: + Boolean (1 byte) + character (1 byte) + integer (4 bytes) + address (8 bytes) + + should #include this file at the start of your alpha file. + Some useful types are defined below. *) + type string: 1 -> character type BooleanXBoolean: [Boolean: x; Boolean: y] type characterXcharacter: [character: x; character: y] @@ -22,7 +25,9 @@ type characterXcharacter2Boolean: characterXcharacter -> Boolean type BooleanXBoolean2Boolean: BooleanXBoolean -> Boolean type integer2address: integer -> address type address2integer: address -> integer + external function printInteger: integer2integer external function printCharacter: character2integer external function printBoolean: Boolean2integer + function entry: string2integer diff --git a/tests/sprint2/test/sp2_llnode.alpha b/tests/sprint2/test/sp2_llnode.alpha index 43007ef..2011a83 100644 --- a/tests/sprint2/test/sp2_llnode.alpha +++ b/tests/sprint2/test/sp2_llnode.alpha @@ -1,3 +1,6 @@ +type main: string -> integer +function entry: main + type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer @@ -10,66 +13,69 @@ function bar1 : T2 function bar2 : T2 function make_list : list -make_list(a) := { - [integer:orig_a; address: ret; address: curr; address: temp] - if (a < 0 | a = 0) then { - return null; - } else { - ret := reserve llnode; - ret.prev := null; - ret.next := null; - ret.val := a; - while (0 < a) { - temp := reserve llnode; - temp.prev := null; - temp.next := null; - temp.val := val; - if (a = orig_a) then { - ret.next := temp; - temp.prev := ret; - curr := temp; - } else { - curr.next := temp; - temp.prev := curr; - curr := temp; - } - a := a - 1; - } - return ret; +make_list (a) := { + [integer:orig_a; address: ret; address: curr; address: temp] + + if (a < 0 | a = 0) then { + return null; + } else { + ret := reserve llnode; + ret.prev := null; + ret.next := null; + ret.val := a; + while (0 < a) { + temp := reserve llnode; + temp.prev := null; + temp.next := null; + temp.val := val; + if (a = orig_a) then { + ret.next := temp; + temp.prev := ret; + curr := temp; + } else { + curr.next := temp; + temp.prev := curr; + curr := temp; + } + a := a - 1; } + return ret; + } } +foo (x) := { + return x * x; +} -foo(x) := { - return x * x; - } -bar1(a) := { - return a.x * a.y; - } +bar1 (a) := { + return a.x * a.y; +} bar2 as (r,s) := { - if (r < s) then { - while (!(r < s)) { - r := r + 1; - } - } else { - [integer: x] - x := 0; - while (x < 10) { - r := r + s; - } + if (r < s) then { + while (!(r < s)) { + r := r + 1; } - return r * s; - } -entry(arg) := { - [ integer: result ; rec: w; llnode: li] - li := make_list(6); - result := foo(5); - w := reserve w; - w.x := 5; - w.y := 7; - result := bar1(w); - result := bar2(5,7); - - return 0; + } else { + [integer: x] + x := 0; + while (x < 10) { + r := r + s; + } + } + return r * s; +} + +entry (arg) := { + [ integer: result ; rec: w; llnode: li] + + li := make_list(6); + result := foo(5); + w := reserve w; + w.x := 5; + w.y := 7; + result := bar1(w); + result := bar2(5,7); + + return 0; } diff --git a/tests/sprint2/test/sp2_one_line.alpha b/tests/sprint2/test/sp2_one_line.alpha index 9031b5f..f1062e9 100644 --- a/tests/sprint2/test/sp2_one_line.alpha +++ b/tests/sprint2/test/sp2_one_line.alpha @@ -1 +1 @@ -type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve w; w.x := 5; w.y := 7; result := bar1(w); result := bar2(5,7); return 0; } +type main: string -> integer function entry: main type rec: [integer: x; integer: y] type T1: integer -> integer type T2: rec -> integer function foo : T1 function bar1 : T2 function bar2 : T2 foo(x) := { return x * x; } bar1(a) := { return a.x * a.y; } bar2 as (r,s) := { return r * s; } entry(arg) := { [ integer: result ; rec: w] result := foo(5); w := reserve w; w.x := 5; w.y := 7; result := bar1(w); result := bar2(5,7); return 0; } diff --git a/tests/sprint2/test/sp2_presidence.alpha b/tests/sprint2/test/sp2_presidence.alpha index 9b2ef86..2d60209 100644 --- a/tests/sprint2/test/sp2_presidence.alpha +++ b/tests/sprint2/test/sp2_presidence.alpha @@ -1,4 +1,8 @@ -entry(arg) := { - [integer:x] - x := 3 + 2 * 8; +type main: string -> integer +function entry: main + +entry (arg) := { + [integer:x] + x := 3 + 2 * 8; + return 0; } diff --git a/tests/sprint2/test/sp2_simple.alpha b/tests/sprint2/test/sp2_simple.alpha index 0b214c3..5f60c1b 100644 --- a/tests/sprint2/test/sp2_simple.alpha +++ b/tests/sprint2/test/sp2_simple.alpha @@ -1,5 +1,7 @@ +type main: string -> integer +function entry: main entry(arg) := { [int : x] - return 0; + return 0; } diff --git a/tests/sprint2/test/sp2_valid_assignable_and_mem.alpha b/tests/sprint2/test/sp2_valid_assignable_and_mem.alpha index 43c5a5f..a49c5dd 100644 --- a/tests/sprint2/test/sp2_valid_assignable_and_mem.alpha +++ b/tests/sprint2/test/sp2_valid_assignable_and_mem.alpha @@ -1,12 +1,16 @@ +type main: string -> integer +function entry: main + type rec: [integer: x; integer: y] type T2: rec -> integer entry(arg) := { - [rec: w] - w := reserve w; + [rec: w] + + w := reserve w; w.x := 1; w.y := 2; w := release w; - return 0; - + + return 0; } \ No newline at end of file diff --git a/tests/sprint3/expected/sp3_boolean_binary_op_typecheck.expected b/tests/sprint3/expected/sp3_boolean_binary_op_typecheck.expected new file mode 100644 index 0000000..299c09d --- /dev/null +++ b/tests/sprint3/expected/sp3_boolean_binary_op_typecheck.expected @@ -0,0 +1,17 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +b1 : 005000 : 001001 : Boolean : User Defined +b2 : 005000 : 001001 : Boolean : User Defined +arr2 : 005000 : 001001 : address : User Defined +arr : 005000 : 001001 : address : User Defined +x : 005000 : 001001 : integer : User Defined +arg : 005000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint3/expected/sp3_boolean_unary_op_typecheck.expected b/tests/sprint3/expected/sp3_boolean_unary_op_typecheck.expected new file mode 100644 index 0000000..299c09d --- /dev/null +++ b/tests/sprint3/expected/sp3_boolean_unary_op_typecheck.expected @@ -0,0 +1,17 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +b1 : 005000 : 001001 : Boolean : User Defined +b2 : 005000 : 001001 : Boolean : User Defined +arr2 : 005000 : 001001 : address : User Defined +arr : 005000 : 001001 : address : User Defined +x : 005000 : 001001 : integer : User Defined +arg : 005000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint3/expected/sp3_carls_second_mistake.expected b/tests/sprint3/expected/sp3_carls_second_mistake.expected new file mode 100644 index 0000000..5d0682f --- /dev/null +++ b/tests/sprint3/expected/sp3_carls_second_mistake.expected @@ -0,0 +1,17 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +a_of_s : 001001 : : 1 -> string : Type of Array +string : 001001 : : 1 -> character : Type of Array +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +many_names : 010000 : 001001 : a_of_s : User Defined +another_name : 010000 : 001001 : string : User Defined +one_name : 010000 : 001001 : string : User Defined +arg : 010000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint3/expected/sp3_integer_binary_op_typecheck.expected b/tests/sprint3/expected/sp3_integer_binary_op_typecheck.expected new file mode 100644 index 0000000..a183cf5 --- /dev/null +++ b/tests/sprint3/expected/sp3_integer_binary_op_typecheck.expected @@ -0,0 +1,18 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +a : 005000 : 001001 : character : User Defined +b1 : 005000 : 001001 : Boolean : User Defined +b2 : 005000 : 001001 : Boolean : User Defined +arr2 : 005000 : 001001 : address : User Defined +arr : 005000 : 001001 : address : User Defined +x : 005000 : 001001 : integer : User Defined +arg : 005000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint3/expected/sp3_integer_unary_op_typecheck.expected b/tests/sprint3/expected/sp3_integer_unary_op_typecheck.expected new file mode 100644 index 0000000..299c09d --- /dev/null +++ b/tests/sprint3/expected/sp3_integer_unary_op_typecheck.expected @@ -0,0 +1,17 @@ +NAME : SCOPE : PARENT : TYPE : Extra annotation +-------------------------:--------:--------:--------------------------:------------------------------ +entry : 001001 : : main : User Defined +main : 001001 : : primitive function type : User Defined +integer : 001001 : : Primitive : size-4 bytes +address : 001001 : : Primitive : size-8 bytes +character : 001001 : : Primitive : size-1 bytes +string : 001001 : : 1 -> character : Type of Array +Boolean : 001001 : : Primitive : size-1 bytes +-------------------------:--------:--------:--------------------------:------------------------------ +b1 : 005000 : 001001 : Boolean : User Defined +b2 : 005000 : 001001 : Boolean : User Defined +arr2 : 005000 : 001001 : address : User Defined +arr : 005000 : 001001 : address : User Defined +x : 005000 : 001001 : integer : User Defined +arg : 005000 : 001001 : string : User Defined +-------------------------:--------:--------:--------------------------:------------------------------ diff --git a/tests/sprint3/test/sp3_boolean_binary_op_typecheck.alpha b/tests/sprint3/test/sp3_boolean_binary_op_typecheck.alpha index 5952129..538d982 100644 --- a/tests/sprint3/test/sp3_boolean_binary_op_typecheck.alpha +++ b/tests/sprint3/test/sp3_boolean_binary_op_typecheck.alpha @@ -1,6 +1,12 @@ -entry(arg) := { - [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] - b2 := 3 < x; - b1 := arr = 2; - b1 := 6<7 & arr2=7; +type main: string -> integer +function entry: main + +entry (arg) := { + [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] + + b2 := 3 < x; + b1 := arr = 2; + b1 := 6<7 & arr2=7; + + return 0; } diff --git a/tests/sprint3/test/sp3_boolean_unary_op_typecheck.alpha b/tests/sprint3/test/sp3_boolean_unary_op_typecheck.alpha index 12db768..6a23ff6 100644 --- a/tests/sprint3/test/sp3_boolean_unary_op_typecheck.alpha +++ b/tests/sprint3/test/sp3_boolean_unary_op_typecheck.alpha @@ -1,5 +1,11 @@ -entry(arg) := { - [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] - b2 := !(3 < 2); - b1 := !5; +type main: string -> integer +function entry: main + +entry (arg) := { + [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] + + b2 := !(3 < 2); + b1 := !5; + + return 0; } diff --git a/tests/sprint3/test/sp3_carls_second_mistake.alpha b/tests/sprint3/test/sp3_carls_second_mistake.alpha index 6d1d614..ddb58a4 100644 --- a/tests/sprint3/test/sp3_carls_second_mistake.alpha +++ b/tests/sprint3/test/sp3_carls_second_mistake.alpha @@ -1,10 +1,14 @@ +type main: string -> integer +function entry: main + type string: 1 -> character type a_of_s: 1 -> string (* maybe some other type definitions *) -entry(arg) := { +entry (arg) := { [ string: one_name; string: another_name; a_of_s: many_names ] + one_name := "a string literal"; another_name := reserve another_name(4); (* reserve space for an an array of character, with 4 members *) another_name(0) := 'C'; @@ -20,6 +24,7 @@ entry(arg) := { many_names(2)(2) := 'r'; many_names(2)(3) := 't'; many_names(2)(4) := 'h'; - 0(2)(5) := 'o'; + many_names(2)(5) := 'o'; + return 0; } \ No newline at end of file diff --git a/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha b/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha index 5b13147..b042e5f 100644 --- a/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha +++ b/tests/sprint3/test/sp3_integer_binary_op_typecheck.alpha @@ -1,9 +1,15 @@ -entry(arg) := { - [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1; character : a] - x := 3 + 2 * 8; - x := 3 - 2 / 8; - x := a * 2 % 8; - b2 := 3 * 2 % 8; - x := 3 % 2 * 8; - x := 3 + arr - 8; +type main: string -> integer +function entry: main + +entry (arg) := { + [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1; character : a] + + x := 3 + 2 * 8; + x := 3 - 2 / 8; + x := a * 2 % 8; + b2 := 3 * 2 % 8; + x := 3 % 2 * 8; + x := 3 + arr - 8; + + return 0; } diff --git a/tests/sprint3/test/sp3_integer_unary_op_typecheck.alpha b/tests/sprint3/test/sp3_integer_unary_op_typecheck.alpha index 31e01a7..7ab6817 100644 --- a/tests/sprint3/test/sp3_integer_unary_op_typecheck.alpha +++ b/tests/sprint3/test/sp3_integer_unary_op_typecheck.alpha @@ -1,6 +1,12 @@ -entry(arg) := { - [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] - x := -8; +type main: string -> integer +function entry: main + +entry (arg) := { + [integer:x; address: arr; address: arr2; Boolean : b2; Boolean : b1] + + x := -8; x := -b1; b2 := -x; + + return 0; } From e56606941872188e91df0c2dcfaebff2f8a69849 Mon Sep 17 00:00:00 2001 From: Annie Date: Fri, 4 Apr 2025 18:43:53 -0400 Subject: [PATCH 09/10] updated to allow -tc and -debug --- Makefile | 4 ++-- src/runner.c | 29 +++++++++++++++++++++++------ test.sh | 20 ++++++++++---------- 3 files changed, 35 insertions(+), 18 deletions(-) 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/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 From 0b33ea4dea5108e6cf431614e9d90da0eb8d7be3 Mon Sep 17 00:00:00 2001 From: Annie Date: Fri, 4 Apr 2025 18:49:04 -0400 Subject: [PATCH 10/10] added -debug option to -help output --- src/runner.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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";