author | mjsousa |
Sun, 02 Mar 2014 16:42:56 +0000 | |
changeset 873 | dea39ef02847 |
parent 267 | 0a1204bcc9af |
permissions | -rwxr-xr-x |
108 | 1 |
(* Test whether the keyword XXXX may be used as an identifier for: |
2 |
* variable name/identifier |
|
3 |
* |
|
4 |
* The XXXX names in the following code are merely a placeholder. |
|
5 |
* They will be replaced by several identifiers before actual testing |
|
6 |
* of the compiler. |
|
7 |
*) |
|
8 |
||
9 |
(* The identifiers that will replace the XXXX |
|
10 |
* must be placed on a line starting with # |
|
11 |
* All identifiers preceded by # are ignored! |
|
12 |
* The identifier list must be placed inside an IEC 61131-3 comment. |
|
13 |
*) |
|
14 |
(* |
|
15 |
#IL_operators ANDN CAL CALC CALCN CD CLK CU IN JMP JMPC JMPCN LD LDN ORN PT PV R R1 RET RETC RETCN S S1 ST STN XORN |
|
16 |
#SFC_qualifiers D DS L N P #R #S SD SL |
|
17 |
NOTE: R and S are identical to IL operators!! |
|
18 |
#Task_initialisers PRIORITY SINGLE INTERVAL |
|
19 |
*) |
|
20 |
||
21 |
(* NOTE: The identifier as a variable test has some special cases. |
|
22 |
* Namely, when using IL operators as variable names. |
|
23 |
* Even though the syntax of the IL language would not result |
|
24 |
* in ambiguities in the above case, our parser does not currently |
|
25 |
* allow the use of variables (with names identical to IL |
|
26 |
* operators) within IL code. |
|
27 |
* |
|
28 |
* The following test code must therefore consider two possibilities: |
|
29 |
* - if the identifier under test is an IL operator |
|
30 |
* - if the identifier under test is not an IL operator |
|
31 |
* |
|
32 |
* The test code in this file should be valid for all identifiers. |
|
33 |
* Test code that is only valid for identifiers not identical to IL operators |
|
34 |
* is placed in another test file (identifier_as_variable2.test). |
|
35 |
*) |
|
36 |
||
37 |
||
38 |
||
39 |
||
40 |
(* A helper FUNCTION BLOCK declaration *) |
|
41 |
function_block foo_fb |
|
42 |
var_input |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
43 |
a_1, b_1: real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
44 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
45 |
var_output |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
46 |
c_1, d_1: real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
47 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
48 |
c_1 := 10.0 + b_1; |
108 | 49 |
end_function_block |
50 |
||
51 |
||
52 |
(* A helper FUNCTION declaration *) |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
53 |
function foo_f1 : real |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
54 |
var_input |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
55 |
a_1, b_1: real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
56 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
57 |
var_output |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
58 |
c_1, d_1: real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
59 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
60 |
c_1 := 10.0 + b_1; |
108 | 61 |
end_function |
62 |
||
63 |
(* Another helper FUNCTION declaration *) |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
64 |
function foo_f2 :real |
108 | 65 |
var_input |
66 |
a_1, b_1: foo_fb; |
|
67 |
end_var |
|
68 |
var_output |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
69 |
c_1, d_1: real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
70 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
71 |
c_1 := 10.0; |
108 | 72 |
end_function |
73 |
||
74 |
||
75 |
||
76 |
(*********************************************************************) |
|
77 |
(* Testing use of XXXX in several locations of variable declarations *) |
|
78 |
(*********************************************************************) |
|
79 |
||
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
80 |
function bar01 : real |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
81 |
var_input |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
82 |
XXXX, a_1, b_1: real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
83 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
84 |
a_1 := 1.0; |
108 | 85 |
end_function |
86 |
||
87 |
function_block bar02 |
|
88 |
var_input |
|
89 |
a_1, XXXX, b_1: int; |
|
90 |
end_var |
|
91 |
a_1 := 1; |
|
92 |
end_function_block |
|
93 |
||
94 |
function_block bar03 |
|
95 |
var_input |
|
96 |
a_1, b_1, XXXX: int; |
|
97 |
end_var |
|
98 |
a_1 := 1; |
|
99 |
end_function_block |
|
100 |
||
101 |
||
102 |
function_block bar04 |
|
103 |
var_output |
|
104 |
XXXX, a_1, b_1: int; |
|
105 |
end_var |
|
106 |
a_1 := 1; |
|
107 |
end_function_block |
|
108 |
||
109 |
function_block bar05 |
|
110 |
var_output |
|
111 |
a_1, XXXX, b_1: int; |
|
112 |
end_var |
|
113 |
a_1 := 1; |
|
114 |
end_function_block |
|
115 |
||
116 |
function_block bar06 |
|
117 |
var_output |
|
118 |
a_1, b_1, XXXX: int; |
|
119 |
end_var |
|
120 |
a_1 := 1; |
|
121 |
end_function_block |
|
122 |
||
123 |
||
124 |
function_block bar07 |
|
125 |
var_in_out |
|
126 |
XXXX, a_1, b_1: int; |
|
127 |
end_var |
|
128 |
a_1 := 1; |
|
129 |
end_function_block |
|
130 |
||
131 |
function_block bar08 |
|
132 |
var_in_out |
|
133 |
a_1, XXXX, b_1: int; |
|
134 |
end_var |
|
135 |
a_1 := 1; |
|
136 |
end_function_block |
|
137 |
||
138 |
function_block bar09 |
|
139 |
var_in_out |
|
140 |
a_1, b_1, XXXX: int; |
|
141 |
end_var |
|
142 |
a_1 := 1; |
|
143 |
end_function_block |
|
144 |
||
145 |
function_block bar10 |
|
146 |
var_external |
|
147 |
XXXX: int; |
|
148 |
a_1 : int; |
|
149 |
end_var |
|
150 |
a_1 := 1; |
|
151 |
end_function_block |
|
152 |
||
153 |
function_block bar11 |
|
154 |
var_external |
|
155 |
a_1 : int; |
|
156 |
XXXX : int; |
|
157 |
end_var |
|
158 |
a_1 := 1; |
|
159 |
end_function_block |
|
160 |
||
161 |
function_block bar12 |
|
162 |
var |
|
163 |
XXXX, a_1, b_1: int; |
|
164 |
end_var |
|
165 |
a_1 := 1; |
|
166 |
end_function_block |
|
167 |
||
168 |
function_block bar13 |
|
169 |
var |
|
170 |
a_1, XXXX, b_1: int; |
|
171 |
end_var |
|
172 |
a_1 := 1; |
|
173 |
end_function_block |
|
174 |
||
175 |
function_block bar14 |
|
176 |
var |
|
177 |
a_1, b_1, XXXX: int; |
|
178 |
end_var |
|
179 |
a_1 := 1; |
|
180 |
end_function_block |
|
181 |
||
182 |
||
183 |
||
184 |
(************************************************) |
|
185 |
(* Using XXXX as a standard variable name in ST *) |
|
186 |
(************************************************) |
|
187 |
||
188 |
function_block bar90 |
|
189 |
var |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
190 |
e_1, f_1 : real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
191 |
XXXX : real; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
192 |
fb : foo_fb; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
193 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
194 |
e_1 := bar01 (XXXX := 10.0); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
195 |
e_1 := bar01 (a_1 := XXXX); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
196 |
e_1 := bar01 (XXXX := XXXX); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
197 |
fb(XXXX, 20.0); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
198 |
fb (10.0, XXXX, e_1, f_1); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
199 |
fb (a_1 := XXXX, b_1:=XXXX, c_1=>XXXX, d_1=>f_1); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
200 |
fb(a_1 := 10.0, b_1:=20.0, c_1=>e_1, d_1=>XXXX); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
201 |
fb (c_1=>XXXX, a_1:=20.0, d_1=>f_1); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
202 |
XXXX := fb.c_1; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
203 |
fb.a_1 := XXXX + XXXX * 2.0 * (XXXX) / foo_f1(XXXX, 10.0, XXXX, e_1) / XXXX ** XXXX; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
204 |
IF (XXXX >= 10.0) THEN XXXX := 10.0; END_IF; |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
205 |
end_function_block |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
206 |
|
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
207 |
|
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
208 |
function_block bar90a |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
209 |
var |
108 | 210 |
e_1, f_1 : int; |
211 |
XXXX : int; |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
212 |
end_var |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
213 |
XXXX := XXXX MOD XXXX; |
108 | 214 |
CASE (XXXX + 10) OF |
215 |
10: XXXX := 10; |
|
216 |
10..20:XXXX := 20; |
|
217 |
ELSE XXXX := 20; |
|
218 |
END_CASE; |
|
219 |
FOR XXXX := 10 TO 20 BY 2 DO |
|
220 |
XXXX := XXXX + 1; |
|
221 |
END_FOR; |
|
222 |
FOR e_1 := XXXX TO 20 DO |
|
223 |
XXXX := XXXX + 1; |
|
224 |
END_FOR; |
|
225 |
FOR e_1 := 10 TO XXXX BY 2 DO |
|
226 |
XXXX := XXXX + 1; |
|
227 |
END_FOR; |
|
228 |
FOR e_1 := 10 TO XXXX DO |
|
229 |
XXXX := XXXX + 1; |
|
230 |
END_FOR; |
|
231 |
FOR e_1 := 10 TO 20 BY XXXX DO |
|
232 |
XXXX := XXXX + 1; |
|
233 |
END_FOR; |
|
234 |
WHILE (XXXX >= 10) DO |
|
235 |
XXXX := 10; |
|
236 |
END_WHILE; |
|
237 |
REPEAT XXXX := 10; UNTIL (XXXX >= 10) END_REPEAT; |
|
238 |
end_function_block |
|
239 |
||
240 |
||
241 |
||
242 |
(* Using XXXX as a function block instance/variable name in ST *) |
|
243 |
||
244 |
function_block bar91 |
|
245 |
var |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
246 |
e_1, f_1 : real; |
108 | 247 |
XXXX : foo_fb; |
248 |
end_var |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
249 |
XXXX(e_1, 20.0); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
250 |
XXXX (10.0, e_1, e_1, f_1); |
108 | 251 |
XXXX (a_1 := e_1, b_1:=e_1 , c_1=>e_1, d_1=>f_1); |
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
252 |
XXXX(a_1 := 10.0, b_1:=20.0, c_1=>e_1, d_1=>e_1); |
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
253 |
XXXX (c_1=>e_1, a_1:=20.0, d_1=>f_1); |
108 | 254 |
e_1 := XXXX.c_1; |
255 |
XXXX.a_1 := e_1; |
|
256 |
e_1 := foo_f2(XXXX, XXXX, e_1, f_1); |
|
257 |
e_1 := foo_f2 (XXXX, XXXX); |
|
267
0a1204bcc9af
starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents:
108
diff
changeset
|
258 |
e_1 := foo_f2 (c_1 => e_1, b_1 := XXXX, d_1 := 10.0, a_1 := XXXX); |
108 | 259 |
e_1 := foo_f2 (b_1 := XXXX); |
260 |
end_function_block |
|
261 |
||
262 |
||
263 |
||
264 |
||
265 |
(************************************************) |
|
266 |
(* Using XXXX as a standard variable name in IL *) |
|
267 |
(************************************************) |
|
268 |
||
269 |
(* NOTE: Currently not supported for identifiers identical to IL operators. |
|
270 |
* We therefore have two versions of this file, one with the following code |
|
271 |
* commented out (used to test the identifiers that clash with IL operators) |
|
272 |
* and a second with the following code included (used to test identifiers |
|
273 |
* that do not clash with IL operators, such as PRIORITY, SINGLE, etc...) |
|
274 |
*) |
|
275 |
||
276 |
||
277 |
(* |
|
278 |
function_block bar93 |
|
279 |
var |
|
280 |
e_1, f_1 : int; |
|
281 |
end_var |
|
282 |
||
283 |
(* Calling function with input parameter named XXXX ** |
|
284 |
bar01 ( |
|
285 |
XXXX := 10 |
|
286 |
) |
|
287 |
end_function_block |
|
288 |
*) |
|
289 |
||
290 |
||
291 |
(* |
|
292 |
function_block bar99 |
|
293 |
(...) |
|
294 |
end_function_block |
|
295 |
*) |
|
296 |
||
297 |
||
298 |
||
299 |
||
300 |
||
301 |
||
302 |
(*************************************************************************************) |
|
303 |
(* Using XXXX as a function block instance/variable/program name in a configuration. *) |
|
304 |
(*************************************************************************************) |
|
305 |
||
306 |
(* a helper program *) |
|
307 |
PROGRAM bar000 |
|
308 |
VAR_INPUT |
|
309 |
a_1, XXXX : BOOL; |
|
310 |
END_VAR |
|
311 |
VAR_OUTPUT |
|
312 |
b_1 : BOOL; |
|
313 |
END_VAR |
|
314 |
a_1 := TRUE; |
|
315 |
END_PROGRAM |
|
316 |
||
317 |
||
318 |
(* using in program parameter *) |
|
319 |
CONFIGURATION config01 |
|
320 |
TASK fast(PRIORITY := 4); |
|
321 |
PROGRAM foo WITH fast: |
|
322 |
bar000(a_1 := TRUE, XXXX := FALSE); |
|
323 |
END_CONFIGURATION |
|
324 |
||
325 |
||
326 |
(* using as a program name *) |
|
327 |
CONFIGURATION config02 |
|
328 |
TASK fast(PRIORITY := 4); |
|
329 |
PROGRAM XXXX WITH fast: |
|
330 |
bar000(a_1 := TRUE, XXXX := FALSE); |
|
331 |
END_CONFIGURATION |
|
332 |
||
333 |
||
334 |
(* using as a resource name *) |
|
335 |
CONFIGURATION config03 |
|
336 |
RESOURCE XXXX on processor_type_1 |
|
337 |
TASK fast(PRIORITY := 4); |
|
338 |
PROGRAM foo WITH fast: |
|
339 |
bar000(a_1 := TRUE, XXXX := FALSE); |
|
340 |
END_RESOURCE |
|
341 |
END_CONFIGURATION |
|
342 |
||
343 |
||
344 |
(* using as a task name *) |
|
345 |
CONFIGURATION config11 |
|
346 |
TASK XXXX(PRIORITY := 4); |
|
347 |
PROGRAM foo WITH XXXX: |
|
348 |
bar000(a_1 := TRUE, XXXX := FALSE); |
|
349 |
END_CONFIGURATION |
|
350 |
||
351 |
||
352 |
CONFIGURATION config12 |
|
353 |
TASK XXXX(SINGLE := 3, PRIORITY := 4); |
|
354 |
PROGRAM P1 WITH XXXX: |
|
355 |
bar000(a_1 := TRUE, XXXX := FALSE); |
|
356 |
END_CONFIGURATION |
|
357 |
||
358 |
||
359 |
CONFIGURATION config13 |
|
360 |
TASK XXXX(INTERVAL := T#1s, PRIORITY := 4); |
|
361 |
PROGRAM P1 WITH XXXX: |
|
362 |
bar000(a_1 := TRUE, XXXX := FALSE); |
|
363 |
END_CONFIGURATION |
|
364 |
||
365 |
||
366 |
CONFIGURATION config14 |
|
367 |
TASK XXXX(SINGLE := 3, INTERVAL := T#1s, PRIORITY := 4); |
|
368 |
PROGRAM P1 WITH XXXX: |
|
369 |
bar000(a_1 := TRUE, XXXX := FALSE); |
|
370 |
END_CONFIGURATION |
|
371 |
||
372 |
||
373 |
(* using as a variable name *) |
|
374 |
CONFIGURATION config21 |
|
375 |
VAR_GLOBAL |
|
376 |
XXXX : bool; |
|
377 |
END_VAR |
|
378 |
TASK fast(PRIORITY := 4); |
|
379 |
PROGRAM foo WITH fast: |
|
380 |
bar000(a_1 := XXXX, b_1 => XXXX, XXXX := XXXX); |
|
381 |
END_CONFIGURATION |
|
382 |
||
383 |
||
384 |
||
385 |
||
386 |
||
387 |
||
388 |
||
389 |
||
390 |
||
391 |
||
392 |
||
393 |
||
394 |
(* Checking whether the use of XXXX will confuse any other |
|
395 |
* normal and correct IL or ST code. |
|
396 |
*) |
|
397 |
{#include "basic_code.test" } |
|
398 |