edited symbol table node structure to remove strlength and value as they are not needed
This commit is contained in:
@ -1,45 +1,8 @@
|
|||||||
//Defining a symbol table
|
//Defining a symbol table
|
||||||
//Using a Linked List Structure. Head of linked List points to parent scope (if one exists)
|
//Using a Linked List Structure. Head of linked List points to parent scope (if one exists)
|
||||||
//Tail of Linked List points to a Linked List of all the child scopes
|
//Tail of Linked List points to a List of child scopes
|
||||||
//T
|
|
||||||
//*#include "symbol_table.h"
|
|
||||||
/*
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef struct ListOfTable{
|
#include "symbol_table.h"
|
||||||
struct SymbolTable* table;
|
|
||||||
//struct ListOfTable* prev;
|
|
||||||
struct ListOfTable* next;
|
|
||||||
|
|
||||||
}ListOfTable;
|
|
||||||
|
|
||||||
typedef union Value{
|
|
||||||
int* value_of_int;
|
|
||||||
void* value_of_pointer;
|
|
||||||
bool* value_of_bool;
|
|
||||||
char* value_of_char;
|
|
||||||
}Value;
|
|
||||||
|
|
||||||
typedef struct TableNode{
|
|
||||||
char* theType;
|
|
||||||
char* theName;
|
|
||||||
Value* value;
|
|
||||||
struct TableNode* next;
|
|
||||||
//this next value is an int for string types to tell you how far to traverse a buffer for the string
|
|
||||||
int StrLength;
|
|
||||||
}TableNode;
|
|
||||||
|
|
||||||
typedef struct SymbolTable{
|
|
||||||
TableNode* entries;
|
|
||||||
struct SymbolTable* Parent_Scope;
|
|
||||||
struct ListOfTable* Children_Scope;
|
|
||||||
int Line_Number;
|
|
||||||
int Column_Number;
|
|
||||||
}SymbolTable;
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
|
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
|
||||||
SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable));
|
SymbolTable* table = (SymbolTable*)malloc(sizeof(SymbolTable));
|
||||||
@ -68,12 +31,10 @@ SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, int StringLength){
|
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id){
|
||||||
TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
|
TableNode* newEntry = (TableNode*)malloc(sizeof(TableNode));
|
||||||
newEntry->theType = typeOf;
|
newEntry->theType = typeOf;
|
||||||
newEntry->theName = id;
|
newEntry->theName = id;
|
||||||
newEntry->value = value;
|
|
||||||
newEntry->StrLength = StringLength;
|
|
||||||
if(table->entries == NULL){
|
if(table->entries == NULL){
|
||||||
table->entries = newEntry;
|
table->entries = newEntry;
|
||||||
return newEntry;
|
return newEntry;
|
||||||
@ -86,16 +47,13 @@ TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//uncomment the below main function along with the headers above for a simple standalone test of table and entry creation
|
//uncomment the below main function along with the headers above for a simple standalone test of table and entry creation
|
||||||
/*
|
|
||||||
int main(){
|
int main(){
|
||||||
char* String = "STRING";
|
char* String = "STRING";
|
||||||
char* X = "X";
|
char* X = "X";
|
||||||
Value* ofX = (Value*)malloc(sizeof(Value));
|
|
||||||
ofX->value_of_char = X;
|
|
||||||
SymbolTable* Second = CreateScope(NULL, 2,2);
|
SymbolTable* Second = CreateScope(NULL, 2,2);
|
||||||
printf("Line number is %d, Column number of scope is %d\n",Second->Line_Number,Second->Column_Number);
|
printf("Line number is %d, Column number of scope is %d\n",Second->Line_Number,Second->Column_Number);
|
||||||
TableNode* First_Entry = CreateEntry(Second,String,X,ofX,-1);
|
TableNode* First_Entry = CreateEntry(Second,String,X);
|
||||||
printf("The value of the first entry is %s\n",First_Entry->value->value_of_char);
|
printf("The type of the first entry is %s\n",First_Entry->theType);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
@ -9,20 +9,10 @@ typedef struct ListOfTable{
|
|||||||
|
|
||||||
}ListOfTable;
|
}ListOfTable;
|
||||||
|
|
||||||
typedef union Value{
|
|
||||||
int* value_of_int;
|
|
||||||
void* value_of_pointer;
|
|
||||||
bool* value_of_bool;
|
|
||||||
char* value_of_char;
|
|
||||||
}Value;
|
|
||||||
|
|
||||||
typedef struct TableNode{
|
typedef struct TableNode{
|
||||||
char* theType;
|
char* theType;
|
||||||
char* theName;
|
char* theName;
|
||||||
Value* value;
|
|
||||||
struct TableNode* next;
|
struct TableNode* next;
|
||||||
//this next value is an int for string types to tell you how far to traverse a buffer for the string
|
|
||||||
int StrLength;
|
|
||||||
}TableNode;
|
}TableNode;
|
||||||
|
|
||||||
typedef struct SymbolTable{
|
typedef struct SymbolTable{
|
||||||
@ -34,5 +24,5 @@ typedef struct SymbolTable{
|
|||||||
}SymbolTable;
|
}SymbolTable;
|
||||||
|
|
||||||
|
|
||||||
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id, Value* value, int StringLength);
|
TableNode* CreateEntry(SymbolTable* table, char* typeOf, char* id);
|
||||||
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column);
|
SymbolTable* CreateScope(SymbolTable* ParentScope, int Line, int Column);
|
||||||
|
Reference in New Issue
Block a user