-
Notifications
You must be signed in to change notification settings - Fork 1
/
ial.h
89 lines (73 loc) · 2.14 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
/*****************************************************************************************
*
* IFJ - interpret of IFJ15 language
*
* ial module header
* implmementation of algorithms to IAL
*
* author: Libor Janíček (xjanic21)
* Jakup Kolb (xkolbj00)
* created: 2015-10-30
* modified: 2015-11-17
*
*****************************************************************************************/
#ifndef IAL_H
#define IAL_H
#include <stdbool.h>
#include "scanner.h"
#include "instlist.h"
// find in 'string' substring 'find'
// returns position of first character of 'find' in 'string'
// if 'string' is empty returns 0, if not found returns -1
// implemented by Knuth-Morris-Pratt alhorithm
int find(char *string, char *search);
// sort characters in 'string'
// use Quick sort algorithm
void sort(char *string);
/****************************************************************************************/
#define SYMBOL_TABLE_SIZE 10
// types of symbols
typedef enum {
CONST_ST,
VARIABLE_ST,
FUNCTION_ST,
} symbolType_T;
typedef struct symbolTableItem symbolTableItem_T;
// symbol table structure
typedef struct symbolTable {
struct symbolTable *parrent;
unsigned int count;
symbolTableItem_T *items[SYMBOL_TABLE_SIZE];
} symbolTable_T;
// symbol structure
typedef struct {
symbolType_T type;
dataType_T dataType;
int count;
bool defined;
union {
int intValue;
double doubleValue;
char *stringValue;
void *data;
};
} symbol_T;
// symbol table item
struct symbolTableItem {
symbol_T data;
struct symbolTableItem *next;
char key[];
};
// init 'table'
void initST(symbolTable_T *table);
// destroy 'table' and free all alocated memory
void destroyST(symbolTable_T *table);
// search in 'table' by the 'key'
// return data of table item
// recursive means that symbol will be search in parrent tables
symbol_T *searchST(symbolTable_T *table, char *key, bool recursive);
// insert in to 'table' item with 'data' and 'key'
// if 'key' exist, will be 'data' updated
// return NULL if fail
symbol_T *insertST(symbolTable_T *table, char *key, symbol_T data);
#endif