added a bunch of NULL checks

This commit is contained in:
Partho
2025-03-28 22:22:58 -04:00
parent 227cec0b73
commit 57ba34ab37
3 changed files with 260 additions and 144 deletions

View File

@ -36,7 +36,7 @@
char * words; char * words;
} }
%type <integ> idlist
%type <words> assignable %type <words> assignable
%type <words> expression %type <words> expression
%type <words> constant %type <words> constant
@ -121,27 +121,39 @@ prototype:
L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID; L_PAREN EXTERNAL R_PAREN FUNCTION ID COLON ID;
definition: definition:
TYPE ID COLON {tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo(0, cur = CreateScope(cur, 0, 0))); TYPE ID COLON {
printf("Currently see a record definition for %s\n", $<words>2);
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"); printf("rec not found \n");
} }
}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 { CreateEntry(cur, arrayprim, $2, CreateArrayInfo($4, look_up(cur, $6)));} | 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",
$2, $6, $4);
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",
$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 || getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) { if (node == NULL) {
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
} else { }else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
}
else {
setStartLine(node, @1.first_line); setStartLine(node, @1.first_line);
setAsKeyword(node, false); setAsKeyword(node, false);
} }
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",
$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 {
@ -149,23 +161,29 @@ TYPE ID COLON {tn = CreateEntry(getAncestor(cur), recprime, $2, CreateRecordInfo
if (node == NULL) { if (node == NULL) {
printf("null check\n"); printf("null check\n");
} }
if (node == NULL || getAdInfoType(node) != TYPE_FUNCTION_DECLARATION) { if (node == NULL) {
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column); printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
} else { }else if(getAdInfoType(node) != TYPE_FUNCTION_DECLARATION){
printf("function not declared at line %d, column %d\n", @1.first_line, @1.first_column);
}
else {
setStartLine(node, @1.first_line); setStartLine(node, @1.first_line);
setAsKeyword(node, false); setAsKeyword(node, false);
} }
cur = CreateScope(cur, 0, 0); cur = CreateScope(cur, 0, 0);
}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 || getAdInfoType(parameter) != TYPE_RECORD) { 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);
}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); printf("function defined with as, but parameter is not a record at line %d, column %d\n", @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 R_PAREN ASSIGN sblock } idlist {printf("Currently see a function definition taking one paramter (with as) of name %s and number of arguments %d\n",
$1,$6);} R_PAREN ASSIGN sblock
; ;
@ -185,7 +203,7 @@ idlist:
printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column); printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column);
} }
addName(entry, $<words>1); addName(entry, $<words>1);
} COMMA idlist } COMMA idlist {$$ = $<integ>3 + 1;}
| ID { | ID {
TableNode *entry = getFirstEntry(cur); TableNode *entry = getFirstEntry(cur);
@ -196,6 +214,7 @@ idlist:
printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column); printf("too many parameters at line %d column %d\n", @1.first_line, @1.first_column);
} }
addName(entry, $<words>1); addName(entry, $<words>1);
$$ = 1;
} }
; ;

View File

