|
1 /* |
|
2 * (c) 2003 Mario de Sousa |
|
3 * |
|
4 * Offered to the public under the terms of the GNU General Public License |
|
5 * as published by the Free Software Foundation; either version 2 of the |
|
6 * License, or (at your option) any later version. |
|
7 * |
|
8 * This program is distributed in the hope that it will be useful, but |
|
9 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
11 * Public License for more details. |
|
12 * |
|
13 * 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. |
|
15 */ |
|
16 |
|
17 /* |
|
18 * An IEC 61131-3 IL and ST compiler. |
|
19 * |
|
20 * Based on the |
|
21 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
|
22 * |
|
23 */ |
|
24 |
|
25 /* |
|
26 * Definition of the Abstract Syntax data structure components |
|
27 */ |
|
28 |
|
29 |
|
30 /* |
|
31 * ABSYNTAX.DEF |
|
32 * |
|
33 * This generates the parse tree structure used to bind the components |
|
34 * identified by Bison in the correct syntax order. At the end of the |
|
35 * Bison analysis the tree is walked in a sequential fashion generating |
|
36 * the relavent code. |
|
37 */ |
|
38 |
|
39 |
|
40 /***************************/ |
|
41 /* 2.1.6 - Pragmas */ |
|
42 /***************************/ |
|
43 SYM_TOKEN(pragma_c) |
|
44 |
|
45 |
|
46 /***************************/ |
|
47 /* B 0 - Programming Model */ |
|
48 /***************************/ |
|
49 SYM_LIST(library_c) |
|
50 |
|
51 |
|
52 /*************************/ |
|
53 /* B.1 - Common elements */ |
|
54 /*************************/ |
|
55 /*******************************************/ |
|
56 /* B 1.1 - Letters, digits and identifiers */ |
|
57 /*******************************************/ |
|
58 SYM_TOKEN(identifier_c) |
|
59 |
|
60 |
|
61 /*********************/ |
|
62 /* B 1.2 - Constants */ |
|
63 /*********************/ |
|
64 |
|
65 /******************************/ |
|
66 /* B 1.2.1 - Numeric Literals */ |
|
67 /******************************/ |
|
68 SYM_TOKEN(real_c) |
|
69 SYM_TOKEN(integer_c) |
|
70 SYM_TOKEN(binary_integer_c) |
|
71 SYM_TOKEN(octal_integer_c) |
|
72 SYM_TOKEN(hex_integer_c) |
|
73 |
|
74 /* Note: |
|
75 * We do not have signed_integer_c and signed_real_c classes. |
|
76 * These are stored in the parse tree as a integer_c or real_c |
|
77 * preceded by a unary minus operator. |
|
78 */ |
|
79 /* Not required: |
|
80 SYM_TOKEN(signed_integer_c) |
|
81 SYM_TOKEN(signed_real_c) |
|
82 */ |
|
83 |
|
84 SYM_REF2(numeric_literal_c, type, value) |
|
85 SYM_REF2(integer_literal_c, type, value) |
|
86 SYM_REF2(real_literal_c, type, value) |
|
87 SYM_REF2(bit_string_literal_c, type, value) |
|
88 SYM_REF2(boolean_literal_c, type, value) |
|
89 |
|
90 /* helper class for boolean_literal_c */ |
|
91 SYM_REF0(boolean_true_c) |
|
92 |
|
93 /* helper class for boolean_literal_c */ |
|
94 SYM_REF0(boolean_false_c) |
|
95 |
|
96 |
|
97 /*******************************/ |
|
98 /* B.1.2.2 Character Strings */ |
|
99 /*******************************/ |
|
100 SYM_TOKEN(double_byte_character_string_c) |
|
101 SYM_TOKEN(single_byte_character_string_c) |
|
102 |
|
103 |
|
104 /***************************/ |
|
105 /* B 1.2.3 - Time Literals */ |
|
106 /***************************/ |
|
107 |
|
108 /************************/ |
|
109 /* B 1.2.3.1 - Duration */ |
|
110 /************************/ |
|
111 SYM_REF0(neg_time_c) |
|
112 SYM_REF2(duration_c, neg, interval) |
|
113 SYM_TOKEN(fixed_point_c) |
|
114 SYM_REF2(days_c, days, hours) |
|
115 SYM_REF2(hours_c, hours, minutes) |
|
116 SYM_REF2(minutes_c, minutes, seconds) |
|
117 SYM_REF2(seconds_c, seconds, milliseconds) |
|
118 SYM_REF2(milliseconds_c, milliseconds, unused) |
|
119 |
|
120 |
|
121 /************************************/ |
|
122 /* B 1.2.3.2 - Time of day and Date */ |
|
123 /************************************/ |
|
124 SYM_REF2(time_of_day_c, daytime, unused) |
|
125 SYM_REF4(daytime_c, day_hour, day_minute, day_second, unused) |
|
126 SYM_REF2(date_c, date_literal, unused) |
|
127 SYM_REF4(date_literal_c, year, month, day, unused) |
|
128 SYM_REF2(date_and_time_c, date_literal, daytime) |
|
129 |
|
130 |
|
131 /**********************/ |
|
132 /* B.1.3 - Data types */ |
|
133 /**********************/ |
|
134 /***********************************/ |
|
135 /* B 1.3.1 - Elementary Data Types */ |
|
136 /***********************************/ |
|
137 SYM_REF0(time_type_name_c) |
|
138 SYM_REF0(bool_type_name_c) |
|
139 SYM_REF0(sint_type_name_c) |
|
140 SYM_REF0(int_type_name_c) |
|
141 SYM_REF0(dint_type_name_c) |
|
142 SYM_REF0(lint_type_name_c) |
|
143 SYM_REF0(usint_type_name_c) |
|
144 SYM_REF0(uint_type_name_c) |
|
145 SYM_REF0(udint_type_name_c) |
|
146 SYM_REF0(ulint_type_name_c) |
|
147 SYM_REF0(real_type_name_c) |
|
148 SYM_REF0(lreal_type_name_c) |
|
149 SYM_REF0(date_type_name_c) |
|
150 SYM_REF0(tod_type_name_c) |
|
151 SYM_REF0(dt_type_name_c) |
|
152 SYM_REF0(byte_type_name_c) |
|
153 SYM_REF0(word_type_name_c) |
|
154 SYM_REF0(dword_type_name_c) |
|
155 SYM_REF0(lword_type_name_c) |
|
156 SYM_REF0(string_type_name_c) |
|
157 SYM_REF0(wstring_type_name_c) |
|
158 |
|
159 |
|
160 |
|
161 /********************************/ |
|
162 /* B.1.3.2 - Generic data types */ |
|
163 /********************************/ |
|
164 |
|
165 /********************************/ |
|
166 /* B 1.3.3 - Derived data types */ |
|
167 /********************************/ |
|
168 /* TYPE type_declaration_list END_TYPE */ |
|
169 SYM_REF2(data_type_declaration_c, type_declaration_list, unused) |
|
170 |
|
171 /* helper symbol for data_type_declaration */ |
|
172 SYM_LIST(type_declaration_list_c) |
|
173 |
|
174 /* simple_type_name ':' simple_spec_init */ |
|
175 SYM_REF2(simple_type_declaration_c, simple_type_name, simple_spec_init) |
|
176 |
|
177 |
|
178 /* simple_specification ASSIGN constant */ |
|
179 SYM_REF2(simple_spec_init_c, simple_specification, constant) |
|
180 |
|
181 /* subrange_type_name ':' subrange_spec_init */ |
|
182 SYM_REF2(subrange_type_declaration_c, subrange_type_name, subrange_spec_init) |
|
183 |
|
184 /* subrange_specification ASSIGN signed_integer */ |
|
185 SYM_REF2(subrange_spec_init_c, subrange_specification, signed_integer) |
|
186 |
|
187 /* integer_type_name '(' subrange')' */ |
|
188 SYM_REF2(subrange_specification_c, integer_type_name, subrange) |
|
189 |
|
190 /* signed_integer DOTDOT signed_integer */ |
|
191 SYM_REF2(subrange_c, lower_limit, upper_limit) |
|
192 |
|
193 /* enumerated_type_name ':' enumerated_spec_init */ |
|
194 SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init) |
|
195 |
|
196 /* enumerated_specification ASSIGN enumerated_value */ |
|
197 SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value) |
|
198 |
|
199 /* helper symbol for enumerated_specification->enumerated_spec_init */ |
|
200 /* enumerated_value_list ',' enumerated_value */ |
|
201 SYM_LIST(enumerated_value_list_c) |
|
202 |
|
203 /* enumerated_type_name '#' identifier */ |
|
204 SYM_REF2(enumerated_value_c, type, value) |
|
205 |
|
206 /* identifier ':' array_spec_init */ |
|
207 SYM_REF2(array_type_declaration_c, identifier, array_spec_init) |
|
208 |
|
209 /* array_specification [ASSIGN array_initialization} */ |
|
210 /* array_initialization may be NULL ! */ |
|
211 SYM_REF2(array_spec_init_c, array_specification, array_initialization) |
|
212 |
|
213 /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ |
|
214 SYM_REF2(array_specification_c, array_subrange_list, non_generic_type_name) |
|
215 |
|
216 /* helper symbol for array_specification */ |
|
217 /* array_subrange_list ',' subrange */ |
|
218 SYM_LIST(array_subrange_list_c) |
|
219 |
|
220 /* array_initialization: '[' array_initial_elements_list ']' */ |
|
221 /* helper symbol for array_initialization */ |
|
222 /* array_initial_elements_list ',' array_initial_elements */ |
|
223 SYM_LIST(array_initial_elements_list_c) |
|
224 |
|
225 /* integer '(' [array_initial_element] ')' */ |
|
226 /* array_initial_element may be NULL ! */ |
|
227 SYM_REF2(array_initial_elements_c, integer, array_initial_element) |
|
228 |
|
229 /* structure_type_name ':' structure_specification */ |
|
230 SYM_REF2(structure_type_declaration_c, structure_type_name, structure_specification) |
|
231 |
|
232 /* structure_type_name ASSIGN structure_initialization */ |
|
233 /* structure_initialization may be NULL ! */ |
|
234 SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization) |
|
235 |
|
236 /* helper symbol for structure_declaration */ |
|
237 /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ |
|
238 /* structure_element_declaration_list structure_element_declaration ';' */ |
|
239 SYM_LIST(structure_element_declaration_list_c) |
|
240 |
|
241 /* structure_element_name ':' *_spec_init */ |
|
242 SYM_REF2(structure_element_declaration_c, structure_element_name, spec_init) |
|
243 |
|
244 /* helper symbol for structure_initialization */ |
|
245 /* structure_initialization: '(' structure_element_initialization_list ')' */ |
|
246 /* structure_element_initialization_list ',' structure_element_initialization */ |
|
247 SYM_LIST(structure_element_initialization_list_c) |
|
248 |
|
249 /* structure_element_name ASSIGN value */ |
|
250 SYM_REF2(structure_element_initialization_c, structure_element_name, value) |
|
251 |
|
252 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
253 /* |
|
254 * NOTE: |
|
255 * (Summary: Contrary to what is expected, the |
|
256 * string_type_declaration_c is not used to store |
|
257 * simple string type declarations that do not include |
|
258 * size limits. |
|
259 * For e.g.: |
|
260 * str1_type: STRING := "hello!" |
|
261 * will be stored in a simple_type_declaration_c |
|
262 * instead of a string_type_declaration_c. |
|
263 * The following: |
|
264 * str2_type: STRING [64] := "hello!" |
|
265 * will be stored in a sring_type_declaration_c |
|
266 * |
|
267 * Read on for why this is done... |
|
268 * End Summary) |
|
269 * |
|
270 * According to the spec, the valid construct |
|
271 * TYPE new_str_type : STRING := "hello!"; END_TYPE |
|
272 * has two possible routes to type_declaration... |
|
273 * |
|
274 * Route 1: |
|
275 * type_declaration: single_element_type_declaration |
|
276 * single_element_type_declaration: simple_type_declaration |
|
277 * simple_type_declaration: identifier ':' simple_spec_init |
|
278 * simple_spec_init: simple_specification ASSIGN constant |
|
279 * (shift: identifier <- 'new_str_type') |
|
280 * simple_specification: elementary_type_name |
|
281 * elementary_type_name: STRING |
|
282 * (shift: elementary_type_name <- STRING) |
|
283 * (reduce: simple_specification <- elementary_type_name) |
|
284 * (shift: constant <- "hello!") |
|
285 * (reduce: simple_spec_init: simple_specification ASSIGN constant) |
|
286 * (reduce: ...) |
|
287 * |
|
288 * |
|
289 * Route 2: |
|
290 * type_declaration: string_type_declaration |
|
291 * string_type_declaration: identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init |
|
292 * (shift: identifier <- 'new_str_type') |
|
293 * elementary_string_type_name: STRING |
|
294 * (shift: elementary_string_type_name <- STRING) |
|
295 * (shift: string_type_declaration_size <- empty ) |
|
296 * string_type_declaration_init: ASSIGN character_string |
|
297 * (shift: character_string <- "hello!") |
|
298 * (reduce: string_type_declaration_init <- ASSIGN character_string) |
|
299 * (reduce: string_type_declaration <- identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init ) |
|
300 * (reduce: type_declaration <- string_type_declaration) |
|
301 * |
|
302 * |
|
303 * At first glance it seems that removing route 1 would make |
|
304 * the most sense. Unfortunately the construct 'simple_spec_init' |
|
305 * shows up multiple times in other rules, so changing this construct |
|
306 * would also mean changing all the rules in which it appears. |
|
307 * I (Mario) therefore chose to remove route 2 instead. This means |
|
308 * that the above declaration gets stored in a |
|
309 * simple_type_declaration_c, and not in a string_type_declaration_c |
|
310 * as would be expected! |
|
311 */ |
|
312 /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ |
|
313 SYM_REF4(string_type_declaration_c, string_type_name, |
|
314 elementary_string_type_name, |
|
315 string_type_declaration_size, |
|
316 string_type_declaration_init) /* may be == NULL! */ |
|
317 |
|
318 |
|
319 /*********************/ |
|
320 /* B 1.4 - Variables */ |
|
321 /*********************/ |
|
322 SYM_REF2(symbolic_variable_c, var_name, unused) |
|
323 |
|
324 /********************************************/ |
|
325 /* B.1.4.1 Directly Represented Variables */ |
|
326 /********************************************/ |
|
327 SYM_TOKEN(direct_variable_c) |
|
328 |
|
329 /*************************************/ |
|
330 /* B.1.4.2 Multi-element Variables */ |
|
331 /*************************************/ |
|
332 /* subscripted_variable '[' subscript_list ']' */ |
|
333 SYM_REF2(array_variable_c, subscripted_variable, subscript_list) |
|
334 |
|
335 /* subscript_list ',' subscript */ |
|
336 SYM_LIST(subscript_list_c) |
|
337 |
|
338 /* record_variable '.' field_selector */ |
|
339 /* WARNING: input and/or output variables of function blocks |
|
340 * may be accessed as fields of a tructured variable! |
|
341 * Code handling a structured_variable_c must take |
|
342 * this into account! |
|
343 */ |
|
344 SYM_REF2(structured_variable_c, record_variable, field_selector) |
|
345 |
|
346 /******************************************/ |
|
347 /* B 1.4.3 - Declaration & Initialisation */ |
|
348 /******************************************/ |
|
349 SYM_REF0(constant_option_c) |
|
350 SYM_REF0(retain_option_c) |
|
351 SYM_REF0(non_retain_option_c) |
|
352 |
|
353 /* option -> the RETAIN/NON_RETAIN/<NULL> directive... */ |
|
354 SYM_REF2(input_declarations_c, option, input_declaration_list) |
|
355 |
|
356 /* helper symbol for input_declarations */ |
|
357 SYM_LIST(input_declaration_list_c) |
|
358 |
|
359 /* edge -> The F_EDGE or R_EDGE directive */ |
|
360 SYM_REF2(edge_declaration_c, edge, var1_list) |
|
361 |
|
362 SYM_REF0(raising_edge_option_c) |
|
363 SYM_REF0(falling_edge_option_c) |
|
364 |
|
365 /* spec_init is one of the following... |
|
366 * simple_spec_init_c * |
|
367 * subrange_spec_init_c * |
|
368 * enumerated_spec_init_c * |
|
369 */ |
|
370 SYM_REF2(var1_init_decl_c, var1_list, spec_init) |
|
371 |
|
372 /* | var1_list ',' variable_name */ |
|
373 SYM_LIST(var1_list_c) |
|
374 |
|
375 /* var1_list ':' array_spec_init */ |
|
376 SYM_REF2(array_var_init_decl_c, var1_list, array_spec_init) |
|
377 |
|
378 /* var1_list ':' initialized_structure */ |
|
379 SYM_REF2(structured_var_init_decl_c, var1_list, initialized_structure) |
|
380 |
|
381 /* fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ |
|
382 /* structure_initialization -> may be NULL ! */ |
|
383 SYM_REF4(fb_name_decl_c, fb_name_list, function_block_type_name, structure_initialization, unused) |
|
384 |
|
385 /* fb_name_list ',' fb_name */ |
|
386 SYM_LIST(fb_name_list_c) |
|
387 |
|
388 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ |
|
389 /* option -> may be NULL ! */ |
|
390 SYM_REF2(output_declarations_c, option, var_init_decl_list) |
|
391 |
|
392 /* VAR_IN_OUT var_declaration_list END_VAR */ |
|
393 SYM_REF2(input_output_declarations_c, var_declaration_list, unused) |
|
394 |
|
395 /* helper symbol for input_output_declarations */ |
|
396 /* var_declaration_list var_declaration ';' */ |
|
397 SYM_LIST(var_declaration_list_c) |
|
398 |
|
399 /* var1_list ':' array_specification */ |
|
400 SYM_REF2(array_var_declaration_c, var1_list, array_specification) |
|
401 |
|
402 /* var1_list ':' structure_type_name */ |
|
403 SYM_REF2(structured_var_declaration_c, var1_list, structure_type_name) |
|
404 |
|
405 /* VAR [CONSTANT] var_init_decl_list END_VAR */ |
|
406 /* option -> may be NULL ! */ |
|
407 SYM_REF2(var_declarations_c, option, var_init_decl_list) |
|
408 |
|
409 /* VAR RETAIN var_init_decl_list END_VAR */ |
|
410 SYM_REF2(retentive_var_declarations_c, var_init_decl_list, unused) |
|
411 |
|
412 /* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ |
|
413 /* option -> may be NULL ! */ |
|
414 SYM_REF2(located_var_declarations_c, option, located_var_decl_list) |
|
415 |
|
416 /* helper symbol for located_var_declarations */ |
|
417 /* located_var_decl_list located_var_decl ';' */ |
|
418 SYM_LIST(located_var_decl_list_c) |
|
419 |
|
420 /* [variable_name] location ':' located_var_spec_init */ |
|
421 /* variable_name -> may be NULL ! */ |
|
422 SYM_REF4(located_var_decl_c, variable_name, location, located_var_spec_init, unused) |
|
423 |
|
424 /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ |
|
425 /* option -> may be NULL ! */ |
|
426 SYM_REF2(external_var_declarations_c, option, external_declaration_list) |
|
427 |
|
428 /* helper symbol for external_var_declarations */ |
|
429 /*| external_declaration_list external_declaration';' */ |
|
430 SYM_LIST(external_declaration_list_c) |
|
431 |
|
432 /* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name */ |
|
433 SYM_REF2(external_declaration_c, global_var_name, specification) |
|
434 |
|
435 /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ |
|
436 /* option -> may be NULL ! */ |
|
437 SYM_REF2(global_var_declarations_c, option, global_var_decl_list) |
|
438 |
|
439 /* helper symbol for global_var_declarations */ |
|
440 /*| global_var_decl_list global_var_decl ';' */ |
|
441 SYM_LIST(global_var_decl_list_c) |
|
442 |
|
443 /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ |
|
444 /* type_specification ->may be NULL ! */ |
|
445 SYM_REF2(global_var_decl_c, global_var_spec, type_specification) |
|
446 |
|
447 /*| global_var_name location */ |
|
448 SYM_REF2(global_var_spec_c, global_var_name, location) |
|
449 |
|
450 /* AT direct_variable */ |
|
451 SYM_REF2(location_c, direct_variable, unused) |
|
452 |
|
453 /*| global_var_list ',' global_var_name */ |
|
454 SYM_LIST(global_var_list_c) |
|
455 |
|
456 /* var1_list ':' single_byte_string_spec */ |
|
457 SYM_REF2(single_byte_string_var_declaration_c, var1_list, single_byte_string_spec) |
|
458 |
|
459 /* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ |
|
460 /* integer ->may be NULL ! */ |
|
461 /* single_byte_character_string ->may be NULL ! */ |
|
462 SYM_REF2(single_byte_string_spec_c, integer, single_byte_character_string) |
|
463 |
|
464 /* var1_list ':' double_byte_string_spec */ |
|
465 SYM_REF2(double_byte_string_var_declaration_c, var1_list, double_byte_string_spec) |
|
466 |
|
467 /* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ |
|
468 /* integer ->may be NULL ! */ |
|
469 /* double_byte_character_string ->may be NULL ! */ |
|
470 SYM_REF2(double_byte_string_spec_c, integer, double_byte_character_string) |
|
471 |
|
472 /*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ |
|
473 /* option ->may be NULL ! */ |
|
474 SYM_REF2(incompl_located_var_declarations_c, option, incompl_located_var_decl_list) |
|
475 |
|
476 /* helper symbol for incompl_located_var_declarations */ |
|
477 /*| incompl_located_var_decl_list incompl_located_var_decl ';' */ |
|
478 SYM_LIST(incompl_located_var_decl_list_c) |
|
479 |
|
480 /* variable_name incompl_location ':' var_spec */ |
|
481 SYM_REF4(incompl_located_var_decl_c, variable_name, incompl_location, var_spec, unused) |
|
482 |
|
483 /* AT incompl_location_token */ |
|
484 SYM_TOKEN(incompl_location_c) |
|
485 |
|
486 /* intermediate helper symbol for: |
|
487 * - non_retentive_var_decls |
|
488 * - output_declarations |
|
489 */ |
|
490 SYM_LIST(var_init_decl_list_c) |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 /**************************************/ |
|
496 /* B.1.5 - Program organization units */ |
|
497 /**************************************/ |
|
498 /***********************/ |
|
499 /* B 1.5.1 - Functions */ |
|
500 /***********************/ |
|
501 SYM_REF4(function_declaration_c, derived_function_name, type_name, var_declarations_list, function_body) |
|
502 |
|
503 /* intermediate helper symbol for |
|
504 * - function_declaration |
|
505 * - function_block_declaration |
|
506 * - program_declaration |
|
507 */ |
|
508 SYM_LIST(var_declarations_list_c) |
|
509 |
|
510 /* option -> storage method, CONSTANT or <null> */ |
|
511 SYM_REF2(function_var_decls_c, option, decl_list) |
|
512 |
|
513 /* intermediate helper symbol for function_var_decls */ |
|
514 SYM_LIST(var2_init_decl_list_c) |
|
515 |
|
516 |
|
517 /*****************************/ |
|
518 /* B 1.5.2 - Function Blocks */ |
|
519 /*****************************/ |
|
520 /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ |
|
521 SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused) |
|
522 |
|
523 /* intermediate helper symbol for function_declaration */ |
|
524 /* { io_var_declarations | other_var_declarations } */ |
|
525 /* |
|
526 * NOTE: we re-use the var_declarations_list_c |
|
527 */ |
|
528 |
|
529 /* VAR_TEMP temp_var_decl_list END_VAR */ |
|
530 SYM_REF2(temp_var_decls_c, var_decl_list, unused) |
|
531 |
|
532 /* intermediate helper symbol for temp_var_decls */ |
|
533 SYM_LIST(temp_var_decls_list_c) |
|
534 |
|
535 /* VAR NON_RETAIN var_init_decl_list END_VAR */ |
|
536 SYM_REF2(non_retentive_var_decls_c, var_decl_list, unused) |
|
537 |
|
538 |
|
539 /**********************/ |
|
540 /* B 1.5.3 - Programs */ |
|
541 /**********************/ |
|
542 /* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ |
|
543 SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) |
|
544 |
|
545 /* intermediate helper symbol for program_declaration_c */ |
|
546 /* { io_var_declarations | other_var_declarations } */ |
|
547 /* |
|
548 * NOTE: we re-use the var_declarations_list_c |
|
549 */ |
|
550 |
|
551 |
|
552 |
|
553 /*********************************************/ |
|
554 /* B.1.6 Sequential function chart elements */ |
|
555 /*********************************************/ |
|
556 |
|
557 |
|
558 /********************************/ |
|
559 /* B 1.7 Configuration elements */ |
|
560 /********************************/ |
|
561 |
|
562 /* |
|
563 CONFIGURATION configuration_name |
|
564 optional_global_var_declarations |
|
565 (resource_declaration_list | single_resource_declaration) |
|
566 optional_access_declarations |
|
567 optional_instance_specific_initializations |
|
568 END_CONFIGURATION |
|
569 */ |
|
570 SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused) |
|
571 |
|
572 /* helper symbol for configuration_declaration */ |
|
573 SYM_LIST(resource_declaration_list_c) |
|
574 |
|
575 /* |
|
576 RESOURCE resource_name ON resource_type_name |
|
577 optional_global_var_declarations |
|
578 single_resource_declaration |
|
579 END_RESOURCE |
|
580 */ |
|
581 SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration) |
|
582 |
|
583 /* task_configuration_list program_configuration_list */ |
|
584 SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list) |
|
585 |
|
586 /* helper symbol for single_resource_declaration */ |
|
587 SYM_LIST(task_configuration_list_c) |
|
588 |
|
589 /* helper symbol for single_resource_declaration */ |
|
590 SYM_LIST(program_configuration_list_c) |
|
591 |
|
592 /* helper symbol for |
|
593 * - access_path |
|
594 * - instance_specific_init |
|
595 */ |
|
596 SYM_LIST(any_fb_name_list_c) |
|
597 |
|
598 /* [resource_name '.'] global_var_name ['.' structure_element_name] */ |
|
599 SYM_REF4(global_var_reference_c, resource_name, global_var_name, structure_element_name, unused) |
|
600 |
|
601 /* prev_declared_program_name '.' symbolic_variable */ |
|
602 SYM_REF2(program_output_reference_c, program_name, symbolic_variable) |
|
603 |
|
604 /* TASK task_name task_initialization */ |
|
605 SYM_REF2(task_configuration_c, task_name, task_initialization) |
|
606 |
|
607 /* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ |
|
608 SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused) |
|
609 |
|
610 /* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ |
|
611 SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused) |
|
612 |
|
613 /* prog_conf_elements ',' prog_conf_element */ |
|
614 SYM_LIST(prog_conf_elements_c) |
|
615 |
|
616 /* fb_name WITH task_name */ |
|
617 SYM_REF2(fb_task_c, fb_name, task_name) |
|
618 |
|
619 /* any_symbolic_variable ASSIGN prog_data_source */ |
|
620 SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source) |
|
621 |
|
622 /* any_symbolic_variable SENDTO data_sink */ |
|
623 SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, prog_data_source) |
|
624 |
|
625 /* VAR_CONFIG instance_specific_init_list END_VAR */ |
|
626 SYM_REF2(instance_specific_initializations_c, instance_specific_init_list, unused) |
|
627 |
|
628 /* helper symbol for instance_specific_initializations */ |
|
629 SYM_LIST(instance_specific_init_list_c) |
|
630 |
|
631 /* resource_name '.' program_name '.' {fb_name '.'} |
|
632 ((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization)) |
|
633 */ |
|
634 SYM_REF6(instance_specific_init_c, resource_name, program_name, any_fb_name_list, variable_name, location, initialization) |
|
635 |
|
636 /* helper symbol for instance_specific_init */ |
|
637 /* function_block_type_name ':=' structure_initialization */ |
|
638 SYM_REF2(fb_initialization_c, function_block_type_name, structure_initialization) |
|
639 |
|
640 |
|
641 |
|
642 /****************************************/ |
|
643 /* B.2 - Language IL (Instruction List) */ |
|
644 /****************************************/ |
|
645 /***********************************/ |
|
646 /* B 2.1 Instructions and Operands */ |
|
647 /***********************************/ |
|
648 /*| instruction_list il_instruction */ |
|
649 SYM_LIST(instruction_list_c) |
|
650 |
|
651 /* | label ':' [il_incomplete_instruction] eol_list */ |
|
652 SYM_REF2(il_instruction_c, label, il_instruction) |
|
653 |
|
654 |
|
655 /* | il_simple_operator [il_operand] */ |
|
656 SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand) |
|
657 |
|
658 /* | function_name [il_operand_list] */ |
|
659 SYM_REF2(il_function_call_c, function_name, il_operand_list) |
|
660 |
|
661 |
|
662 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ |
|
663 SYM_REF4(il_expression_c, il_expr_operator, il_operand, simple_instr_list, unused) |
|
664 |
|
665 /* il_jump_operator label */ |
|
666 SYM_REF2(il_jump_operation_c, il_jump_operator, label) |
|
667 |
|
668 /* il_call_operator prev_declared_fb_name |
|
669 * | il_call_operator prev_declared_fb_name '(' ')' |
|
670 * | il_call_operator prev_declared_fb_name '(' eol_list ')' |
|
671 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')' |
|
672 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' |
|
673 */ |
|
674 SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) |
|
675 |
|
676 |
|
677 /* | function_name '(' eol_list [il_param_list] ')' */ |
|
678 SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) |
|
679 |
|
680 /* | il_operand_list ',' il_operand */ |
|
681 SYM_LIST(il_operand_list_c) |
|
682 |
|
683 /* | simple_instr_list il_simple_instruction */ |
|
684 SYM_LIST(simple_instr_list_c) |
|
685 |
|
686 /* | il_initial_param_list il_param_instruction */ |
|
687 SYM_LIST(il_param_list_c) |
|
688 |
|
689 /* il_assign_operator il_operand |
|
690 * | il_assign_operator '(' eol_list simple_instr_list ')' |
|
691 */ |
|
692 SYM_REF4(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list, unused) |
|
693 |
|
694 /* il_assign_out_operator variable */ |
|
695 SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable) |
|
696 |
|
697 |
|
698 |
|
699 /*******************/ |
|
700 /* B 2.2 Operators */ |
|
701 /*******************/ |
|
702 SYM_REF0(LD_operator_c) |
|
703 SYM_REF0(LDN_operator_c) |
|
704 SYM_REF0(ST_operator_c) |
|
705 SYM_REF0(STN_operator_c) |
|
706 SYM_REF0(NOT_operator_c) |
|
707 SYM_REF0(S_operator_c) |
|
708 SYM_REF0(R_operator_c) |
|
709 SYM_REF0(S1_operator_c) |
|
710 SYM_REF0(R1_operator_c) |
|
711 SYM_REF0(CLK_operator_c) |
|
712 SYM_REF0(CU_operator_c) |
|
713 SYM_REF0(CD_operator_c) |
|
714 SYM_REF0(PV_operator_c) |
|
715 SYM_REF0(IN_operator_c) |
|
716 SYM_REF0(PT_operator_c) |
|
717 SYM_REF0(AND_operator_c) |
|
718 SYM_REF0(OR_operator_c) |
|
719 SYM_REF0(XOR_operator_c) |
|
720 SYM_REF0(ANDN_operator_c) |
|
721 SYM_REF0(ORN_operator_c) |
|
722 SYM_REF0(XORN_operator_c) |
|
723 SYM_REF0(ADD_operator_c) |
|
724 SYM_REF0(SUB_operator_c) |
|
725 SYM_REF0(MUL_operator_c) |
|
726 SYM_REF0(DIV_operator_c) |
|
727 SYM_REF0(MOD_operator_c) |
|
728 SYM_REF0(GT_operator_c) |
|
729 SYM_REF0(GE_operator_c) |
|
730 SYM_REF0(EQ_operator_c) |
|
731 SYM_REF0(LT_operator_c) |
|
732 SYM_REF0(LE_operator_c) |
|
733 SYM_REF0(NE_operator_c) |
|
734 SYM_REF0(CAL_operator_c) |
|
735 SYM_REF0(CALC_operator_c) |
|
736 SYM_REF0(CALCN_operator_c) |
|
737 SYM_REF0(RET_operator_c) |
|
738 SYM_REF0(RETC_operator_c) |
|
739 SYM_REF0(RETCN_operator_c) |
|
740 SYM_REF0(JMP_operator_c) |
|
741 SYM_REF0(JMPC_operator_c) |
|
742 SYM_REF0(JMPCN_operator_c) |
|
743 |
|
744 /*| [NOT] any_identifier SENDTO */ |
|
745 SYM_REF2(il_assign_out_operator_c, option, variable_name) |
|
746 |
|
747 |
|
748 |
|
749 /***************************************/ |
|
750 /* B.3 - Language ST (Structured Text) */ |
|
751 /***************************************/ |
|
752 /***********************/ |
|
753 /* B 3.1 - Expressions */ |
|
754 /***********************/ |
|
755 SYM_REF2(or_expression_c, l_exp, r_exp) |
|
756 SYM_REF2(xor_expression_c, l_exp, r_exp) |
|
757 SYM_REF2(and_expression_c, l_exp, r_exp) |
|
758 SYM_REF2(equ_expression_c, l_exp, r_exp) |
|
759 SYM_REF2(notequ_expression_c, l_exp, r_exp) |
|
760 SYM_REF2(lt_expression_c, l_exp, r_exp) |
|
761 SYM_REF2(gt_expression_c, l_exp, r_exp) |
|
762 SYM_REF2(le_expression_c, l_exp, r_exp) |
|
763 SYM_REF2(ge_expression_c, l_exp, r_exp) |
|
764 SYM_REF2(add_expression_c, l_exp, r_exp) |
|
765 SYM_REF2(sub_expression_c, l_exp, r_exp) |
|
766 SYM_REF2(mul_expression_c, l_exp, r_exp) |
|
767 SYM_REF2(div_expression_c, l_exp, r_exp) |
|
768 SYM_REF2(mod_expression_c, l_exp, r_exp) |
|
769 SYM_REF2(power_expression_c, l_exp, r_exp) |
|
770 SYM_REF2(neg_expression_c, exp, unused) |
|
771 SYM_REF2(not_expression_c, exp, unused) |
|
772 |
|
773 SYM_REF2(function_invocation_c, function_name, parameter_assignment_list) |
|
774 |
|
775 |
|
776 /********************/ |
|
777 /* B 3.2 Statements */ |
|
778 /********************/ |
|
779 SYM_LIST(statement_list_c) |
|
780 |
|
781 |
|
782 /*********************************/ |
|
783 /* B 3.2.1 Assignment Statements */ |
|
784 /*********************************/ |
|
785 SYM_REF2(assignment_statement_c, l_exp, r_exp) |
|
786 |
|
787 |
|
788 /*****************************************/ |
|
789 /* B 3.2.2 Subprogram Control Statements */ |
|
790 /*****************************************/ |
|
791 /* RETURN */ |
|
792 SYM_REF0(return_statement_c) |
|
793 |
|
794 /* fb_name '(' [param_assignment_list] ')' */ |
|
795 /* param_assignment_list -> may be NULL ! */ |
|
796 SYM_REF2(fb_invocation_c, fb_name, param_assignment_list) |
|
797 |
|
798 /* helper symbol for fb_invocation */ |
|
799 /* param_assignment_list ',' param_assignment */ |
|
800 SYM_LIST(param_assignment_list_c) |
|
801 |
|
802 /* variable_name ASSIGN expression */ |
|
803 SYM_REF2(input_variable_param_assignment_c, variable_name, expression) |
|
804 |
|
805 /* [NOT] variable_name '=>' variable */ |
|
806 SYM_REF4(output_variable_param_assignment_c, not_param, variable_name, variable, unused) |
|
807 |
|
808 /* helper CLASS for output_variable_param_assignment */ |
|
809 SYM_REF0(not_paramassign_c) |
|
810 |
|
811 |
|
812 /********************************/ |
|
813 /* B 3.2.3 Selection Statements */ |
|
814 /********************************/ |
|
815 /* IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF */ |
|
816 SYM_REF4(if_statement_c, expression, statement_list, elseif_statement_list, else_statement_list) |
|
817 |
|
818 /* helper symbol for if_statement */ |
|
819 SYM_LIST(elseif_statement_list_c) |
|
820 |
|
821 /* helper symbol for elseif_statement_list */ |
|
822 /* ELSIF expression THEN statement_list */ |
|
823 SYM_REF2(elseif_statement_c, expression, statement_list) |
|
824 |
|
825 /* CASE expression OF case_element_list ELSE statement_list END_CASE */ |
|
826 SYM_REF4(case_statement_c, expression, case_element_list, statement_list, unused) |
|
827 |
|
828 /* helper symbol for case_statement */ |
|
829 SYM_LIST(case_element_list_c) |
|
830 |
|
831 /* case_list ':' statement_list */ |
|
832 SYM_REF2(case_element_c, case_list, statement_list) |
|
833 |
|
834 SYM_LIST(case_list_c) |
|
835 |
|
836 |
|
837 /********************************/ |
|
838 /* B 3.2.4 Iteration Statements */ |
|
839 /********************************/ |
|
840 /* FOR control_variable ASSIGN expression TO expression [BY expression] DO statement_list END_FOR */ |
|
841 SYM_REF6(for_statement_c, control_variable, beg_expression, end_expression, by_expression, statement_list, unused) |
|
842 |
|
843 /* WHILE expression DO statement_list END_WHILE */ |
|
844 SYM_REF2(while_statement_c, expression, statement_list) |
|
845 |
|
846 /* REPEAT statement_list UNTIL expression END_REPEAT */ |
|
847 SYM_REF2(repeat_statement_c, statement_list, expression) |
|
848 |
|
849 /* EXIT */ |
|
850 SYM_REF0(exit_statement_c) |
|
851 |
|
852 |