-
Notifications
You must be signed in to change notification settings - Fork 0
/
ial.h
112 lines (95 loc) · 2.58 KB
/
ial.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* 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 IFJ_IAL_H
#define IFJ_IAL_H
#include "stringology.h"
#include "scanner.h"
#include "int_memory_management.h"
typedef enum {
N_VALUE,
N_FUNCTION,
N_CLASS,
} NodeType;
typedef struct tNode {
char *symbol;
NodeType type;
union {
Value *value;
Function *function;
} data;
struct tNode *left, *right;
} Node;
typedef struct {
Node *root;
} SymbolTable;
typedef struct tList {
int index;
unsigned length;
struct tList *next;
} List;
/* Support functions for IAL algorithms - symbolTable */
Node *createFunctionNode(char *, Function *);
Node *createValueNode(char *, Value *);
Node *createClassNode(char *);
void freeNode(Node *);
void printNode(Node *);
char *showNodeType(NodeType);
SymbolTable *createSymbolTable();
void freeSymbolTable(SymbolTable *);
void printSymbolTable(SymbolTable *);
/* IAL Start */
int *Prefixcreator( char *, int );
int find( char *, char * );
void deleteFirst();
void insertList(int val, int length);
void makeComponents(char* s);
char *sort( char * );
/**
* Rotation of tree left right , left left
* right left and right right for balance of AVL tree
*/
Node *table_rotate_left_right ( Node * );
Node *table_rotate_left_left ( Node* );
Node *table_rotate_right_left ( Node * );
Node *table_rotate_right_right ( Node* );
/**
* count factor of tree based on tree height
*/
int table_node_height( Node * );
int table_balance_factor ( Node * );
/**
* balance Node in AVL table
* returns balanced node which should be
* inserted in balanced tree
*/
Node *table_balance_node( Node * );
/**
* Balance AVL tree after for insertion function
*/
void table_balance( SymbolTable * );
/**
* Inserts Node into created AVL table
*/
void table_insert( SymbolTable *, Node * );
void table_insert_dummy(SymbolTable *, Declaration);
void table_insert_function(SymbolTable *, Function *);
/**
* Removes the Node referenced by `symbol` and returns the deleted node.
*/
Node *table_remove(SymbolTable *, char *);
/**
* Seach for a Node in AVL table
* returns pointer to Node
*/
Node **table_lookup_ptr(SymbolTable *, char *);
Node *table_lookup(SymbolTable *, char *);
Node *table_lookup_either(SymbolTable *global, SymbolTable *local, char *class, char *var);
void table_iterate_fn(Node *, void (*fn)(Function *));
#endif /* IFJ_IAL_H */