restructured table, still have to update print table properly as well as grammar rules
This commit is contained in:
@ -77,10 +77,12 @@ typedef union {
|
||||
}AdInfo;
|
||||
*/
|
||||
|
||||
primitive_info* CreatePrimitiveInfo(size){
|
||||
primitive_info* prim = (primitive_info*)malloc(sizeof(primitive_info));
|
||||
prim.size=size;
|
||||
return prim;
|
||||
AdInfo* CreatePrimitiveInfo(int size){
|
||||
|
||||
AdInfo* info = (AdInfo*)malloc(sizeof(AdInfo));
|
||||
info->PrimAdInfo = (primitive_info*)malloc(sizeof(primitive_info));
|
||||
info->PrimAdInfo->size=size;
|
||||
return info;
|
||||
}
|
||||
|
||||
//probably don't need the below structure since can create from an array
|
||||
@ -91,35 +93,39 @@ primitive_info* CreatePrimitiveInfo(size){
|
||||
return stringy;
|
||||
}
|
||||
*/
|
||||
array_info* CreateArrayInfo(int dim, /*int* sizes,*/ TableNode* type){
|
||||
array_info* arr = (array_info*)malloc(sizeof(array_info));
|
||||
arr.numofdimensions=dim;
|
||||
arr->typeofarray=type;
|
||||
AdInfo* CreateArrayInfo(int dim, /*int* sizes,*/ TableNode* type){
|
||||
AdInfo* info = (AdInfo*)malloc(sizeof(AdInfo));
|
||||
info->ArrayAdInfo = (array_info*)malloc(sizeof(array_info));
|
||||
info->ArrayAdInfo->numofdimensions=dim;
|
||||
info->ArrayAdInfo->typeofarray=type;
|
||||
//avoiding storing any types like below
|
||||
//int* dimensionsizes = loc;
|
||||
return arr;
|
||||
return info;
|
||||
}
|
||||
|
||||
record_info* CreateRecordInfo(int length, TableNode* typesarray){
|
||||
record_info* reccy = (record_info*)malloc(sizeof(record_info));
|
||||
reccy.numofelements=length;
|
||||
reccy->listoftypes = typesarray;
|
||||
return reccy;
|
||||
AdInfo* CreateRecordInfo(int length, TableNode* typesarray){
|
||||
AdInfo* info = (AdInfo*)malloc(sizeof(AdInfo));
|
||||
info->RecAdInfo = (record_info*)malloc(sizeof(record_info));
|
||||
info->RecAdInfo->numofelements=length;
|
||||
info->RecAdInfo->listoftypes = typesarray;
|
||||
return info;
|
||||
}
|
||||
|
||||
//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;
|
||||
fundec.regularoras = asorregular;
|
||||
return fundec;
|
||||
AdInfo* CreateFunctionDeclarationInfo(int line, bool asorregular){
|
||||
AdInfo* info = (AdInfo*)malloc(sizeof(AdInfo));
|
||||
info->FunDecAdInfo = (function_declaration_info*)malloc(sizeof(function_declaration_info));
|
||||
info->FunDecAdInfo->startlinenumber=line;
|
||||
info->FunDecAdInfo->regularoras = asorregular;
|
||||
return info;
|
||||
}
|
||||
|
||||
function_type_info* CreateFunctionTypeInfo(TableNode* parameter, TableNode* returntype){
|
||||
function_type_info* funtype = (function_type_info*)malloc(sizeof(function_type_info));
|
||||
funtype->parameter=parameter;
|
||||
funtype->returntype = returntype;
|
||||
return funtype;
|
||||
AdInfo* CreateFunctionTypeInfo(TableNode* parameter, TableNode* returntype){
|
||||
AdInfo* info = (AdInfo*)malloc(sizeof(AdInfo));
|
||||
info->FunTypeAdInfo = (function_type_info*)malloc(sizeof(function_type_info));
|
||||
info->FunTypeAdInfo->parameter=parameter;
|
||||
info->FunTypeAdInfo->returntype = returntype;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -205,9 +211,9 @@ SymbolTable* init(SymbolTable* start){
|
||||
integ->theType=prime;
|
||||
addr->theType=prime;
|
||||
chara->theType=prime;
|
||||
stri->theType=striprim;
|
||||
stri->theType=arrayprim;
|
||||
boo->theType=prime;
|
||||
arr->theType=arrayprim;
|
||||
//arr->theType=arrayprim;
|
||||
|
||||
//filling in all the values for the additional info for initial types
|
||||
integ->additionalinfo = CreatePrimitiveInfo(4);
|
||||
@ -329,7 +335,8 @@ 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,"
|
||||
/*have to update*/ if(strcmp(entrie->theType->theName,"function primitive")|| strcmp(entrie->theType->theName,"array")){
|
||||
}
|
||||
fprintf(file_ptr, "%-17s: %06d : : %-21s: %-28s\n",
|
||||
entrie->theName, current_scope, entrie->theType->theName,
|
||||
"Extra annotation");
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct TableNode;
|
||||
|
||||
typedef struct{
|
||||
int size;
|
||||
}primitive_info;
|
||||
@ -21,12 +23,13 @@ typedef struct{
|
||||
//shouldn't need to store any values (like sizes of dimenions or the location
|
||||
//int* sizesofdimensions;
|
||||
//do have to store type of array
|
||||
TableNode* typeofarray;
|
||||
struct TableNode* typeofarray;
|
||||
}array_info;
|
||||
|
||||
typedef struct{
|
||||
//similar to above we define a record to hold the number of elements and an array of tablenodes (types) that it contains in the > int numofelements;
|
||||
TableNode* listoftypes;
|
||||
//similar to above we define a record to hold the number of elements and an array of tablenodes (types) that it contains in the >
|
||||
int numofelements;
|
||||
struct TableNode* listoftypes;
|
||||
}record_info;
|
||||
|
||||
typedef struct{
|
||||
@ -35,8 +38,8 @@ typedef struct{
|
||||
}function_declaration_info;
|
||||
|
||||
typedef struct{
|
||||
TableNode* parameter;
|
||||
TableNode* returntype;
|
||||
struct TableNode* parameter;
|
||||
struct TableNode* returntype;
|
||||
}function_type_info;
|
||||
|
||||
typedef union {
|
||||
@ -44,8 +47,8 @@ typedef union {
|
||||
array_info* ArrayAdInfo;
|
||||
record_info* RecAdInfo;
|
||||
//string_info* StringAdInfo;
|
||||
func_dec_info* FunDecAdInfo;
|
||||
func_type_info* FunTypeAdInfo;
|
||||
function_declaration_info* FunDecAdInfo;
|
||||
function_type_info* FunTypeAdInfo;
|
||||
}AdInfo;
|
||||
|
||||
typedef struct ListOfTable {
|
||||
@ -56,7 +59,7 @@ typedef struct ListOfTable {
|
||||
|
||||
typedef struct TableNode {
|
||||
//reference to the type entry that this is
|
||||
TableNode* theType;
|
||||
struct TableNode* theType;
|
||||
char* theName;
|
||||
AdInfo* additionalinfo;
|
||||
struct TableNode* next;
|
||||
@ -71,7 +74,6 @@ typedef struct SymbolTable {
|
||||
} SymbolTable;
|
||||
|
||||
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column);
|
||||
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id);
|
||||
TableNode* table_lookup(SymbolTable* table, char* x);
|
||||
TableNode* look_up(SymbolTable* table, char* x);
|
||||
void print_symbol_table(SymbolTable* table, FILE* file_ptr);
|
||||
@ -83,6 +85,7 @@ SymbolTable* getFirstChild(ListOfTable* lt);
|
||||
ListOfTable* getRestOfChildren(ListOfTable* lt);
|
||||
TableNode* getFirstEntry(SymbolTable* st);
|
||||
TableNode* getNextEntry(TableNode* tn);
|
||||
SymbolTable* init(SymbolTable* scope);
|
||||
char* getType(TableNode* tn);
|
||||
char* getName(TableNode* tn);
|
||||
int getLine(SymbolTable* st);
|
||||
|
Reference in New Issue
Block a user