-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathenv.c
61 lines (47 loc) · 1.01 KB
/
env.c
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
#include <stdio.h>
#include "util.h"
#include "symbol.h"
#include "env.h"
/*Lab4: Your implementation of lab4*/
E_enventry E_VarEntry(Ty_ty ty)
{
E_enventry entry = checked_malloc(sizeof(*entry));
entry->u.var.ty = ty;
return entry;
}
E_enventry E_ROVarEntry(Ty_ty ty)
{
E_enventry entry = checked_malloc(sizeof(*entry));
entry->u.var.ty = ty;
entry->readonly = 1;
return entry;
}
E_enventry E_FunEntry(Ty_tyList formals, Ty_ty result)
{
E_enventry entry = checked_malloc(sizeof(*entry));
entry->u.fun.formals = formals;
entry->u.fun.result = result;
return entry;
}
//sym->value
//type_id(name, S_symbol) -> type (Ty_ty)
S_table E_base_tenv(void)
{
S_table table;
S_symbol ty_int;
S_symbol ty_string;
table = S_empty();
//basic type: string
ty_int = S_Symbol("int");
S_enter(table, ty_int, Ty_Int());
//basic type: string
ty_string = S_Symbol("string");
S_enter(table, ty_string, Ty_String());
return table;
}
S_table E_base_venv(void)
{
S_table table;
table = S_empty();
return table;
}