-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.h
125 lines (106 loc) · 3.66 KB
/
generate.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
113
114
115
116
117
118
119
120
121
122
123
124
125
///////////////////////////////////////////////////////////////////////////////////
// School: Brno University of Technology, Faculty of Information Technology //
// Course: Formal Languages and Compilers //
// Project: IFJ17 //
// Module: Header fole of generator of code //
// Authors: Kristián Liščinský (xlisci01) //
// Matúš Liščinský (xlisci02) //
// Šimon Stupinský (xstupi00) //
// Vladimír Marcin (xmarci10) //
///////////////////////////////////////////////////////////////////////////////////
#ifndef GENERATE_H
#define GENERATE_H
#include "semantic_control.h"
extern struct list_t * list; ///< global instrucion tape as list
#define S "string"
#define I "int"
#define F "float"
/**
* @brief structure represents instruction
*/
typedef struct instruction_t{
char * instr_name; ///< string represents key word with instruction name (operating code)
struct variable_t * op1; ///< pointer to 1st variable
struct variable_t * op2; ///< pointer to 2nd variable
struct variable_t * op3; ///< pointer to 3rd variable
struct instruction_t* next; ///< ponter to next instruction in list
}instruction_t;
/**
* @brief structure of list
*/
typedef struct list_t{
instruction_t * First; ///< pointer to first item of list
instruction_t * Last; ///< pointer to last item of list
}list_t;
/**
* @brief Function to initialize global list (instruction tape)
*/
void list_init();
/**
* @brief Function to print list
*/
void print_list();
/**
* @brief Function to insert instruction for default retype according to var
*
* @param var Pointer to variable
*/
void retype(variable_t * var);
/**
* @brief Proccess string to acceptable form for interpret
*
* @param orig_string Original string
*/
void process_string (char * orig_string);
/**
* @brief Function to generate & add instructions to instr.tape for built-in function length
*
* @param l_value L_value in case of retyping
*/
void length_of_str(variable_t * l_value);
/**
* @brief Function to insert instruction to instr.tape
*
* @param instr Instruction name (key word)
* @param par1 pointer to 1st variable
* @param par2 pointer to 2nd variable
* @param par3 pointer to 3rd variable
*/
void list_insert(char * instr, variable_t * par1, variable_t * par2, variable_t * par3 );
/**
* @brief Function to generate & add instructions to instr.tape for concate two strings
*/
void concat();
/**
* @brief Creates a variable.
*
* @param str1 Instruction name (key word)
* @param[in] constant Define if variable is constant or not
*
* @return Pointer to created variable
*/
variable_t * create_var(char *str1, bool constant);
/**
* @brief Function to generate & add instructions to instr.tape for built-in function substr
*/
void substr();
/**
* @brief Function to generate & add instructions to instr.tape for built-in function asc
*
* @param l_value L_value in case of retyping
*/
void asc(variable_t * l_value);
/**
* @brief Function to generate & add instructions to instr.tape for built-in function chr
*/
void chr();
/**
* @brief Function to generate label name
*
* @param i Integer as end of the string
* @param c Start char of the string
*
* @return Generated label name
*/
char * gen_label_name(int i, char c);
#endif