1 /* |
1 /* |
2 * (c) 2003-2007 Mario de Sousa |
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
3 * |
3 * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
4 * Offered to the public under the terms of the GNU General Public License |
4 * |
5 * as published by the Free Software Foundation; either version 2 of the |
5 * This program is free software: you can redistribute it and/or modify |
6 * License, or (at your option) any later version. |
6 * it under the terms of the GNU General Public License as published by |
7 * |
7 * the Free Software Foundation, either version 3 of the License, or |
8 * This program is distributed in the hope that it will be useful, but |
8 * (at your option) any later version. |
9 * WITHOUT ANY WARRANTY; without even the implied warranty of |
9 * |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
10 * This program is distributed in the hope that it will be useful, |
11 * Public License for more details. |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 * |
12 * |
18 * |
13 * This code is made available on the understanding that it will not be |
19 * This code is made available on the understanding that it will not be |
14 * used in safety-critical situations without a full and competent review. |
20 * used in safety-critical situations without a full and competent review. |
15 */ |
21 */ |
16 |
22 |
17 /* |
23 /* |
18 * An IEC 61131-3 IL and ST compiler. |
24 * An IEC 61131-3 compiler. |
19 * |
25 * |
20 * Based on the |
26 * Based on the |
21 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
27 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
22 * |
28 * |
23 */ |
29 */ |
|
30 |
24 |
31 |
25 /* |
32 /* |
26 * Definition of the Abstract Syntax data structure components |
33 * Definition of the Abstract Syntax data structure components |
27 */ |
34 */ |
28 |
35 |
44 /*****************************************************************/ |
51 /*****************************************************************/ |
45 /*****************************************************************/ |
52 /*****************************************************************/ |
46 /*****************************************************************/ |
53 /*****************************************************************/ |
47 /*****************************************************************/ |
54 /*****************************************************************/ |
48 /* */ |
55 /* */ |
49 /* Symbols defined in: */ |
56 /* safe<xxxxxx> Symbols are defined in: */ |
50 /* PLCopen - Technical Committee 5 */ |
57 /* PLCopen - Technical Committee 5 */ |
51 /* Safety Software Technical Specification, */ |
58 /* Safety Software Technical Specification, */ |
52 /* Part 1: Concepts and Function Blocks, */ |
59 /* Part 1: Concepts and Function Blocks, */ |
53 /* Version 1.0 – Official Release - 2006-01-31 */ |
60 /* Version 1.0 – Official Release - 2006-01-31 */ |
54 /* */ |
61 /* */ |
127 SYM_TOKEN(hex_integer_c) |
133 SYM_TOKEN(hex_integer_c) |
128 |
134 |
129 /* Note: |
135 /* Note: |
130 * We do not have signed_integer_c and signed_real_c classes. |
136 * We do not have signed_integer_c and signed_real_c classes. |
131 * These are stored in the parse tree as a integer_c or real_c |
137 * These are stored in the parse tree as a integer_c or real_c |
132 * preceded by a unary minus operator. |
138 * preceded by a unary minus operator if they are inside an expression, |
|
139 * or a neg_integer_c and neg_real_c when used outside an ST expression. |
133 */ |
140 */ |
134 /* Not required: |
141 /* Not required: |
135 SYM_TOKEN(signed_integer_c) |
142 SYM_TOKEN(signed_integer_c) |
136 SYM_TOKEN(signed_real_c) |
143 SYM_TOKEN(signed_real_c) |
137 */ |
144 */ |
138 |
145 |
139 SYM_REF1(neg_literal_c, exp) |
146 /* NOTE: literal __values__ are stored directly in classes such as: |
|
147 * - real_c |
|
148 * - integer_c |
|
149 * - binary_integer_c |
|
150 * - etc... |
|
151 * |
|
152 * However, for both the real_c and the integer_c, if they are preceded |
|
153 * by a '-' negation sign, they are further encapsulated inside |
|
154 * a neg_literal_c (i.e. the neg_literal_c will point to the |
|
155 * real_c or integer_c with the value being negated. |
|
156 * neg_literal_c -> integer_literal_c |
|
157 * OR |
|
158 * neg_literal_c -> real_literal_c |
|
159 * |
|
160 * In the semantic verification and code generation stages of the compiler, |
|
161 * the integer_c is treated as a basic (undefined) data type, since an integer |
|
162 * constant may be used as a BYTE, BOOLEAN, REAL, etc..., depending on the |
|
163 * context in which it is used. |
|
164 * However, an integer_c that is preceded by a '-' may not be used |
|
165 * as an ANY_BIT data type (BYTE, BOOLEAN, WORD, ...). |
|
166 * We must therefore be able to determine, holding a simple pointer |
|
167 * to an integer_c, if that integer_c value is preceded by a '-'. |
|
168 * However, since the neg_literal_c points to the integer_c, and not |
|
169 * vice-versa, we can't determine that. |
|
170 * There are 3 simple ways of working around this: |
|
171 * - change the order of the pointers: |
|
172 * have the integer_c and real_c point to the neg_literal_c |
|
173 * - maintain the order of the pointers, and |
|
174 * add redundant info to the integer_c and real_c |
|
175 * - replace the neg_literal_c with two distinc classes |
|
176 * (neg_integer_c and neg_real_c), one for each |
|
177 * lietral type. This means that we can now treat |
|
178 * each of these classes as an unknown data type |
|
179 * just as we do with the integer_c and real_c. |
|
180 * |
|
181 * The second option is simply ugly. |
|
182 * and the first has a serious drawback: when generating code it is |
|
183 * easier to encapsulate the real or integer values inside prefix |
|
184 * and postfix symbols (e.g. NEG(<value>) - with postfix ')' ) |
|
185 * if we keep the pointer order as is. |
|
186 * |
|
187 * For the above reasoning, we use the third option. |
|
188 */ |
|
189 SYM_REF1(neg_real_c, exp) |
|
190 SYM_REF1(neg_integer_c, exp) |
140 |
191 |
141 /* Not required: |
192 /* Not required: |
142 SYM_REF2(numeric_literal_c, type, value) |
193 SYM_REF2(numeric_literal_c, type, value) |
143 */ |
194 */ |
144 SYM_REF2(integer_literal_c, type, value) |
195 SYM_REF2(integer_literal_c, type, value) |
145 SYM_REF2(real_literal_c, type, value) |
196 SYM_REF2(real_literal_c, type, value) |
146 SYM_REF2(bit_string_literal_c, type, value) |
197 SYM_REF2(bit_string_literal_c, type, value) |
|
198 /* A typed or untyped boolean literal... */ |
|
199 /* type may be NULL */ |
147 SYM_REF2(boolean_literal_c, type, value) |
200 SYM_REF2(boolean_literal_c, type, value) |
148 |
201 |
149 /* helper class for boolean_literal_c */ |
202 /* helper class for boolean_literal_c */ |
150 SYM_REF0(boolean_true_c) |
203 SYM_REF0(boolean_true_c) |
151 |
204 |
166 |
219 |
167 /************************/ |
220 /************************/ |
168 /* B 1.2.3.1 - Duration */ |
221 /* B 1.2.3.1 - Duration */ |
169 /************************/ |
222 /************************/ |
170 SYM_REF0(neg_time_c) |
223 SYM_REF0(neg_time_c) |
171 SYM_REF2(duration_c, neg, interval) |
224 SYM_REF3(duration_c, type_name, neg, interval) |
172 SYM_TOKEN(fixed_point_c) |
225 SYM_TOKEN(fixed_point_c) |
173 SYM_REF2(days_c, days, hours) |
226 SYM_REF2(days_c, days, hours) |
174 SYM_REF2(hours_c, hours, minutes) |
227 SYM_REF2(hours_c, hours, minutes) |
175 SYM_REF2(minutes_c, minutes, seconds) |
228 SYM_REF2(minutes_c, minutes, seconds) |
176 SYM_REF2(seconds_c, seconds, milliseconds) |
229 SYM_REF2(seconds_c, seconds, milliseconds) |
178 |
231 |
179 |
232 |
180 /************************************/ |
233 /************************************/ |
181 /* B 1.2.3.2 - Time of day and Date */ |
234 /* B 1.2.3.2 - Time of day and Date */ |
182 /************************************/ |
235 /************************************/ |
183 SYM_REF1(time_of_day_c, daytime) |
236 SYM_REF2(time_of_day_c, type_name, daytime) |
184 SYM_REF3(daytime_c, day_hour, day_minute, day_second) |
237 SYM_REF3(daytime_c, day_hour, day_minute, day_second) |
185 SYM_REF1(date_c, date_literal) |
238 SYM_REF2(date_c, type_name, date_literal) |
186 SYM_REF3(date_literal_c, year, month, day) |
239 SYM_REF3(date_literal_c, year, month, day) |
187 SYM_REF2(date_and_time_c, date_literal, daytime) |
240 SYM_REF3(date_and_time_c, type_name, date_literal, daytime) |
188 |
241 |
189 |
242 |
190 /**********************/ |
243 /**********************/ |
191 /* B.1.3 - Data types */ |
244 /* B.1.3 - Data types */ |
192 /**********************/ |
245 /**********************/ |
213 SYM_REF0(dword_type_name_c) |
266 SYM_REF0(dword_type_name_c) |
214 SYM_REF0(lword_type_name_c) |
267 SYM_REF0(lword_type_name_c) |
215 SYM_REF0(string_type_name_c) |
268 SYM_REF0(string_type_name_c) |
216 SYM_REF0(wstring_type_name_c) |
269 SYM_REF0(wstring_type_name_c) |
217 |
270 |
218 /* |
271 /*****************************************************************/ |
219 SYM_REF0(constant_int_type_name_c) |
272 /* Keywords defined in "Safety Software Technical Specification" */ |
220 SYM_REF0(constant_real_type_name_c) |
273 /*****************************************************************/ |
221 */ |
274 |
|
275 SYM_REF0(safetime_type_name_c) |
|
276 SYM_REF0(safebool_type_name_c) |
|
277 SYM_REF0(safesint_type_name_c) |
|
278 SYM_REF0(safeint_type_name_c) |
|
279 SYM_REF0(safedint_type_name_c) |
|
280 SYM_REF0(safelint_type_name_c) |
|
281 SYM_REF0(safeusint_type_name_c) |
|
282 SYM_REF0(safeuint_type_name_c) |
|
283 SYM_REF0(safeudint_type_name_c) |
|
284 SYM_REF0(safeulint_type_name_c) |
|
285 SYM_REF0(safereal_type_name_c) |
|
286 SYM_REF0(safelreal_type_name_c) |
|
287 SYM_REF0(safedate_type_name_c) |
|
288 SYM_REF0(safetod_type_name_c) |
|
289 SYM_REF0(safedt_type_name_c) |
|
290 SYM_REF0(safebyte_type_name_c) |
|
291 SYM_REF0(safeword_type_name_c) |
|
292 SYM_REF0(safedword_type_name_c) |
|
293 SYM_REF0(safelword_type_name_c) |
|
294 SYM_REF0(safestring_type_name_c) |
|
295 SYM_REF0(safewstring_type_name_c) |
222 |
296 |
223 |
297 |
224 /********************************/ |
298 /********************************/ |
225 /* B.1.3.2 - Generic data types */ |
299 /* B.1.3.2 - Generic data types */ |
226 /********************************/ |
300 /********************************/ |