-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymtable.h
More file actions
executable file
·57 lines (41 loc) · 1.58 KB
/
symtable.h
File metadata and controls
executable file
·57 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _SYMTABLE_H
#define _SYMTABLE_H
// Header file for the symbol table for variables acquired from the parser
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "hash.h"
enum SCOPE_TYPE {
SCOPE_FILE = 0,
SCOPE_FUNCTION,
SCOPE_BLOCK,
SCOPE_PROTOTYPE
};
// The symbol table - one hash table for each scope
struct symTable {
enum SCOPE_TYPE scope;
char filename[128];
int linedeclared;
// For now, only one namespace, else would use an array of hashTables?
struct hashTable *symbols;
struct symTable *prevTable;
};
struct symbol {
int linedeclared;
int value;
char filename[128];
int scope;
// Could also store identifier's name, but hash table will take care of that when referencing the symbol
};
// Upon entering new scope (i.e. block scope) append new symbol table onto stack (returns this table)
struct symTable *new_symTable(int scope, char *srcfilename, int linenum, struct symTable *parent);
// Takes current symbol and returns parent symbol table
struct symTable *destroy_symTable(struct symTable *current);
// Create a new symbol (when spotting an identifier)
//struct symbol *newSymbol(int linenum, char *srcfilename, int scope);
// Return 0 if insert successful, else 1 if symbol (IDENT) already exists in current scope, else 2 if table is full
int insertSymbol(struct symTable *destTable, char *identKey, void *ptr);
// Returns value of the symbol
void *getSymbol(struct symTable *current, char *identKey);
#endif