-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymtable.h
57 lines (42 loc) · 1.06 KB
/
symtable.h
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
/**
* School project to subject IFJ (Formal Languages and Compilers)
* Compiler implementation of imperative language IFJ18
*
* Module for hash table used as symbol table
*
* Author: Julius Marko
* Login: xmarko17
*/
#ifndef _SYMTABLE_H_
#define _SYMTABLE_H_
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define SYMTABLE_SIZE 101
typedef char *t_key;
typedef enum {
FUNCTION,
VARIABLE
} st_elem_types;
typedef struct elem_data {
char *id;
char **params;
size_t params_count;
struct st_elem *fun; // if elem is var then it points to function where its defined
bool defined;
bool is_builtin;
} elem_data;
typedef struct st_elem {
t_key key;
st_elem_types elem_type;
elem_data *data;
struct st_elem *ptrnext;
} st_elem;
typedef st_elem *st[SYMTABLE_SIZE];
int hash_code(t_key key);
void st_init(st *st_ptr);
st_elem *st_search(st *st_ptr, t_key key);
int st_insert(st *st_ptr, t_key key, st_elem_types elem_type, elem_data *data);
void st_clear_elem_data(st_elem *elem);
void st_clear_all(st *st_ptr);
#endif