still working through symbol_table to try and get it to compile soon but fixed issues with storing values and calling the right element of a struct
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
#include <stdlib.h>
|
||||
char * typey = "type";
|
||||
char * funy = "function";
|
||||
TableNode* funprime;
|
||||
TableNode* arrayprim;
|
||||
|
||||
typedef enum {
|
||||
//First 4 below are primitive types that are all encapsulated in primitive type
|
||||
@ -81,18 +83,20 @@ primitive_info* CreatePrimitiveInfo(size){
|
||||
return prim;
|
||||
}
|
||||
|
||||
string_info* CreateStringInfo(int length, char* loc){
|
||||
//probably don't need the below structure since can create from an array
|
||||
/*string_info* CreateStringInfo(int length, char* loc){
|
||||
string_info* stringy = (string_info*)malloc(sizeof(string_info));
|
||||
stringy.length=length;
|
||||
char* location = loc;
|
||||
return stringy;
|
||||
}
|
||||
|
||||
array_info* CreateArrayInfo(int dim, int* sizes, TableNode* type){
|
||||
*/
|
||||
array_info* CreateArrayInfo(int dim, /*int* sizes,*/ TableNode* type){
|
||||
array_info* arr = (array_info*)malloc(sizeof(array_info));
|
||||
arr.numofdimensions=dim;
|
||||
arr.typeofarray=type;
|
||||
int* dimensionsizes = loc;
|
||||
arr->typeofarray=type;
|
||||
//avoiding storing any types like below
|
||||
//int* dimensionsizes = loc;
|
||||
return arr;
|
||||
}
|
||||
|
||||
@ -103,6 +107,7 @@ record_info* CreateRecordInfo(int length, TableNode* typesarray){
|
||||
return reccy;
|
||||
}
|
||||
|
||||
//below function takes a bool to see if parameter should be decomposed or not
|
||||
function_declaration_info* CreateFunctionDeclarationInfo(int line, bool asorregular){
|
||||
function_declaration_info* fundec = (function_declaration_info*)malloc(sizeof(function_declaration_info));
|
||||
fundec.startlinenumber=line;
|
||||
@ -158,19 +163,21 @@ SymbolTable* init(SymbolTable* start){
|
||||
TableNode* chara = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
TableNode* stri = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
TableNode* boo = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
//TableNode* arr = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
start->entries = integ;
|
||||
integ->next = addr;
|
||||
addr->next = chara;
|
||||
chara->next = stri;
|
||||
stri->next = boo;
|
||||
boo->next = arr;
|
||||
//boo->next = arr;
|
||||
boo->next = NULL;
|
||||
|
||||
integ->theName= "integer";
|
||||
addr->theName= "address";
|
||||
chara->theName= "character";
|
||||
boo->theName= "Boolean";
|
||||
stri->theName= "string";
|
||||
arr->theName= "array"
|
||||
//arr->theName= "array"
|
||||
|
||||
//root TableNode that all are pointing to but not in table
|
||||
TableNode* prime = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
@ -178,19 +185,37 @@ SymbolTable* init(SymbolTable* start){
|
||||
prime->theType=NULL;
|
||||
prime->additionalinfo = NULL;
|
||||
prime->next = NULL;
|
||||
|
||||
TableNode* striprim = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
prime->theName= "1->character";
|
||||
|
||||
//note sur exatly how to get array types to look right so using a dummy Table Node below and updating the print symbol table function to access the additional information to print for array types, similar to function types
|
||||
TableNode* arrayprim = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
prime->theName= "array";
|
||||
prime->theType=NULL;
|
||||
prime->additionalinfo = NULL;
|
||||
prime->next = NULL;
|
||||
|
||||
//funprime = CreateEntry(NULL,NULL,strdup("function primitive"),NULL);
|
||||
|
||||
//similar workaround to arrays above
|
||||
TableNode* funprime = (TableNode*)malloc(sizeof(SymbolTable));
|
||||
prime->theName= "primitive function";
|
||||
prime->theType=NULL;
|
||||
prime->additionalinfo = NULL;
|
||||
prime->next = NULL;
|
||||
|
||||
integ->theType=prime;
|
||||
addr->theType=prime;
|
||||
chara->theType=prime;
|
||||
stri->theType=striprim;
|
||||
boo->theType=prime;
|
||||
arr->theType=prime;
|
||||
arr->theType=arrayprim;
|
||||
|
||||
//filling in all the values for the additional info for initial types
|
||||
integ->additionalinfo = CreatePrimitiveInfo(4);
|
||||
addr->additionalinfo = CreatePrimitiveInfo(8);
|
||||
chara->additionalinfo = CreatePrimitiveInfo(1);
|
||||
stri->additionalinfo = CreateArrayInfo(1,chara);
|
||||
boo->additionalinfo = CreatePrimitiveInfo(1);
|
||||
//addr->additionalinfo = CreatePrimitiveInfo(8);
|
||||
|
||||
start->Line_Number = 1;
|
||||
start->Column_Number = 1;
|
||||
@ -304,6 +329,7 @@ void print_symbol_table(SymbolTable* table, FILE* file_ptr) {
|
||||
}
|
||||
for (; entrie != NULL; entrie = entrie->next) {
|
||||
if (parant_scope == 0) {
|
||||
if(strcmp(entrie->theType->theName,"function primitive")|| strccmp(entrie->theType->theName,"
|
||||
fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n",
|
||||
entrie->theName, current_scope, entrie->theType->theName,
|
||||
"Extra annotation");
|
||||
|
Reference in New Issue
Block a user