Purple  0.1
Standard Language Specification
symbol_table.h
Go to the documentation of this file.
1
8#ifndef SYMBOL_TABLE
9#define SYMBOL_TABLE
10
11#include <stdbool.h>
12
13#include "types/identifier.h"
14#include "types/type.h"
15
17#define SYMBOL_TABLE_DEFAULT_LENGTH 1024
18
22typedef struct SymbolTableEntry {
26 unsigned int length;
28 unsigned long int bucket_index;
34 unsigned int chain_index;
36
40typedef struct SymbolTable {
42 unsigned long int length;
44 unsigned long int capacity;
46 unsigned long int total_buckets;
52
56typedef struct SymbolTableStack {
57 unsigned long long int length;
60
61// Symbol Table Stack functions
67
68// Symbol Table functions
75SymbolTableEntry* find_symbol_table_entry(SymbolTable* table, char* symbol_name);
76
77// Symbol Table Entry functions
79SymbolTableEntry* add_symbol_table_entry(SymbolTable* table, char* symbol_name, Type type);
80
81#endif /* SYMBOL_TABLE */
Definitions for identifiers.
#define MAX_IDENTIFIER_LENGTH
Definition: identifier.h:12
Struct holding data about a symbol.
Definition: symbol_table.h:22
unsigned long int bucket_index
Definition: symbol_table.h:28
char symbol_name[MAX_IDENTIFIER_LENGTH+1]
Definition: symbol_table.h:24
Type type
Definition: symbol_table.h:30
unsigned int chain_index
Definition: symbol_table.h:34
unsigned int length
Definition: symbol_table.h:26
struct SymbolTableEntry * next
Definition: symbol_table.h:32
Stack of Symbol Tables used for scoping.
Definition: symbol_table.h:56
SymbolTable * top
Definition: symbol_table.h:58
unsigned long long int length
Definition: symbol_table.h:57
Holds data for symbols within a scope.
Definition: symbol_table.h:40
unsigned long int total_buckets
Definition: symbol_table.h:46
unsigned long int length
Definition: symbol_table.h:42
SymbolTableEntry ** buckets
Definition: symbol_table.h:48
struct SymbolTable * next
Definition: symbol_table.h:50
unsigned long int capacity
Definition: symbol_table.h:44
Container for type data.
Definition: type.h:18
struct SymbolTable SymbolTable
Holds data for symbols within a scope.
struct SymbolTableStack SymbolTableStack
Stack of Symbol Tables used for scoping.
SymbolTableEntry * new_symbol_table_entry(char *symbol_name)
Get pointer to new Symbol Table Entry.
Definition: symbol_table.c:180
SymbolTable * peek_symbol_table(SymbolTableStack *stack)
Get pointer of the top Symbol Table from Symbol Table Stack.
Definition: symbol_table.c:112
void free_symbol_table_stack(SymbolTableStack *stack)
Free all memory in a Symbol Table Stack.
Definition: symbol_table.c:44
SymbolTable * new_symbol_table(void)
Get pointer to empty Symbol Table with length SYMBOL_TABLE_DEFAULT_LENGTH.
Definition: symbol_table.c:122
struct SymbolTableEntry SymbolTableEntry
Struct holding data about a symbol.
SymbolTableStack * new_symbol_table_stack(void)
Create a new Symbol Table Stack.
Definition: symbol_table.c:21
SymbolTableEntry * find_symbol_table_entry(SymbolTable *table, char *symbol_name)
Find the entry of a symbol in the provided Symbol Table if it exists.
Definition: symbol_table.c:164
SymbolTable * new_symbol_table_with_length(int length)
Get pointer to empty Symbol Table with a custom length.
Definition: symbol_table.c:132
SymbolTableStack * new_nonempty_symbol_table_stack(void)
Create a new Symbol Table Stack with one empty Symbol Table at the bottom.
Definition: symbol_table.c:34
SymbolTableEntry * add_symbol_table_entry(SymbolTable *table, char *symbol_name, Type type)
Hash symbol_name with hash function FNV-1 and put it into the chained Symbol Table.
Definition: symbol_table.c:199
void resize_symbol_table(SymbolTable *table)
Double the size of a Symbol Table's buckets array.
Definition: symbol_table.c:148
void push_existing_symbol_table(SymbolTableStack *stack, SymbolTable *new_table)
Push existing Symbol Table onto Symbol Table Stack.
Definition: symbol_table.c:67
void push_symbol_table(SymbolTableStack *stack)
Push new empty Symbol Table onto Symbol Table Stack.
Definition: symbol_table.c:56
void pop_and_free_symbol_table(SymbolTableStack *stack)
Remove Symbol Table from Symbol Table Stack and free its memory.
Definition: symbol_table.c:97
SymbolTable * pop_symbol_table(SymbolTableStack *stack)
Remove Symbol Table from Symbol Table Stack and return its pointer.
Definition: symbol_table.c:84
Function headers and defines for.