-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymbol_table.h
63 lines (53 loc) · 1.49 KB
/
symbol_table.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
58
59
60
61
62
63
#ifndef SYMTAB_H
#define SYMTAB_H
#include "hashmap.h" /* struct hm_item */
#include "astree.h" /* struct astree */
#define SYMBOL_LIT_INT 1
#define SYMBOL_LIT_REAL 2
#define SYMBOL_LIT_CHAR 3
#define SYMBOL_LIT_STRING 4
#define SYMBOL_IDENTIFIER 5
#define ID_VAR 1
#define ID_VEC 2
#define ID_FUN 3
#define TP_DOUBLE 1
#define TP_FLOAT 3
#define TP_LONG 5
#define TP_SHORT 15
#define TP_BYTE 31
#define TP_BOOLEAN 32
/* Test masks compatibility*/
#define TP_ALL ~(0)
#define TP_INCOMP 0
#define TP_INTEGER 5
#define TP_FLOATING 1
/**
* Symbols are:
* - identifiers
* - integer literals
* - real literals
* - character literals
* - string literals
*
* The fields in a symbol table item are:
* - code: the type of symbol. It's filled for all symbols.
* - data_type: the type of data attached to that symbol. It's filled for all
* symbols.
* - id_type: the "nature" of the identifier: varible, vector or function.
* It's only *not* zero when code == SYMBOL_IDENTIFIER.
* - decl: pointer to the symbol declaration in the astree. It's only *not*
* NULL when code == SYMBOL_IDENTIFIER.
*/
struct symtab_item {
int code;
int data_type;
int id_type;
struct astree *decl;
};
void symtab_init(void);
struct hm_item *symtab_insert(const char* symbol, int code);
int symtab_get(const char* symbol, struct symtab_item* dummy);
void symtab_print(void);
void symtab_fprint_item(FILE *stream, struct symtab_item *item);
void symtab_destroy(void);
#endif