-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildin.h
189 lines (167 loc) · 4.12 KB
/
buildin.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**
* Implementace překladače imperativního jazyka IFJ22
*
* @file buildin.h
* @author Josef Kuchař ([email protected])
* @author Matej Sirovatka ([email protected])
* @author Tomáš Běhal ([email protected])
* @author Šimon Benčík ([email protected])
* @brief Header file for IFJ22 buildin functions
*/
#ifndef __BUILDIN_H__
#define __BUILDIN_H__
#include "gen.h"
/**
* @brief function write (term1 ,term2 , …, termn) : void
* Writes all terms to the standard output.
* Similar to echo in php.
*
* @param gen Generator instance
*/
void gen_func_write(gen_t* gen);
/**
* @brief function readi() : ?int
* Reads an integer from the standard input.
* Returns null if input is invalid.
*
* @param gen Generator instance
*/
void gen_func_readi(gen_t* gen);
/**
* @brief function readf() : ?float
* Reads a float from the standard input.
* Returns null if input is invalid.
*
* @param gen Generator instance
*/
void gen_func_readf(gen_t* gen);
/**
* @brief function reads() : ?string
* Reads a string from the standard input.
* Returns null if input is invalid.
*
* @param gen Generator instance
*/
void gen_func_reads(gen_t* gen);
/**
* @brief function strlen(string $s) : int
* Returns length of string.
*
* @param gen Generator instance
*/
void gen_func_strlen(gen_t* gen);
/**
* @brief function chr(int $i) : string
* Returns character with ASCII code $i.
*
* @param gen Generator instance
*/
void gen_func_chr(gen_t* gen);
/**
* @brief function ord(string $c) : int
* Returns ASCII code of first character of $c.
* Returns 0 if $c is empty.
*
* @param gen Generator instance
*/
void gen_func_ord(gen_t* gen);
/**
* @brief function substring(string $s, int $i, int $j) : ?string
* Returns substring of $s starting at $i and ending at $j.
*
* Returns null when
* $i < 0
* $j < 0
* $i > $j
* $i >= strlen($s)
* $j > strlen($s)
*
* @param gen Generator instance
*/
void gen_func_substring(gen_t* gen);
/**
* @brief function floatval(term) : float
* Returns float value of term.
* Term can be int, float or null, otherwise generates error
*
* @param gen Generator instance
*/
void gen_func_floatval(gen_t* gen);
/**
* @brief function intval(term) : int
* Returns int value of term.
* Term can be int, float or null, otherwise generates error
*
* @param gen Generator instance
*/
void gen_func_intval(gen_t* gen);
/**
* @brief function strval(term) : string
* Returns string value of term.
* Term can be string or null, otherwise generates error
*
* @param gen Generator instance
*/
void gen_func_strval(gen_t* gen);
/**
* @brief Prepare parameters for arithmetic functions (+, -, *)
* If either of the parameters is null, they are replaced with 0
* If both parameters are int, they are left as int
* If one of parameters is float, both are converted to float
* If either of parameters is string, it raises error
*
* @param gen Generator instance
*/
void gen_num_prepare(gen_t* gen);
/**
* @brief Prepare parameters for division
* If either of the parameters is null, they are replaced with 0
* Converts both parameters to float
* If either of parameters is string, it raises error
*
* @param gen Generator instance
*/
void gen_num_prepare_div(gen_t* gen);
/**
* @brief Concat two strings
* Parameters are on top of stack
* Parameters must be strings or null otherwise generates error
*
* @param gen Generator instance
*/
void gen_concat(gen_t* gen);
/**
* @brief Convert condition to bool value
* Parameter is on top of stack
*
* @param gen Generator instance
*/
void gen_to_bool(gen_t* gen);
/**
* @brief Evaluate === operator
* Parameters are on the top of the stack
*
* @param gen Generator instance
*/
void gen_equals(gen_t* gen);
/**
* @brief Convert ints to floats
*
* @param gen Generator instance
*/
void gen_comp_prepare(gen_t* gen);
/**
* @brief Evaluate > operator
* Parameters are GF@?tmp1 and GF@?tmp2
*
* @param gen Generator instance
*/
void gen_greater(gen_t* gen);
/**
* @brief Evaluate >= operator
* Parameters are GF@?tmp1 and GF@?tmp2
*
* @param gen Generator instance
*/
void gen_greater_equals(gen_t* gen);
#endif