-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.h
73 lines (57 loc) · 1.51 KB
/
interpreter.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
64
65
66
67
68
69
70
71
72
73
#ifndef __INTERPRETER_H__
#define __INTERPRETER_H__
#include <parser_helper.h>
struct scope;
typedef enum {
VAR_UNKNOWN,
VAR_NONE,
VAR_BOOL,
VAR_INT
} vardecl_e;
typedef struct vardecl {
char* identifier;
vardecl_e type;
int mut;
int initialised;
union {
int iVal;
int bVal;
} item;
struct vardecl* next;
struct scope* containingScope;
} vardecl_t;
typedef enum {
RES_INT,
RES_BOOL,
RES_ERROR,
RES_DECL,
RES_NONE,
RES_CONT
} result_e;
typedef struct result {
result_e type;
union {
int iVal;
int bVal;
char* error;
vardecl_t* decl;
} item;
} result_t;
typedef struct scope {
vardecl_t* vars;
struct scope* parent;
} scope_t;
vardecl_t* getvar(char* name, scope_t* scope);
vardecl_t* newvar(char* name, scope_t* scope);
result_t* interpreter_handledecl(ast_decl_t* t, scope_t* scope);
result_t* interpreter_handlenewident(ast_ident_t* t, scope_t* scope);
result_t* interpreter_handleident(ast_ident_t* t, scope_t* scope);
result_t* interpreter_handlebinop(ast_binop_t* t, scope_t* scope);
result_t* interpreter_handleexpr(ast_expr_t* t, scope_t* scope);
result_t* interpreter_handleassign(ast_assign_t* t, scope_t* scope);
result_t* interpreter_handlestmt(ast_stmt_t* t, scope_t* scope);
result_t* interpreter_handlecond(ast_cond_t* t, scope_t* scope);
result_t* interpreter_handlewhile(ast_while_t* loop, scope_t* scope);
result_t* interpreter_handleblock(ast_block_t* block, scope_t* scope);
result_t* interpretloop(ast_stmt_t* t, scope_t* scope);
#endif