forked from thewhoo/ifj15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adt.h
98 lines (87 loc) · 1.97 KB
/
adt.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Course IFJ @ FIT VUT Brno, 2015
* IFJ15 Interpreter Project
*
* Authors:
* Lukas Osadsky - xosads00
* Pavol Plaskon - xplask00
* Pavel Pospisil - xpospi88
* Matej Postolka - xposto02
*
* Unless otherwise stated, all code is licensed under a
* GNU General Public License v2.0
*
*/
/**
* @file types.h
* @brief abstract data types for interpret
*
*/
#ifndef ADTYPES_H
#define ADTYPES_H
#include "ilist.h"
#include "stack.h"
enum vars
{
TYPE_INT,
TYPE_DOUBLE,
TYPE_STRING,
TYPE_PSEUDO,
TYPE_AUTO
};
typedef struct s_variable
{
int var_type;
char *name;
int initialized;
int constant;
union
{
int i;
double d;
char *str;
}data;
} TVariable;
typedef struct s_function
{
char *name;
int return_type;
int defined;
int var_count;
Tins_list *ins_list;
struct hash_tab *local_tab;
TStack *params_stack;
TVariable *return_var;
} TFunction;
typedef struct token
{
int type;
char *data;
} TToken;
/**
* @brief Create TVar representation for local/constant
* symbol table from token.
*
* For int/double/string value - create TVar named by string value, set
* as initialized, value and type is set,
* stored in const table
*
* @param *token ptr to token from lexer
* @return TVariable new initialized TVar
*/
TVariable* token_to_const(TToken* token);
/**
* @brief Creates TFunction representation for global symbol table from token.
*
* Sets funciton name.
* Function "defined" is FALSE (no idea if it's * definition/declaration,
* set it manually later)
* Instruction list for function is initialized and ready for use.
* Local symbol table is initialized and ready.
* Params stack is initialized and ready.
*
* @param *token ptr to token from lexer.
* @return ptr to TFunction type
*/
TFunction* token_to_function(TToken* token);
#endif //ADTYPES_H