-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpret.h
82 lines (64 loc) · 2.21 KB
/
interpret.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
74
75
76
77
78
79
80
81
82
/*
* Project: IFJ16, a programming language interpreter
* FIT VUT Brno
* Authors: xzaryb00 - Zarybnický Jakub
* xtamas01 - Tamaškovič Marek
* xvasko12 - Vaško Martin
* xvasko14 - Vaško Michal
* xzales12 - Záleský Jiří
*/
#ifndef INTERPRET_H
#define INTERPRET_H
/*--------------------------------LIBRARIES---------------------------------*/
// System libraries
#include <stdbool.h>
#include <assert.h>
#include <string.h>
#include <math.h>
// Local libraries
#include "error.h"
#include "ial.h"
#include "ir.h"
#include "int_memory_management.h"
#include "int_debug.h"
#include "type.h"
/*--------------------------------STRUCTURES--------------------------------*/
typedef struct {
SymbolTable symTable;
} Interpret;
typedef struct Stack{
struct Stack *prev;
int cap;
int size;
Value *data[];
} Stack;
/*-------------------------------Declarations-------------------------------*/
Interpret *createInterpret(void);
int freeInterpret(Interpret *);
// Main interpret function
int evalMain(Interpret *);
//Static variables can be initialiezd using an expression as well, though I
//suppose these expressions shouldn't contain any references to variables?
int interpretNode(Stack *, Node *);
int interpretFunc(Stack *, Node *);
int builtInFunc(Stack *, Function *);
// These functions are needed to evaluate abstract syntax tree.
Value *evalStaticExpression(Expression *);
bool evalCondition(SymbolTable *, Stack *, char *, Expression *);
Value *evalExpression(SymbolTable *, Stack *, char *, Expression *, UnaryOperation);
Value *evalCommand(SymbolTable *, Stack *, Command *, char *);
int evalBlock(SymbolTable *, Stack *, Block *, char *);
void evalFunction(Stack *, SymbolTable *, Function *, char *);
Value *evalUnaryExpression(UnaryOperation, Value *);
Value *evalBinaryExpression(BinaryOperation, Value *, Value *);
// Stack constructor
Stack *createLocalStack(Stack *);
// Work with Stack
int pushToStack(Stack *, Value *);
Value *popFromStack(Stack *);
int pushParamToStack(SymbolTable *, Stack *, char *, Expression *);
void printStack(Stack *);
Stack *createLocalStack(Stack *stack);
int pushToStack(Stack *stack, Value *val);
Value *popFromStack(Stack *stack);
#endif