This commit is contained in:
Scarlett
2025-03-28 23:33:08 -04:00
parent aebb831fe8
commit d587ed9f3b
6 changed files with 383 additions and 289 deletions

View File

@ -37,7 +37,7 @@ debug: clean compiler
test: test:
chmod +x ./check.sh chmod +x ./check.sh
chmod +x ./test.sh chmod +x ./test.sh
$(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) || true);) $(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) -debug || true);)
./test.sh sp2 ./test.sh sp2
./test.sh sp3 ./test.sh sp3
./test.sh sp4 ./test.sh sp4
@ -46,7 +46,7 @@ test:
test-s1: test-s1:
chmod +x ./check.sh chmod +x ./check.sh
chmod +x ./test.sh chmod +x ./test.sh
$(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) || true);) $(foreach test, $(TESTS-S1), (./$(EXE) -tok $(test) -debug || true);)
./check.sh sp1 ./check.sh sp1
test-s2: test-s2:

View File

@ -9,8 +9,19 @@ extern TableNode *addr;
extern TableNode *chara; extern TableNode *chara;
extern TableNode *stri; extern TableNode *stri;
extern TableNode *boo; extern TableNode *boo;
extern bool DEBUG;
extern char * COLOR_YELLOW;
extern char * COLOR_BLUE;
extern char * COLOR_WHITE;
int main(int argc, char *argv[]) { 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) { if (argc == 1) {
fprintf(stderr, INVALID); fprintf(stderr, INVALID);
return -1; return -1;

View File

@ -107,7 +107,8 @@ AdInfo *CreatePrimitiveInfo(int size) {
// only gets the size of a primitive type // only gets the size of a primitive type
int getPrimSize(TableNode *definition) { int getPrimSize(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL entry to getPrimSize function. Invalid.\n"); printf(
"passed an NULL entry to getPrimSize function. Invalid.\n");
return -1; return -1;
} }
if (definition->additionalinfo == NULL) { if (definition->additionalinfo == NULL) {
@ -135,7 +136,8 @@ int getPrimSize(TableNode *definition) {
// calculated at runtime so bounds checking only needs to be done then // calculated at runtime so bounds checking only needs to be done then
AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) { AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) {
if (type == NULL || type == undefined) { if (type == NULL || type == undefined) {
printf("passed a NULL or undefined type reference to CreateArrayInfo. Invalid.\n"); printf("passed a NULL or undefined type reference to "
"CreateArrayInfo. Invalid.\n");
return NULL; return NULL;
} }
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
@ -149,7 +151,8 @@ AdInfo *CreateArrayInfo(int dim, /*int* sizes,*/ TableNode *type) {
// This gets the number of dimensions from array info // This gets the number of dimensions from array info
int getNumArrDim(TableNode *definition) { int getNumArrDim(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getNumArrDim function. Invalid.\n"); printf("passed an NULL or undefined entry to getNumArrDim "
"function. Invalid.\n");
return -1; return -1;
} }
if (strcmp(getType(definition), "array") != 0) { if (strcmp(getType(definition), "array") != 0) {
@ -162,7 +165,8 @@ int getNumArrDim(TableNode *definition) {
// the entry of that type // the entry of that type
TableNode *getArrType(TableNode *definition) { TableNode *getArrType(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getArrType function. Invalid.\n"); printf("passed an NULL or undefined entry to getArrType "
"function. Invalid.\n");
return NULL; return NULL;
} }
if (strcmp(getType(definition), "array") != 0) { if (strcmp(getType(definition), "array") != 0) {
@ -189,7 +193,8 @@ AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) {
// anyways. // anyways.
int getRecLength(TableNode *definition) { int getRecLength(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getRecLength function. Invalid.\n"); printf("passed an NULL or undefined entry to getRecLength "
"function. Invalid.\n");
return -1; return -1;
} }
if (strcmp(getType(definition), "record") != 0) { if (strcmp(getType(definition), "record") != 0) {
@ -201,7 +206,8 @@ int getRecLength(TableNode *definition) {
// This gets the array. Needs to up be updated to get the scope instead // This gets the array. Needs to up be updated to get the scope instead
SymbolTable *getRecList(TableNode *definition) { SymbolTable *getRecList(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getRecList function. Invalid.\n"); printf("passed an NULL or undefined entry to getRecList "
"function. Invalid.\n");
return NULL; return NULL;
} }
if (strcmp(getType(definition), "record") != 0) { if (strcmp(getType(definition), "record") != 0) {
@ -255,7 +261,8 @@ AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular) {
// out in table if needed) // out in table if needed)
int getStartLine(TableNode *definition) { int getStartLine(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getStartLine function. Invalid.\n"); printf("passed an NULL or undefined entry to getStartLine "
"function. Invalid.\n");
return -1; return -1;
} }
if (strcmp(getType(definition), "primitive function") != 0) { if (strcmp(getType(definition), "primitive function") != 0) {
@ -268,7 +275,8 @@ int getStartLine(TableNode *definition) {
TableNode *setStartLine(TableNode *tn, int start) { TableNode *setStartLine(TableNode *tn, int start) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
printf("passing in a NULL or undefined entry to setStartLine. invalid\n"); printf("passing in a NULL or undefined entry to setStartLine. "
"invalid\n");
return undefined; return undefined;
} }
tn->additionalinfo->FunDecAdInfo->startlinenumber = start; tn->additionalinfo->FunDecAdInfo->startlinenumber = start;
@ -278,7 +286,8 @@ TableNode* setStartLine(TableNode* tn, int start){
// not used or used. // not used or used.
bool getAsKeyword(TableNode *definition) { bool getAsKeyword(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getAsKeyword function. Invalid.\n"); printf("passed an NULL or undefined entry to getAsKeyword "
"function. Invalid.\n");
return false; return false;
} }
if (strcmp(getType(definition), "primitive function") != 0) { if (strcmp(getType(definition), "primitive function") != 0) {
@ -291,7 +300,8 @@ bool getAsKeyword(TableNode *definition) {
TableNode *setAsKeyword(TableNode *tn, bool as) { TableNode *setAsKeyword(TableNode *tn, bool as) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
printf("passing in a NULL or undefined entry to setAsKeyword. invalid\n"); printf("passing in a NULL or undefined entry to setAsKeyword. "
"invalid\n");
return undefined; return undefined;
} }
tn->additionalinfo->FunDecAdInfo->regularoras = as; tn->additionalinfo->FunDecAdInfo->regularoras = as;
@ -301,11 +311,13 @@ TableNode* setAsKeyword(TableNode* tn, bool as){
// stores the type of a function (parameter type and return type) // stores the type of a function (parameter type and return type)
AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) { AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
if (parameter == NULL || parameter == undefined) { if (parameter == NULL || parameter == undefined) {
printf("passed a NULL or undefined parameter to CreateFunctionTypeInfo. Invalid.\n"); printf("passed a NULL or undefined parameter to "
"CreateFunctionTypeInfo. Invalid.\n");
return NULL; return NULL;
} }
if (returntype == NULL || returntype == undefined) { if (returntype == NULL || returntype == undefined) {
printf("passed a NULL or undefined return type to CreateFunctionTypeInfo. Invalid.\n"); printf("passed a NULL or undefined return type to "
"CreateFunctionTypeInfo. Invalid.\n");
return NULL; return NULL;
} }
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
@ -318,7 +330,8 @@ AdInfo *CreateFunctionTypeInfo(TableNode *parameter, TableNode *returntype) {
// returns parameter type of a function // returns parameter type of a function
TableNode *getParameter(TableNode *definition) { TableNode *getParameter(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getParameter function. Invalid.\n"); printf("passed an NULL or undefined entry to getParameter "
"function. Invalid.\n");
return undefined; return undefined;
} }
if (strcmp(getType(definition), "primitive function type") != 0) { if (strcmp(getType(definition), "primitive function type") != 0) {
@ -331,7 +344,8 @@ TableNode *getParameter(TableNode *definition) {
// returns return type of a function // returns return type of a function
TableNode *getReturn(TableNode *definition) { TableNode *getReturn(TableNode *definition) {
if (definition == NULL || definition == undefined) { if (definition == NULL || definition == undefined) {
printf("passed an NULL or undefined entry to getReturn function. Invalid.\n"); printf("passed an NULL or undefined entry to getReturn "
"function. Invalid.\n");
return NULL; return NULL;
} }
if (strcmp(getType(definition), "primitive function type") != 0) { if (strcmp(getType(definition), "primitive function type") != 0) {
@ -450,7 +464,8 @@ SymbolTable *init(SymbolTable *start) {
undefined->additionalinfo = NULL; undefined->additionalinfo = NULL;
undefined->next = NULL; undefined->next = NULL;
//Undefined_function_type_info = CreateFunctionTypeInfo(undefined, undefined); // Undefined_function_type_info = CreateFunctionTypeInfo(undefined,
// undefined);
integ->theType = prime; integ->theType = prime;
addr->theType = prime; addr->theType = prime;
@ -489,15 +504,18 @@ TableNode* funtypeprime;
*/ */
TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) { TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
printf("passed in an invalid table node to modify (NULL or undefined).\n"); printf("passed in an invalid table node to modify (NULL or "
"undefined).\n");
return undefined; return undefined;
} }
if (type == NULL || type == undefined) { if (type == NULL || type == undefined) {
printf("passed in a NULL or undefined type reference to populate a table node. Invalid.\n"); printf("passed in a NULL or undefined type reference to "
"populate a table node. Invalid.\n");
return undefined; return undefined;
} }
if (info == NULL) { if (info == NULL) {
printf("passed in a NULL info reference to populate a table node. Invalid.\n"); printf("passed in a NULL info reference to populate a table "
"node. Invalid.\n");
return undefined; return undefined;
} }
tn->theType = type; tn->theType = type;
@ -512,7 +530,8 @@ int getAdInfoType(TableNode* tn){
return -1; return -1;
} }
if (tn->theType == NULL || tn->theType == undefined) { if (tn->theType == NULL || tn->theType == undefined) {
printf("Entry being passed in has a null or undefined reference for theType. Invalid.\n"); printf("Entry being passed in has a null or undefined "
"reference for theType. Invalid.\n");
return -1; return -1;
} }
if (strcmp(getName(tn), getName(integ)) == 0) { if (strcmp(getName(tn), getName(integ)) == 0) {
@ -541,13 +560,13 @@ int getAdInfoType(TableNode* tn){
} }
if (strcmp(getName(tn), getName(undefined)) == 0) { if (strcmp(getName(tn), getName(undefined)) == 0) {
return TYPE_UNDEFINED; return TYPE_UNDEFINED;
} } else {
else{
return TYPE_FUNCTION_DECLARATION; return TYPE_FUNCTION_DECLARATION;
} }
} }
TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, AdInfo *ad) { TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
AdInfo *ad) {
if (table == NULL) { if (table == NULL) {
printf("Null reference to table"); printf("Null reference to table");
@ -562,7 +581,8 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, AdInfo *
} }
*/ */
if (typeOf == NULL || typeOf == undefined) { if (typeOf == NULL || typeOf == undefined) {
printf("This is not pointing to a proper definition (either NULL or undefined)\n"); printf("This is not pointing to a proper definition (either "
"NULL or undefined)\n");
return undefined; return undefined;
} }
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode)); TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
@ -589,11 +609,13 @@ char *getType(TableNode *tn) {
printf("type of entry is currently NULL or undefined type \n"); printf("type of entry is currently NULL or undefined type \n");
return getName(undefined); return getName(undefined);
} }
return tn->theType->theName; } return tn->theType->theName;
}
char *getName(TableNode *tn) { char *getName(TableNode *tn) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
//printf("passed a NULL or undefined table entry to getName\n"); // printf("passed a NULL or undefined table entry to
// getName\n");
return undefined->theName; return undefined->theName;
} }
if (tn->theName == NULL) { if (tn->theName == NULL) {
@ -605,27 +627,34 @@ char *getName(TableNode *tn) {
int getLine(SymbolTable *st) { int getLine(SymbolTable *st) {
if (st == NULL) { if (st == NULL) {
printf("passed a NULL symbol table to getLine function. Invalid.\n"); printf("passed a NULL symbol table to getLine function. "
"Invalid.\n");
return -1; return -1;
} }
return st->Line_Number; } return st->Line_Number;
}
int getColumn(SymbolTable *st) { int getColumn(SymbolTable *st) {
if (st == NULL) { if (st == NULL) {
printf("passed a NULL symbol table to getColumn function. Invalid.\n"); printf("passed a NULL symbol table to getColumn function. "
"Invalid.\n");
return -1; return -1;
} }
return st->Column_Number; } return st->Column_Number;
}
TableNode *addName(TableNode *tn, char *str) { TableNode *addName(TableNode *tn, char *str) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
printf("passed a Null or undefined table node to the addName function. Invalid./n"); printf("passed a Null or undefined table node to the addName "
"function. Invalid./n");
return undefined; return undefined;
} }
if (tn->theName != NULL) { if (tn->theName != NULL) {
printf("Name doesn't look like it is empty before you change. Are you sure you need to update name?/n"); printf("Name doesn't look like it is empty before you change. "
"Are you sure you need to update name?/n");
return undefined; return undefined;
} }
if (str == NULL) { if (str == NULL) {
printf("passed a NULL string to the addName function. Invalid./n"); printf(
"passed a NULL string to the addName function. Invalid./n");
return undefined; return undefined;
} }
tn->theName = str; tn->theName = str;
@ -634,7 +663,8 @@ TableNode* addName(TableNode *tn, char* str){
SymbolTable *setLineNumber(SymbolTable *st, int line) { SymbolTable *setLineNumber(SymbolTable *st, int line) {
if (st == NULL) { if (st == NULL) {
printf("passed a Null Symbol Table to the setLineNumber function. Invalid./n"); printf("passed a Null Symbol Table to the setLineNumber "
"function. Invalid./n");
return st; return st;
} }
st->Line_Number = line; st->Line_Number = line;
@ -643,7 +673,8 @@ SymbolTable* setLineNumber(SymbolTable *st,int line){
SymbolTable *setColumnNumber(SymbolTable *st, int column) { SymbolTable *setColumnNumber(SymbolTable *st, int column) {
if (st == NULL) { if (st == NULL) {
printf("passed a Null Symbol Table to the setColumnNumber function. Invalid./n"); printf("passed a Null Symbol Table to the setColumnNumber "
"function. Invalid./n");
return st; return st;
} }
st->Line_Number = column; st->Line_Number = column;
@ -708,8 +739,9 @@ TableNode *look_up(SymbolTable *table, char *x) {
if (ret != NULL && ret != undefined) { if (ret != NULL && ret != undefined) {
return ret; return ret;
} }
printf("could not find %s in scope that started at line %d and column %d so moving up a scope\n" printf("could not find %s in scope that started at line %d and column "
,x,getLine(table),getColumn(table)); "%d so moving up a scope\n",
x, getLine(table), getColumn(table));
return look_up(table->Parent_Scope, x); return look_up(table->Parent_Scope, x);
} }
/* /*
@ -795,16 +827,24 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : : %-21d -> %-21s: %-28s\n", "%-17s: %06d : : %-21d -> "
"%-21s: %-28s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
entrie->additionalinfo->ArrayAdInfo->numofdimensions, entrie->additionalinfo->ArrayAdInfo
entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, ->numofdimensions,
entrie->additionalinfo->ArrayAdInfo
->typeofarray->theName,
"Type of Array"); "Type of Array");
} else { } else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n", fprintf(file_ptr,
entrie->theName, current_scope, parant_scope, "%-17s: %06d : %06d : %-21d -> %-21s: "
entrie->additionalinfo->ArrayAdInfo->numofdimensions, "%-28s\n",
entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, entrie->theName, current_scope,
parant_scope,
entrie->additionalinfo->ArrayAdInfo
->numofdimensions,
entrie->additionalinfo->ArrayAdInfo
->typeofarray->theName,
"Type of Array"); "Type of Array");
} }
} }
@ -812,29 +852,38 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : :%-21s: elements-%-28d\n", "%-17s: %06d : :%-21s: "
"elements-%-28d\n",
entrie->theName, current_scope, entrie->theName, current_scope,
"record", "record",
entrie->additionalinfo->RecAdInfo->numofelements); entrie->additionalinfo->RecAdInfo
->numofelements);
} else { } else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n", fprintf(file_ptr,
entrie->theName, current_scope, parant_scope, "%-17s: %06d : %06d : %-21s: "
"record", "elements-%-28d\n",
entrie->additionalinfo->RecAdInfo->numofelements); entrie->theName, current_scope,
parant_scope, "record",
entrie->additionalinfo->RecAdInfo
->numofelements);
} }
} }
if (getAdInfoType(entrie) == TYPE_PRIMITIVE) { if (getAdInfoType(entrie) == TYPE_PRIMITIVE) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(
"%-17s: %06d : :%-21s: size-%-28d bytes\n", file_ptr,
entrie->theName, current_scope, "%-17s: %06d : :%-21s: size-%-28d "
"Primitive", "bytes\n",
entrie->theName, current_scope, "Primitive",
entrie->additionalinfo->PrimAdInfo->size); entrie->additionalinfo->PrimAdInfo->size);
} else { } else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n", fprintf(
entrie->theName, current_scope, parant_scope, file_ptr,
"Primitive", "%-17s: %06d : %06d : %-21s: size-%-28d "
"bytes\n",
entrie->theName, current_scope,
parant_scope, "Primitive",
entrie->additionalinfo->PrimAdInfo->size); entrie->additionalinfo->PrimAdInfo->size);
} }
} }
@ -842,16 +891,24 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (parant_scope == 0) { if (parant_scope == 0) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : : %-21s -> %-21s: %-28s\n", "%-17s: %06d : : %-21s -> "
"%-21s: %-28s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
entrie->additionalinfo->FunTypeAdInfo->parameter->theName, entrie->additionalinfo->FunTypeAdInfo
entrie->additionalinfo->FunTypeAdInfo->returntype->theName, ->parameter->theName,
entrie->additionalinfo->FunTypeAdInfo
->returntype->theName,
"Type of Function"); "Type of Function");
} else { } else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n", fprintf(file_ptr,
entrie->theName, current_scope, parant_scope, "%-17s: %06d : %06d : %-21s -> %-21s: "
entrie->additionalinfo->FunTypeAdInfo->parameter->theName, "%-28s\n",
entrie->additionalinfo->FunTypeAdInfo->returntype->theName, entrie->theName, current_scope,
parant_scope,
entrie->additionalinfo->FunTypeAdInfo
->parameter->theName,
entrie->additionalinfo->FunTypeAdInfo
->returntype->theName,
"Type of Function"); "Type of Function");
} }
} }
@ -861,12 +918,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : :%-21s: %-28s\n", "%-17s: %06d : :%-21s: %-28s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
getType(entrie), getType(entrie), "Function");
"Function");
} else { } else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", fprintf(file_ptr,
entrie->theName, current_scope, parant_scope, "%-17s: %06d : %06d : %-21s: %-28s\n",
getType(entrie), entrie->theName, current_scope,
parant_scope, getType(entrie),
"Function"); "Function");
} }
} }
@ -876,12 +933,12 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
fprintf(file_ptr, fprintf(file_ptr,
"%-17s: %06d : :%-21s: %-28s\n", "%-17s: %06d : :%-21s: %-28s\n",
entrie->theName, current_scope, entrie->theName, current_scope,
"undefined", "undefined", "undefined entry");
"undefined entry");
} else { } else {
fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", fprintf(file_ptr,
entrie->theName, current_scope, parant_scope, "%-17s: %06d : %06d : %-21s: %-28s\n",
"undefined", entrie->theName, current_scope,
parant_scope, "undefined",
"undefined entry"); "undefined entry");
} }
} }
@ -941,7 +998,8 @@ SymbolTable *removeEntry(SymbolTable *scope, char *search) {
return scope; return scope;
} }
//almost certainly don't need to use the below function since type checking happens by passing types up the grammar // 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) { bool typeCheck(char *firstID, char *secondID) {
TableNode *entry1 = look_up(cur, firstID); TableNode *entry1 = look_up(cur, firstID);
@ -1002,3 +1060,28 @@ TableNode *getNextEntry(TableNode *tn) { return tn->next; }
return 0; return 0;
} }
*/ */
char *getLineStr();
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;
char *getLineStr(int d) {
char *new_text = malloc(100);
sprintf(new_text, "%s[%d]%s ", COLOR_DARKGRAY, d, COLOR_WHITE);
return new_text;
}

18
test.sh
View File

@ -48,7 +48,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then if [ -f "$file" ]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc switchfunc
fi fi
@ -60,7 +60,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then if [ -f "$file" ]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc switchfunc
fi fi
@ -72,7 +72,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then if [ -f "$file" ]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc switchfunc
fi fi
@ -84,7 +84,7 @@ if [ $# -eq 0 ]; then
if [ -f "$file" ]; then if [ -f "$file" ]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n${WHITE}" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n${WHITE}"
switchfunc switchfunc
fi fi
@ -106,7 +106,7 @@ else
if [ -f "$1" ]; then if [ -f "$1" ]; then
filename=$(basename -- "$1") filename=$(basename -- "$1")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$1" ./alpha -st "$1" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}"
exit 1 exit 1
else else
@ -121,7 +121,7 @@ else
if [[ "$file" == *"$1"* ]]; then if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc switchfunc
fi fi
@ -132,7 +132,7 @@ else
if [[ "$file" == *"$1"* ]]; then if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc switchfunc
fi fi
@ -143,7 +143,7 @@ else
if [[ "$file" == *"$1"* ]]; then if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc switchfunc
fi fi
@ -154,7 +154,7 @@ else
if [[ "$file" == *"$1"* ]]; then if [[ "$file" == *"$1"* ]]; then
filename=$(basename -- "$file") filename=$(basename -- "$file")
echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}" echo -e "- ${SWITCH}Running test: ${LIGHTBLUE}$filename ${SWITCH}-----${WHITE}"
./alpha -st "$file" ./alpha -st "$file" -debug
echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n" echo -e "${SWITCH}----- End of test: ${LIGHTBLUE}$filename ${SWITCH}-${WHITE}\n"
switchfunc switchfunc
fi fi