@ -19,6 +19,7 @@ TableNode *boo;
TableNode *recprime; TableNode *recprime;
TableNode *funtypeprime; TableNode *funtypeprime;
TableNode *undefined; TableNode *undefined;
//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
@ -133,6 +134,10 @@ int getPrimSize(TableNode *definition) {
// type stored in the array per professor, the actual size of the array is // 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 // 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){
printf("passed a NULL or undefined type reference to CreateArrayInfo. Invalid.\n");
return NULL;
}
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
info->ArrayAdInfo = (array_info *)malloc(sizeof(array_info)); info->ArrayAdInfo = (array_info *)malloc(sizeof(array_info));
info->ArrayAdInfo->numofdimensions = dim; info->ArrayAdInfo->numofdimensions = dim;
@ -144,7 +149,7 @@ 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 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) {
@ -156,6 +161,10 @@ int getNumArrDim(TableNode *definition) {
// This gets the type stored in an array from arrtype. It returns a reference to // This gets the type stored in an array from arrtype. It returns a reference to
// the entry of that type // the entry of that type
TableNode *getArrType(TableNode *definition) { TableNode *getArrType(TableNode *definition) {
if(definition == NULL|| definition == undefined){
printf("passed an NULL or undefined entry to getArrType function. Invalid.\n");
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"); printf("not checking the type of an array -- invalid op\n");
return undefined; return undefined;
@ -179,6 +188,10 @@ AdInfo *CreateRecordInfo(int length, SymbolTable *recordScope) {
// Perhaps this may not be needed since we need to iterate over all elements // Perhaps this may not be needed since we need to iterate over all elements
// anyways. // anyways.
int getRecLength(TableNode *definition) { int getRecLength(TableNode *definition) {
if (definition == NULL|| definition == undefined){
printf("passed an NULL or undefined entry to getRecLength function. Invalid.\n");
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"); printf("not checking the length of an record -- invalid op\n");
return 0; return 0;
@ -187,6 +200,10 @@ 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){
printf("passed an NULL or undefined entry to getRecList function. Invalid.\n");
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 " printf("not checking the list of types of a record -- invalid "
"op\n"); "op\n");
@ -205,14 +222,21 @@ TableNode* setRecSize(TableNode* tn, int n){
} }
int getRecSize(SymbolTable* tn){ int getRecSize(SymbolTable* tn){
if(tn == NULL){
printf("passed in NULL SymbolTable for getRecSize. Invalid\n");
return -1;
}
int s = 0; int s = 0;
TableNode* cur = getFirstEntry(tn); TableNode* cur = getFirstEntry(tn);
if (cur != NULL){
while(getNextEntry(cur) != NULL){ while(getNextEntry(cur) != NULL){
s++; s++;
cur = getNextEntry(cur); cur = getNextEntry(cur);
} }
return s; return s;
} }
return -1;
}
// below function takes a bool to see if parameter should be decomposed or not // below function takes a bool to see if parameter should be decomposed or not
;// note that functions only take one input and have one output ;// note that functions only take one input and have one output
@ -230,6 +254,10 @@ AdInfo *CreateFunctionDeclarationInfo(int line, bool asorregular) {
// gets the line at which the function was first defined. (Can be used to print // gets the line at which the function was first defined. (Can be used to print
// out in table if needed) // out in table if needed)
int getStartLine(TableNode *definition) { int getStartLine(TableNode *definition) {
if (definition == NULL|| definition == undefined){
printf("passed an NULL or undefined entry to getStartLine function. Invalid.\n");
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 " printf("not checking the start line of a function -- invalid "
"op\n"); "op\n");
@ -249,6 +277,10 @@ TableNode* setStartLine(TableNode* tn, int start){
// checks if "as" keyword was used for function definition. Either 0 or 1 for // checks if "as" keyword was used for function definition. Either 0 or 1 for
// not used or used. // not used or used.
bool getAsKeyword(TableNode *definition) { bool getAsKeyword(TableNode *definition) {
if (definition == NULL|| definition == undefined){
printf("passed an NULL or undefined entry to getAsKeyword function. Invalid.\n");
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 -- " printf("not checking if a function is called with as or not -- "
"invalid op\n"); "invalid op\n");
@ -268,6 +300,14 @@ 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){
printf("passed a NULL or undefined parameter to CreateFunctionTypeInfo. Invalid.\n");
return NULL;
}
if(returntype == NULL||returntype == undefined){
printf("passed a NULL or undefined return type to CreateFunctionTypeInfo. Invalid.\n");
return NULL;
}
AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo)); AdInfo *info = (AdInfo *)malloc(sizeof(AdInfo));
info->FunTypeAdInfo = info->FunTypeAdInfo =
(function_type_info *)malloc(sizeof(function_type_info)); (function_type_info *)malloc(sizeof(function_type_info));
@ -277,6 +317,10 @@ 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){
printf("passed an NULL or undefined entry to getParameter function. Invalid.\n");
return undefined;
}
if (strcmp(getType(definition), "primitive function type") != 0) { if (strcmp(getType(definition), "primitive function type") != 0) {
printf( printf(
"not checking the parameter of a function -- invalid op\n"); "not checking the parameter of a function -- invalid op\n");
@ -286,6 +330,10 @@ 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){
printf("passed an NULL or undefined entry to getReturn function. Invalid.\n");
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"); printf("not checking the return of a function -- invalid op\n");
return undefined; return undefined;
@ -331,11 +379,11 @@ SymbolTable *init(SymbolTable *start) {
"Cannot initialize a scope that is not the parent scope\n"); "Cannot initialize a scope that is not the parent scope\n");
return NULL; return NULL;
} }
integ = (TableNode *)malloc(sizeof(TableNode)); integ = (TableNode *)calloc(1,sizeof(TableNode));
addr = (TableNode *)malloc(sizeof(TableNode)); addr = (TableNode *)calloc(1,sizeof(TableNode));
chara = (TableNode *)malloc(sizeof(TableNode)); chara = (TableNode *)calloc(1,sizeof(TableNode));
stri = (TableNode *)malloc(sizeof(TableNode)); stri = (TableNode *)calloc(1,sizeof(TableNode));
boo = (TableNode *)malloc(sizeof(TableNode)); boo = (TableNode *)calloc(1,sizeof(TableNode));
// TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable)); // TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable));
start->entries = integ; start->entries = integ;
integ->next = addr; integ->next = addr;
@ -402,6 +450,8 @@ SymbolTable *init(SymbolTable *start) {
undefined->additionalinfo = NULL; undefined->additionalinfo = NULL;
undefined->next = NULL; undefined->next = NULL;
//Undefined_function_type_info = CreateFunctionTypeInfo(undefined, undefined);
integ->theType = prime; integ->theType = prime;
addr->theType = prime; addr->theType = prime;
chara->theType = prime; chara->theType = prime;
@ -465,31 +515,31 @@ int getAdInfoType(TableNode* tn){
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(getType(tn),getName(integ))==0){ if(strcmp(getName(tn),getName(integ))==0){
return TYPE_PRIMITIVE; return TYPE_PRIMITIVE;
} }
if(strcmp(getType(tn),getName(addr))==0){ if(strcmp(getName(tn),getName(addr))==0){
return TYPE_PRIMITIVE; return TYPE_PRIMITIVE;
} }
if(strcmp(getType(tn),getName(chara))==0){ if(strcmp(getName(tn),getName(chara))==0){
return TYPE_PRIMITIVE; return TYPE_PRIMITIVE;
} }
if(strcmp(getType(tn),getName(stri))==0){ if(strcmp(getName(tn),getName(stri))==0){
return TYPE_ARRAY; return TYPE_ARRAY;
} }
if(strcmp(getType(tn),getName(boo))==0){ if(strcmp(getName(tn),getName(boo))==0){
return TYPE_PRIMITIVE; return TYPE_PRIMITIVE;
} }
if(strcmp(getType(tn),getName(recprime))==0){ if(strcmp(getName(tn),getName(recprime))==0){
return TYPE_RECORD; return TYPE_RECORD;
} }
if(strcmp(getType(tn),getName(funtypeprime))==0){ if(strcmp(getName(tn),getName(funtypeprime))==0){
return TYPE_FUNCTION_TYPE; return TYPE_FUNCTION_TYPE;
} }
if(strcmp(getType(tn),getName(arrayprim))==0){ if(strcmp(getName(tn),getName(arrayprim))==0){
return TYPE_ARRAY; return TYPE_ARRAY;
} }
if(strcmp(getType(tn),getName(undefined))==0){ if(strcmp(getName(tn),getName(undefined))==0){
return TYPE_UNDEFINED; return TYPE_UNDEFINED;
} }
else{ else{
@ -497,13 +547,13 @@ int getAdInfoType(TableNode* tn){
} }
} }
TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, TableNode *CreateEntry(SymbolTable *table, TableNode *typeOf, char *id, AdInfo *ad) {
AdInfo *ad) {
if (table == NULL) { if (table == NULL) {
printf("Null reference to table"); printf("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){
@ -553,8 +603,18 @@ char *getName(TableNode *tn) {
return tn->theName; return tn->theName;
} }
int getLine(SymbolTable *st) { return st->Line_Number; } int getLine(SymbolTable *st) {
int getColumn(SymbolTable *st) { return st->Column_Number; } if(st == NULL){
printf("passed a NULL symbol table to getLine function. Invalid.\n");
return -1;
}
return st->Line_Number; }
int getColumn(SymbolTable *st) {
if(st == NULL){
printf("passed a NULL symbol table to getColumn function. Invalid.\n");
return -1;
}
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");
@ -626,6 +686,10 @@ 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) {
printf("passed in empty scope. error.\n");
return undefined;
}
TableNode *entrie = table->entries; TableNode *entrie = table->entries;
for (; entrie != NULL; entrie = entrie->next) { for (; entrie != NULL; entrie = entrie->next) {
if (!strcmp(entrie->theName, x)) { if (!strcmp(entrie->theName, x)) {
@ -648,8 +712,9 @@ TableNode *look_up(SymbolTable *table, char *x) {
,x,getLine(table),getColumn(table)); ,x,getLine(table),getColumn(table));
return look_up(table->Parent_Scope, x); return look_up(table->Parent_Scope, x);
} }
/*
void print_symbol_table(SymbolTable *table, FILE *file_ptr) { void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
if (table->Parent_Scope == NULL) { if (table->Parent_Scope == NULL) {
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",
"SCOPE", "PARENT", "TYPE", "Extra annotation"); "SCOPE", "PARENT", "TYPE", "Extra annotation");
@ -674,7 +739,7 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
} }
for (; entrie != NULL; entrie = entrie->next) { for (; entrie != NULL; entrie = entrie->next) {
if (parant_scope == 0) { if (parant_scope == 0) {
/*have to update*/ if (strcmp(entrie->theType->theName, /*have to update if (strcmp(entrie->theType->theName,
"function primitive") || "function primitive") ||
strcmp(entrie->theType->theName, strcmp(entrie->theType->theName,
"array")) { "array")) {
@ -700,124 +765,139 @@ void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
"--------------:-------" "--------------:-------"
"----------------------\n"); "----------------------\n");
} }
}*/
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");
} }
// void print_symbol_table(SymbolTable *table, FILE *file_ptr) { 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 (getAdInfoType(entrie) == TYPE_ARRAY){
if (parant_scope == 0) {
// if (table->Parent_Scope == NULL) { fprintf(file_ptr,
// fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME", "%-17s: %06d : : %-21d -> %-21s: %-28s\n",
// "SCOPE", "PARENT", "TYPE", "Extra annotation"); entrie->theName, current_scope,
// } entrie->additionalinfo->ArrayAdInfo->numofdimensions,
// TableNode *entrie = table->entries; entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
// fprintf(file_ptr, "-----------------:--------:--------:----------------" "Type of Array");
// "------:---------" } else {
// "--------------------\n"); fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n",
// int parant_scope = 0; entrie->theName, current_scope, parant_scope,
// int current_scope = 0; entrie->additionalinfo->ArrayAdInfo->numofdimensions,
// if (table->Parent_Scope != NULL) { entrie->additionalinfo->ArrayAdInfo->typeofarray->theName,
// parant_scope = table->Parent_Scope->Line_Number * 1000 + "Type of Array");
// table->Parent_Scope->Column_Number; }
// current_scope = }
// table->Line_Number * 1000 + table->Column_Number; if (getAdInfoType(entrie) == TYPE_RECORD){
// } else { if (parant_scope == 0) {
// 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 (getAdInfoType(entrie) == TYPE_ARRAY){
// if (parant_scope == 0) {
// fprintf(file_ptr, fprintf(file_ptr,
// "%-17s: %06d : : %-21d -> %-21s: %-28s\n", "%-17s: %06d : :%-21s: elements-%-28d\n",
// entrie->theName, current_scope, entrie->theName, current_scope,
// entrie->additionalinfo->ArrayAdInfo->numofdimensions, "record",
// entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, entrie->additionalinfo->RecAdInfo->numofelements);
// "Type of Array"); } else {
// } else { fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n",
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21d -> %-21s: %-28s\n", entrie->theName, current_scope, parant_scope,
// entrie->theName, current_scope, parant_scope, "record",
// entrie->additionalinfo->ArrayAdInfo->numofdimensions, entrie->additionalinfo->RecAdInfo->numofelements);
// entrie->additionalinfo->ArrayAdInfo->typeofarray->theName, }
// "Type of Array"); }
// } if (getAdInfoType(entrie) == TYPE_PRIMITIVE){
// } if (parant_scope == 0) {
// if (getAdInfoType(entrie) == TYPE_RECORD){
// if (parant_scope == 0) {
// fprintf(file_ptr, fprintf(file_ptr,
// "%-17s: %06d : :%-21s: elements-%-28d\n", "%-17s: %06d : :%-21s: size-%-28d bytes\n",
// entrie->theName, current_scope, entrie->theName, current_scope,
// "record", "Primitive",
// entrie->additionalinfo->RecAdInfo->numofelements); entrie->additionalinfo->PrimAdInfo->size);
// } else { } else {
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: elements-%-28d\n", fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n",
// entrie->theName, current_scope, parant_scope, entrie->theName, current_scope, parant_scope,
// "record", "Primitive",
// entrie->additionalinfo->RecAdInfo->numofelements); entrie->additionalinfo->PrimAdInfo->size);
// } }
// } }
// if (getAdInfoType(entrie) == TYPE_PRIMITIVE){ if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE){
// if (parant_scope == 0) { if (parant_scope == 0) {
// fprintf(file_ptr, fprintf(file_ptr,
// "%-17s: %06d : :%-21s: size-%-28d bytes\n", "%-17s: %06d : : %-21s -> %-21s: %-28s\n",
// entrie->theName, current_scope, entrie->theName, current_scope,
// "Primitive", entrie->additionalinfo->FunTypeAdInfo->parameter->theName,
// entrie->additionalinfo->PrimAdInfo->size); entrie->additionalinfo->FunTypeAdInfo->returntype->theName,
// } else { "Type of Function");
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: size-%-28d bytes\n", } else {
// entrie->theName, current_scope, parant_scope, fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n",
// "Primitive", entrie->theName, current_scope, parant_scope,
// entrie->additionalinfo->PrimAdInfo->size); entrie->additionalinfo->FunTypeAdInfo->parameter->theName,
// } entrie->additionalinfo->FunTypeAdInfo->returntype->theName,
// } "Type of Function");
// if (getAdInfoType(entrie) == TYPE_FUNCTION_TYPE){ }
// if (parant_scope == 0) { }
if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION){
if (parant_scope == 0) {
// fprintf(file_ptr, fprintf(file_ptr,
// "%-17s: %06d : : %-21s -> %-21s: %-28s\n", "%-17s: %06d : :%-21s: %-28s\n",
// entrie->theName, current_scope, entrie->theName, current_scope,
// entrie->additionalinfo->FunTypeAdInfo->parameter->theName, getType(entrie),
// entrie->additionalinfo->FunTypeAdInfo->returntype->theName, "Function");
// "Type of Function"); } else {
// } else { fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n",
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s -> %-21s: %-28s\n", entrie->theName, current_scope, parant_scope,
// entrie->theName, current_scope, parant_scope, getType(entrie),
// entrie->additionalinfo->FunTypeAdInfo->parameter->theName, "Function");
// entrie->additionalinfo->FunTypeAdInfo->returntype->theName, }
// "Type of Function"); }
// } if (getAdInfoType(entrie) == TYPE_UNDEFINED){
// } if (parant_scope == 0) {
// if (getAdInfoType(entrie) == TYPE_FUNCTION_DECLARATION){
// if (parant_scope == 0) {
// 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), "undefined",
// "Function"); "undefined entry");
// } else { } else {
// fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n", fprintf(file_ptr, "%-17s: %06d : %06d : %-21s: %-28s\n",
// entrie->theName, current_scope, parant_scope, entrie->theName, current_scope, parant_scope,
// getType(entrie), "undefined",
// "Function"); "undefined entry");
// } }
// } }
// } }
// if (table->Children_Scope != NULL) { if (table->Children_Scope != NULL) {
// ListOfTable *node = table->Children_Scope; ListOfTable *node = table->Children_Scope;
// for (; node != NULL; node = node->next) { for (; node != NULL; node = node->next) {
// print_symbol_table(node->table, file_ptr); print_symbol_table(node->table, file_ptr);
// } }
// } }
// if (table->Parent_Scope == NULL) { if (table->Parent_Scope == NULL) {
// fprintf(file_ptr, "-----------------:--------:--------:--------" fprintf(file_ptr, "-----------------:--------:--------:--------"
// "--------------:-------" "--------------:-------"
// "----------------------\n"); "----------------------\n");
// } }
// } }
//get top most symbol table //get top most symbol table
SymbolTable *getAncestor(SymbolTable *table) { SymbolTable *getAncestor(SymbolTable *table) {
if(table == NULL){ if(table == NULL){

View File

@ -0,0 +1,17 @@
type Boolean2Boolean: Boolean -> Boolean
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 integer2address: integer -> address
type address2integer: address -> integer
external function printInteger: integer2integer
external function printCharacter: character2integer
external function printBoolean: Boolean2integer
external function reserve: integer2address
external function release: address2integer
function entry: string2integer*)