printdebug function with line and file names

This commit is contained in:
Scarlett
2025-03-31 11:43:30 -04:00
parent d587ed9f3b
commit be311c7418
3 changed files with 206 additions and 181 deletions

View File

@ -122,29 +122,29 @@ prototype:
definition: definition:
TYPE ID COLON { TYPE ID COLON {
printf("Currently see a record definition for %s\n", $<words>2); printdebug("Currently see a record definition for %s", $<words>2);
tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0))); tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0)));
if (table_lookup(getAncestor(cur), $2) == NULL) { if (table_lookup(getAncestor(cur), $2) == NULL) {
printf("rec not found \n"); printdebug("rec not found ");
} }
}dblock { setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur)); }dblock { setRecSize(table_lookup(getParent(cur), $2), getRecSize(cur));
cur = getParent(cur);} cur = getParent(cur);}
| TYPE ID COLON C_INTEGER ARROW id_or_types | TYPE ID COLON C_INTEGER ARROW id_or_types
{printf("Currently see a array definition of name %s,storing type %s, of dimensions %d\n", {printdebug("Currently see a array definition of name %s,storing type %s, of dimensions %d",
$2, $6, $4); $2, $6, $4);
CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));} CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));}
| function_declaration | function_declaration
| TYPE ID COLON id_or_types ARROW id_or_types { | TYPE ID COLON id_or_types ARROW id_or_types {
printf("Currently see a function type definition of name %s,parameter type %s, of return type %s\n", printdebug("Currently see a function type definition of name %s,parameter type %s, of return type %s",
$2, $4, $6); $2, $4, $6);
CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6))); CreateEntry(cur,funtypeprime,$2,CreateFunctionTypeInfo(table_lookup(cur,$4),table_lookup(cur,$6)));
} }
| ID { | ID {
TableNode *node = table_lookup(getAncestor(cur), $<words>1); TableNode *node = table_lookup(getAncestor(cur), $<words>1);
if (node == NULL) { if (node == NULL) {
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); 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){
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
} }
else { else {
setStartLine(node, @1.first_line); setStartLine(node, @1.first_line);
@ -152,19 +152,19 @@ TYPE ID COLON {
} }
cur = CreateScope(cur, 0, 0); cur = CreateScope(cur, 0, 0);
} L_PAREN ID { } L_PAREN ID {
printf("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s\n", printdebug("Currently see a function definition taking only one parameter (no as) of name %s and argument name %s",
$1,$4); $1,$4);
CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL); CreateEntry(cur, getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))), $<words>4, NULL);
}R_PAREN ASSIGN sblock }R_PAREN ASSIGN sblock
| ID { | ID {
TableNode *node = table_lookup(getAncestor(cur), $<words>1); TableNode *node = table_lookup(getAncestor(cur), $<words>1);
if (node == NULL) { if (node == NULL) {
printf("null check\n"); printdebug("null check");
} }
if (node == NULL) { if (node == NULL) {
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); 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){
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); printdebug("function not declared at line %d, column %d", @1.first_line, @1.first_column);
} }
else { else {
setStartLine(node, @1.first_line); setStartLine(node, @1.first_line);
@ -174,15 +174,15 @@ TYPE ID COLON {
}AS L_PAREN { }AS L_PAREN {
TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1)))); TableNode *parameter = getParameter(table_lookup(getAncestor(cur), getType(table_lookup(getAncestor(cur), $<words>1))));
if (parameter == NULL) { if (parameter == NULL) {
printf("function defined with as, but parameter is not a record at line %d, column %d\n", @1.first_line, @1.first_column); printdebug("function defined with as, but parameter is not a record at line %d, column %d", @1.first_line, @1.first_column);
}else if(getAdInfoType(parameter) != TYPE_RECORD){ }else if(getAdInfoType(parameter) != TYPE_RECORD){
printf("function defined with as, but parameter is not a record at line %d, column %d\n", @1.first_line, @1.first_column); printdebug("function defined with as, but parameter is not a record at line %d, column %d", @1.first_line, @1.first_column);
}else { }else {
for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){ for (TableNode* entry = getFirstEntry(getRecList(parameter)); entry!= NULL; entry = getNextEntry(entry)){
CreateEntry(cur, entry, NULL, NULL); CreateEntry(cur, entry, NULL, NULL);
} }
} }
} idlist {printf("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d\n", } idlist {printdebug("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d",
$1,$6);} R_PAREN ASSIGN sblock $1,$6);} R_PAREN ASSIGN sblock
; ;
@ -200,7 +200,7 @@ idlist:
entry = getNextEntry(entry); entry = getNextEntry(entry);
} }
if (getNextEntry(entry) == NULL) { if (getNextEntry(entry) == NULL) {
printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column); printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
} }
addName(entry, $<words>1); addName(entry, $<words>1);
} COMMA idlist {$$ = $<integ>3 + 1;} } COMMA idlist {$$ = $<integ>3 + 1;}
@ -211,7 +211,7 @@ idlist:
entry = getNextEntry(entry); entry = getNextEntry(entry);
} }
if (getNextEntry(entry) != NULL) { if (getNextEntry(entry) != NULL) {
printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column); printdebug("too many parameters at line %d column %d", @1.first_line, @1.first_column);
} }
addName(entry, $<words>1); addName(entry, $<words>1);
$$ = 1; $$ = 1;
@ -222,7 +222,7 @@ idlist:
sblock: sblock:
L_BRACE {if (getLine(cur) != 0 && getColumn(cur))cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE L_BRACE {if (getLine(cur) != 0 && getColumn(cur))cur = CreateScope(cur,@1.first_line,@1.first_column);} statement_list {cur = getParent(cur);} R_BRACE
| L_BRACE {if (getLine(cur) != 0 && getColumn(cur))cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock | L_BRACE {if (getLine(cur) != 0 && getColumn(cur))cur = CreateScope(cur,@1.first_line,@1.first_column);} dblock
{printf("seen sblock with dblock\n");} statement_list {cur = getParent(cur);} R_BRACE {printdebug("seen sblock with dblock");} statement_list {cur = getParent(cur);} R_BRACE
; ;
dblock: dblock:
@ -234,14 +234,14 @@ declaration_list:
; ;
declaration: declaration:
id_or_types COLON ID {printf("ID/TYPE: %s, ID: %s\n", $<words>1, $<words>3) ; CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); } id_or_types COLON ID {printdebug("ID/TYPE: %s, ID: %s", $<words>1, $<words>3) ; CreateEntry(cur,table_lookup(getAncestor(cur),$<words>1),$<words>3,NULL); }
; ;
id_or_types: id_or_types:
ID {printf("string of id is %s in ID pattern of id_or_type rule.\n"); $$ = $1;} ID {printdebug("string of id is %s in ID pattern of id_or_type rule."); $$ = $1;}
//{printf("string of id is %s in ID pattern of id_or_type rule. Type passed up the tree is %s.\n",$1,getType(look_up(cur,$1))); $$ = getType(look_up(cur,$1));} //{printdebug("string of id is %s in ID pattern of id_or_type rule. Type passed up the tree is %s.",$1,getType(look_up(cur,$1))); $$ = getType(look_up(cur,$1));}
| types {printf("string of type is %s in types pattern of id_or_type rule.\n",$1);} {$$ = $1;} | types {printdebug("string of type is %s in types pattern of id_or_type rule.",$1);} {$$ = $1;}
//{printf("string of type is %s in types pattern of id_or_type rule. That is passed up the tree.\n",$<words>1);} {$$ = $<words>1;} //{printdebug("string of type is %s in types pattern of id_or_type rule. That is passed up the tree.",$<words>1);} {$$ = $<words>1;}
; ;
; ;
@ -255,13 +255,13 @@ statement_list:
compound_statement: compound_statement:
WHILE L_PAREN expression R_PAREN sblock WHILE L_PAREN expression R_PAREN sblock
| IF L_PAREN expression R_PAREN THEN sblock ELSE sblock | IF L_PAREN expression R_PAREN THEN sblock ELSE sblock
| sblock //{printf("seen a compound statement rule\n");} | sblock //{printdebug("seen a compound statement rule");}
; ;
simple_statement: simple_statement:
assignable ASSIGN expression {if(strcmp($1, $3) == 0){ assignable ASSIGN expression {if(strcmp($1, $3) == 0){
} else { } else {
printf("Mismatch at line %d and column%d\n", @2.first_line, @2.first_column); printdebug("Mismatch at line %d and column%d", @2.first_line, @2.first_column);
}} }}
| RETURN expression | RETURN expression
@ -278,77 +278,77 @@ rec_op :
DOT DOT
expression: expression:
constant {printf("constant expression\n");} {$$ = $<words>1;} constant {printdebug("constant expression");} {$$ = $<words>1;}
| SUB_OR_NEG expression %prec UMINUS {printf("negative expression\n");if(strcmp($2,"integer") != 0) | SUB_OR_NEG expression %prec UMINUS {printdebug("negative expression");if(strcmp($2,"integer") != 0)
{printf("cant negate something not an integer at line %d and column %d\n",@2.first_line,@2.first_column); {printdebug("cant negate something not an integer at line %d and column %d",@2.first_line,@2.first_column);
$$=strdup("undefined");}else{$$=$2;}} $$=strdup("undefined");}else{$$=$2;}}
| NOT expression {printf("not expression\n"); if(strcmp($2,"Boolean")==0){$$=$2;}else{$$=strdup("undefined"); | NOT expression {printdebug("not expression"); if(strcmp($2,"Boolean")==0){$$=$2;}else{$$=strdup("undefined");
printf("mismatch at line %d and column %d. Invalid type being negated is %s\n", printdebug("mismatch at line %d and column %d. Invalid type being negated is %s",
@1.first_line,@1.first_column,$2);}} @1.first_line,@1.first_column,$2);}}
| expression ADD expression | expression ADD expression
{printf("add expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("integer");} {printdebug("add expression");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("integer");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression SUB_OR_NEG expression | expression SUB_OR_NEG expression
{printf("sub or neg expression\n");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("integer");} {printdebug("sub or neg expression");if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("integer");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression MUL expression | expression MUL expression
{printf("multiply expression\n"); {printdebug("multiply expression");
if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("integer");} if(strcmp($1,$3)==0 &&strcmp($1,"integer")==0){$$=strdup("integer");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression DIV expression | expression DIV expression
{printf("divide expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("integer");} {printdebug("divide expression");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("integer");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression REM expression | expression REM expression
{printf("remainder expression\n");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("integer");} {printdebug("remainder expression");if(strcmp($1,$3)==0 && strcmp($1,"integer")==0){$$=strdup("integer");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression AND expression | expression AND expression
{printf("AND expression\n");if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0){$$=strdup("Boolean");} {printdebug("AND expression");if(strcmp($1,$3)==0 && strcmp($1,"Boolean")==0){$$=strdup("Boolean");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression OR expression | expression OR expression
{printf("OR\n");if(strcmp($1,$3)==0 && {printdebug("OR");if(strcmp($1,$3)==0 &&
strcmp($1,"Boolean")==0){$$=strdup("Boolean");} strcmp($1,"Boolean")==0){$$=strdup("Boolean");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression LESS_THAN expression | expression LESS_THAN expression
{printf("less than expression\n");if(strcmp($1,$3)==0 && {printdebug("less than expression");if(strcmp($1,$3)==0 &&
strcmp($1,"integer")==0){$$=strdup("Boolean");} strcmp($1,"integer")==0){$$=strdup("Boolean");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s.\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s.",
@2.first_line,@2.first_column,$1,$3); @2.first_line,@2.first_column,$1,$3);
$$=strdup("undefined");}} $$=strdup("undefined");}}
| expression EQUAL_TO expression {printf("equals check expression\n"); | expression EQUAL_TO expression {printdebug("equals check expression");
if(strcmp($1,$3)==0){$$=strdup("Boolean");} if(strcmp($1,$3)==0){$$=strdup("Boolean");}
else if((strcmp($1,"array")==0||strcmp($1,"record")==0|| else if((strcmp($1,"array")==0||strcmp($1,"record")==0||
strcmp($1,"function type primitive")==0) && (strcmp($3,"address")==0)){$$=strdup("Boolean");} strcmp($1,"function type primitive")==0) && (strcmp($3,"address")==0)){$$=strdup("Boolean");}
else{printf("mismatch at line %d and column %d. Invalid types %s and %s\n", else{printdebug("mismatch at line %d and column %d. Invalid types %s and %s",
@2.first_line,@2.first_column,$1,$3);$$=strdup("undefined");}} @2.first_line,@2.first_column,$1,$3);$$=strdup("undefined");}}
| assignable {printf("assignable expression. current type is %s\n",$1);$$=$1;} | assignable {printdebug("assignable expression. current type is %s",$1);$$=$1;}
| L_PAREN expression R_PAREN {printf("paren expression. current type is %s\n",$2);$$=$2;} | L_PAREN expression R_PAREN {printdebug("paren expression. current type is %s",$2);$$=$2;}
| memOp assignable {$$ = strdup("address");} | memOp assignable {$$ = strdup("address");}
; ;
@ -365,8 +365,8 @@ expression COMMA argument_list {$<integ>$ = $<integ>3 + 1;}
memOp: memOp:
RESERVE {printf("reserve expression\n");} RESERVE {printdebug("reserve expression");}
| RELEASE {printf("release expression\n");} | RELEASE {printdebug("release expression");}
; ;
@ -381,15 +381,15 @@ constant:
types: types:
// Commented out T_String below // Commented out T_String below
// T_STRING {printf("string of T_STRING in types is %s\n",$<words>1);} {$$ = $<words>1;} // T_STRING {printdebug("string of T_STRING in types is %s",$<words>1);} {$$ = $<words>1;}
T_INTEGER {printf("string of T_INTEGER in types is %s\n",$<words>1);} {$$ = $1;} T_INTEGER {printdebug("string of T_INTEGER in types is %s",$<words>1);} {$$ = $1;}
| T_ADDRESS {printf("string of T_ADDRESS in types is %s\n",$<words>1);} {$$ = $1;} | T_ADDRESS {printdebug("string of T_ADDRESS in types is %s",$<words>1);} {$$ = $1;}
| T_CHARACTER {printf("string of T_CHARACTER in types is %s\n",$<words>1);} {$$ = $1;} | T_CHARACTER {printdebug("string of T_CHARACTER in types is %s",$<words>1);} {$$ = $1;}
| T_BOOLEAN {printf("string of T_BOOLEAN in types is %s\n",$<words>1);} {$$ = $1;} | T_BOOLEAN {printdebug("string of T_BOOLEAN in types is %s",$<words>1);} {$$ = $1;}
; ;
%% %%
void yyerror(const char *err) { void yyerror(const char *err) {
fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d\n", err,yytext,yylloc.first_line,yylloc.first_column); fprintf(stderr, "ERROR: %s at token %s at line number %d,column number %d", err,yytext,yylloc.first_line,yylloc.first_column);
} }

View File

@ -15,13 +15,13 @@ extern char * COLOR_BLUE;
extern char *COLOR_WHITE; 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 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) { if (argc > 1 && strcmp(argv[argc - 1], "-debug") == 0) {
DEBUG = true; DEBUG = true;
argc--; argc--;
} }
if (argc == 1) { if (argc == 1) {
fprintf(stderr, INVALID); fprintf(stderr, INVALID);
return -1; return -1;

View File

@ -3,6 +3,7 @@
#include "symbol_table.h" #include "symbol_table.h"
#include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -19,8 +20,43 @@ TableNode *boo;
TableNode *recprime; TableNode *recprime;
TableNode *funtypeprime; TableNode *funtypeprime;
TableNode *undefined; TableNode *undefined;
// AdInfo *Undefined_function_type_info;
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 = true;
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,
COLOR_WHITE);
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
printf("\n");
}
}
#define printdebug(format, ...) \
printdebug_impl(__FILE__, __LINE__, format, ##__VA_ARGS__)
// AdInfo *Undefined_function_type_info;
typedef enum { typedef enum {
// First 4 below are primitive types that are all encapsulated in // First 4 below are primitive types that are all encapsulated in
// primitive type // primitive type
@ -107,16 +143,17 @@ 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( printdebug(
"passed an NULL entry to getPrimSize function. Invalid.\n"); "passed an NULL entry to getPrimSize function. Invalid.");
return -1; return -1;
} }
if (definition->additionalinfo == NULL) { if (definition->additionalinfo == NULL) {
printf("node has NULL additionalinfo. Invalid.\n"); printdebug("node has NULL additionalinfo. Invalid.");
return -1; return -1;
} }
if (strcmp(getType(definition), "primitive") != 0) { if (strcmp(getType(definition), "primitive") != 0) {
printf("not checking the size of a primitive -- invalid op\n"); printdebug(
"not checking the size of a primitive -- invalid op");
return 0; return 0;
} }
return definition->additionalinfo->PrimAdInfo->size; return definition->additionalinfo->PrimAdInfo->size;
@ -136,8 +173,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 " printdebug("passed a NULL or undefined type reference to "
"CreateArrayInfo. Invalid.\n"); "CreateArrayInfo. Invalid.");
return NULL; return NULL;
} }
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
@ -151,12 +188,12 @@ 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 " printdebug("passed an NULL or undefined entry to getNumArrDim "
"function. Invalid.\n"); "function. Invalid.");
return -1; return -1;
} }
if (strcmp(getType(definition), "array") != 0) { if (strcmp(getType(definition), "array") != 0) {
printf("not checking the dim of an array -- invalid op\n"); printdebug("not checking the dim of an array -- invalid op");
return 0; return 0;
} }
return definition->additionalinfo->ArrayAdInfo->numofdimensions; return definition->additionalinfo->ArrayAdInfo->numofdimensions;
@ -165,12 +202,12 @@ 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 " printdebug("passed an NULL or undefined entry to getArrType "
"function. Invalid.\n"); "function. Invalid.");
return NULL; return NULL;
} }
if (strcmp(getType(definition), "array") != 0) { if (strcmp(getType(definition), "array") != 0) {
printf("not checking the type of an array -- invalid op\n"); printdebug("not checking the type of an array -- invalid op");
return undefined; return undefined;
} }
return definition->additionalinfo->ArrayAdInfo->typeofarray; return definition->additionalinfo->ArrayAdInfo->typeofarray;
@ -193,12 +230,13 @@ 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 " printdebug("passed an NULL or undefined entry to getRecLength "
"function. Invalid.\n"); "function. Invalid.");
return -1; return -1;
} }
if (strcmp(getType(definition), "record") != 0) { if (strcmp(getType(definition), "record") != 0) {
printf("not checking the length of an record -- invalid op\n"); printdebug(
"not checking the length of an record -- invalid op");
return 0; return 0;
} }
return definition->additionalinfo->RecAdInfo->numofelements; return definition->additionalinfo->RecAdInfo->numofelements;
@ -206,13 +244,14 @@ 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 " printdebug("passed an NULL or undefined entry to getRecList "
"function. Invalid.\n"); "function. Invalid.");
return NULL; return NULL;
} }
if (strcmp(getType(definition), "record") != 0) { if (strcmp(getType(definition), "record") != 0) {
printf("not checking the list of types of a record -- invalid " printdebug(
"op\n"); "not checking the list of types of a record -- invalid "
"op");
return NULL; return NULL;
} }
return definition->additionalinfo->RecAdInfo->recordScope; return definition->additionalinfo->RecAdInfo->recordScope;
@ -220,7 +259,7 @@ SymbolTable *getRecList(TableNode *definition) {
TableNode *setRecSize(TableNode *tn, int n) { TableNode *setRecSize(TableNode *tn, int n) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
printf("passed in NULL entry for setRecSize. Invalid\n"); printdebug("passed in NULL entry for setRecSize. Invalid");
return undefined; return undefined;
} }
tn->additionalinfo->RecAdInfo->numofelements = n; tn->additionalinfo->RecAdInfo->numofelements = n;
@ -229,7 +268,8 @@ TableNode *setRecSize(TableNode *tn, int n) {
int getRecSize(SymbolTable *tn) { int getRecSize(SymbolTable *tn) {
if (tn == NULL) { if (tn == NULL) {
printf("passed in NULL SymbolTable for getRecSize. Invalid\n"); printdebug(
"passed in NULL SymbolTable for getRecSize. Invalid");
return -1; return -1;
} }
int s = 0; int s = 0;
@ -261,13 +301,14 @@ 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 " printdebug("passed an NULL or undefined entry to getStartLine "
"function. Invalid.\n"); "function. Invalid.");
return -1; return -1;
} }
if (strcmp(getType(definition), "primitive function") != 0) { if (strcmp(getType(definition), "primitive function") != 0) {
printf("not checking the start line of a function -- invalid " printdebug(
"op\n"); "not checking the start line of a function -- invalid "
"op");
return 0; return 0;
} }
return definition->additionalinfo->FunDecAdInfo->startlinenumber; return definition->additionalinfo->FunDecAdInfo->startlinenumber;
@ -275,8 +316,9 @@ 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. " printdebug(
"invalid\n"); "passing in a NULL or undefined entry to setStartLine. "
"invalid");
return undefined; return undefined;
} }
tn->additionalinfo->FunDecAdInfo->startlinenumber = start; tn->additionalinfo->FunDecAdInfo->startlinenumber = start;
@ -286,13 +328,14 @@ 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 " printdebug("passed an NULL or undefined entry to getAsKeyword "
"function. Invalid.\n"); "function. Invalid.");
return false; return false;
} }
if (strcmp(getType(definition), "primitive function") != 0) { if (strcmp(getType(definition), "primitive function") != 0) {
printf("not checking if a function is called with as or not -- " printdebug(
"invalid op\n"); "not checking if a function is called with as or not -- "
"invalid op");
return 0; return 0;
} }
return definition->additionalinfo->FunDecAdInfo->regularoras; return definition->additionalinfo->FunDecAdInfo->regularoras;
@ -300,8 +343,9 @@ 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. " printdebug(
"invalid\n"); "passing in a NULL or undefined entry to setAsKeyword. "
"invalid");
return undefined; return undefined;
} }
tn->additionalinfo->FunDecAdInfo->regularoras = as; tn->additionalinfo->FunDecAdInfo->regularoras = as;
@ -311,13 +355,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 " printdebug("passed a NULL or undefined parameter to "
"CreateFunctionTypeInfo. Invalid.\n"); "CreateFunctionTypeInfo. Invalid.");
return NULL; return NULL;
} }
if (returntype == NULL || returntype == undefined) { if (returntype == NULL || returntype == undefined) {
printf("passed a NULL or undefined return type to " printdebug("passed a NULL or undefined return type to "
"CreateFunctionTypeInfo. Invalid.\n"); "CreateFunctionTypeInfo. Invalid.");
return NULL; return NULL;
} }
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
@ -330,13 +374,13 @@ 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 " printdebug("passed an NULL or undefined entry to getParameter "
"function. Invalid.\n"); "function. Invalid.");
return undefined; return undefined;
} }
if (strcmp(getType(definition), "primitive function type") != 0) { if (strcmp(getType(definition), "primitive function type") != 0) {
printf( printdebug(
"not checking the parameter of a function -- invalid op\n"); "not checking the parameter of a function -- invalid op");
return undefined; return undefined;
} }
return definition->additionalinfo->FunTypeAdInfo->parameter; return definition->additionalinfo->FunTypeAdInfo->parameter;
@ -344,12 +388,13 @@ 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 " printdebug("passed an NULL or undefined entry to getReturn "
"function. Invalid.\n"); "function. Invalid.");
return NULL; return NULL;
} }
if (strcmp(getType(definition), "primitive function type") != 0) { if (strcmp(getType(definition), "primitive function type") != 0) {
printf("not checking the return of a function -- invalid op\n"); printdebug(
"not checking the return of a function -- invalid op");
return undefined; return undefined;
} }
return definition->additionalinfo->FunTypeAdInfo->returntype; return definition->additionalinfo->FunTypeAdInfo->returntype;
@ -389,8 +434,8 @@ SymbolTable *CreateScope(SymbolTable *ParentScope, int Line, int Column) {
// types // types
SymbolTable *init(SymbolTable *start) { SymbolTable *init(SymbolTable *start) {
if (start->Parent_Scope != NULL) { if (start->Parent_Scope != NULL) {
printf( printdebug(
"Cannot initialize a scope that is not the parent scope\n"); "Cannot initialize a scope that is not the parent scope");
return NULL; return NULL;
} }
integ = (TableNode *)calloc(1, sizeof(TableNode)); integ = (TableNode *)calloc(1, sizeof(TableNode));
@ -504,18 +549,19 @@ 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 " printdebug("passed in an invalid table node to modify (NULL or "
"undefined).\n"); "undefined).");
return undefined; return undefined;
} }
if (type == NULL || type == undefined) { if (type == NULL || type == undefined) {
printf("passed in a NULL or undefined type reference to " printdebug("passed in a NULL or undefined type reference to "
"populate a table node. Invalid.\n"); "populate a table node. Invalid.");
return undefined; return undefined;
} }
if (info == NULL) { if (info == NULL) {
printf("passed in a NULL info reference to populate a table " printdebug(
"node. Invalid.\n"); "passed in a NULL info reference to populate a table "
"node. Invalid.");
return undefined; return undefined;
} }
tn->theType = type; tn->theType = type;
@ -526,12 +572,12 @@ TableNode *populateTypeAndInfo(TableNode *tn, TableNode *type, AdInfo *info) {
int getAdInfoType(TableNode *tn) { int getAdInfoType(TableNode *tn) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
printf("passing in NULL or undefined table entry. Invalid\n"); printdebug("passing in NULL or undefined table entry. Invalid");
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 " printdebug("Entry being passed in has a null or undefined "
"reference for theType. Invalid.\n"); "reference for theType. Invalid.");
return -1; return -1;
} }
if (strcmp(getName(tn), getName(integ)) == 0) { if (strcmp(getName(tn), getName(integ)) == 0) {
@ -569,20 +615,21 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
AdInfo *ad) { AdInfo *ad) {
if (table == NULL) { if (table == NULL) {
printf("Null reference to table"); printdebug("Null reference to table");
return undefined; return undefined;
} }
/* /*
TableNode* topDef = (table_lookup(getAncestor(table),typeOf)); TableNode* topDef = (table_lookup(getAncestor(table),typeOf));
if(topDef == NULL){ if(topDef == NULL){
printf("This type is not defined at the top level\n"); printdebug("This type is not defined at the top level");
return NULL; return NULL;
} }
*/ */
if (typeOf == NULL || typeOf == undefined) { if (typeOf == NULL || typeOf == undefined) {
printf("This is not pointing to a proper definition (either " printdebug(
"NULL or undefined)\n"); "This is not pointing to a proper definition (either "
"NULL or undefined)");
return undefined; return undefined;
} }
TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode)); TableNode *newEntry = (TableNode *)calloc(1, sizeof(TableNode));
@ -602,11 +649,11 @@ TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id,
char *getType(TableNode *tn) { char *getType(TableNode *tn) {
if (tn == NULL || tn == undefined) { if (tn == NULL || tn == undefined) {
printf("passed a NULL or undefined table entry to getType\n"); printdebug("passed a NULL or undefined table entry to getType");
return getName(undefined); return getName(undefined);
} }
if (tn->theType == NULL || tn->theType == undefined) { if (tn->theType == NULL || tn->theType == undefined) {
printf("type of entry is currently NULL or undefined type \n"); printdebug("type of entry is currently NULL or undefined type");
return getName(undefined); return getName(undefined);
} }
return tn->theType->theName; return tn->theType->theName;
@ -614,12 +661,12 @@ char *getType(TableNode *tn) {
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 // printdebug("passed a NULL or undefined table entry to
// getName\n"); // getName");
return undefined->theName; return undefined->theName;
} }
if (tn->theName == NULL) { if (tn->theName == NULL) {
// printf("name of entry is currently NULL, undefined \n"); // printdebug("name of entry is currently NULL, undefined");
return undefined->theName; return undefined->theName;
} }
return tn->theName; return tn->theName;
@ -627,34 +674,36 @@ 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. " printdebug("passed a NULL symbol table to getLine function. "
"Invalid.\n"); "Invalid.");
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. " printdebug("passed a NULL symbol table to getColumn function. "
"Invalid.\n"); "Invalid.");
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 " printdebug(
"function. Invalid./n"); "passed a Null or undefined table node to the addName "
"function. Invalid.");
return undefined; return undefined;
} }
if (tn->theName != NULL) { if (tn->theName != NULL) {
printf("Name doesn't look like it is empty before you change. " printdebug(
"Are you sure you need to update name?/n"); "Name doesn't look like it is empty before you change. "
"Are you sure you need to update name?");
return undefined; return undefined;
} }
if (str == NULL) { if (str == NULL) {
printf( printdebug(
"passed a NULL string to the addName function. Invalid./n"); "passed a NULL string to the addName function. Invalid.");
return undefined; return undefined;
} }
tn->theName = str; tn->theName = str;
@ -663,8 +712,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 " printdebug("passed a Null Symbol Table to the setLineNumber "
"function. Invalid./n"); "function. Invalid.");
return st; return st;
} }
st->Line_Number = line; st->Line_Number = line;
@ -673,8 +722,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 " printdebug("passed a Null Symbol Table to the setColumnNumber "
"function. Invalid./n"); "function. Invalid.");
return st; return st;
} }
st->Line_Number = column; st->Line_Number = column;
@ -684,7 +733,7 @@ SymbolTable *setColumnNumber(SymbolTable *st, int column) {
//we use false for type defs and true for functions for parameter of typeOf //we use false for type defs and true for functions for parameter of typeOf
TableNode* Define(SymbolTable* table, bool typeOf, char* id) { TableNode* Define(SymbolTable* table, bool typeOf, char* id) {
if(table ==NULL || table->Parent_Scope != NULL){ if(table ==NULL || table->Parent_Scope != NULL){
printf("No valid table given for header defs\n"); printdebug("No valid table given for header defs");
return NULL; return NULL;
} }
@ -699,8 +748,8 @@ if (typeOf == 1){
newEntry->theType = funy; newEntry->theType = funy;
} }
if(table_lookup(table,id) != NULL){ if(table_lookup(table,id) != NULL){
printf("already defined at the top level, can't define duplicate printdebug("already defined at the top level, can't define duplicate
names\n"); return NULL; names"); return NULL;
} }
newEntry->theName = id; newEntry->theName = id;
if (table->entries == NULL) { if (table->entries == NULL) {
@ -718,7 +767,7 @@ names\n"); return NULL;
// only check table that is given // only check table that is given
TableNode *table_lookup(SymbolTable *table, char *x) { TableNode *table_lookup(SymbolTable *table, char *x) {
if (table == NULL) { if (table == NULL) {
printf("passed in empty scope. error.\n"); printdebug("passed in empty scope. error.");
return undefined; return undefined;
} }
TableNode *entrie = table->entries; TableNode *entrie = table->entries;
@ -732,15 +781,16 @@ TableNode *table_lookup(SymbolTable *table, char *x) {
// check current table and all parents // check current table and all parents
TableNode *look_up(SymbolTable *table, char *x) { TableNode *look_up(SymbolTable *table, char *x) {
if (table == NULL) { if (table == NULL) {
printf("passed in empty scope. error.\n"); printdebug("passed in empty scope. error.");
return undefined; return undefined;
} }
TableNode *ret = table_lookup(table, x); TableNode *ret = table_lookup(table, 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 " printdebug(
"%d so moving up a scope\n", "could not find %s in scope that started at line %d and column "
"%d so moving up a scope",
x, getLine(table), getColumn(table)); x, getLine(table), getColumn(table));
return look_up(table->Parent_Scope, x); return look_up(table->Parent_Scope, x);
} }
@ -958,7 +1008,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
// get top most symbol table // get top most symbol table
SymbolTable *getAncestor(SymbolTable *table) { SymbolTable *getAncestor(SymbolTable *table) {
if (table == NULL) { if (table == NULL) {
printf("passing a NULL reference to getAncestor. Invalid.\n"); printdebug("passing a NULL reference to getAncestor. Invalid.");
return NULL; return NULL;
} }
if (table->Parent_Scope == NULL) { if (table->Parent_Scope == NULL) {
@ -1005,11 +1055,11 @@ bool typeCheck(char *firstID, char *secondID) {
TableNode *entry1 = look_up(cur, firstID); TableNode *entry1 = look_up(cur, firstID);
TableNode *entry2 = look_up(cur, secondID); TableNode *entry2 = look_up(cur, secondID);
if (entry1 == NULL || entry1 == undefined) { if (entry1 == NULL || entry1 == undefined) {
printf("first type not defined\n"); printdebug("first type not defined");
return false; return false;
} }
if (entry2 == NULL || entry2 == undefined) { if (entry2 == NULL || entry2 == undefined) {
printf("second type not defined\n"); printdebug("second type not defined");
return false; return false;
} }
if (table_lookup(getAncestor(cur), getType(look_up(cur, firstID))) == if (table_lookup(getAncestor(cur), getType(look_up(cur, firstID))) ==
@ -1052,36 +1102,11 @@ TableNode *getNextEntry(TableNode *tn) { return tn->next; }
char* String = "STRING"; char* String = "STRING";
char* X = "X"; char* X = "X";
SymbolTable* Second = CreateScope(NULL, 2,2); SymbolTable* Second = CreateScope(NULL, 2,2);
printf("Line number is %d, Column number of scope is printdebug("Line number is %d, Column number of scope is
%d\n",Second->Line_Number,Second->Column_Number); TableNode* First_Entry = %d",Second->Line_Number,Second->Column_Number); TableNode* First_Entry =
CreateEntry(Second,String,X); CreateEntry(Second,String,X);
printf("The type of the first entry is %s\n",First_Entry->theType); printdebug("The type of the first entry is %s",First_Entry->theType);
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;
}