1 /* |
1 /* |
2 * (c) 2003 Mario de Sousa |
2 * matiec - a compiler for the programming languages defined in IEC 61131-3 |
3 * |
3 * |
4 * Offered to the public under the terms of the GNU General Public License |
4 * Copyright (C) 2003-2011 Mario de Sousa (msousa@fe.up.pt) |
5 * as published by the Free Software Foundation; either version 2 of the |
|
6 * License, or (at your option) any later version. |
|
7 * |
5 * |
8 * This program is distributed in the hope that it will be useful, but |
6 * This program is free software: you can redistribute it and/or modify |
9 * WITHOUT ANY WARRANTY; without even the implied warranty of |
7 * it under the terms of the GNU General Public License as published by |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
8 * the Free Software Foundation, either version 3 of the License, or |
11 * Public License for more details. |
9 * (at your option) any later version. |
|
10 * |
|
11 * This program is distributed in the hope that it will be useful, |
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 * GNU General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License |
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
18 * |
12 * |
19 * |
13 * This code is made available on the understanding that it will not be |
20 * 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. |
21 * used in safety-critical situations without a full and competent review. |
15 */ |
22 */ |
16 |
23 |
17 /* |
24 /* |
18 * An IEC 61131-3 IL and ST compiler. |
25 * An IEC 61131-3 compiler. |
19 * |
26 * |
20 * Based on the |
27 * Based on the |
21 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
28 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) |
22 * |
29 * |
23 */ |
30 */ |
166 /*********************/ |
177 /*********************/ |
167 |
178 |
168 /******************************/ |
179 /******************************/ |
169 /* B 1.2.1 - Numeric Literals */ |
180 /* B 1.2.1 - Numeric Literals */ |
170 /******************************/ |
181 /******************************/ |
171 void *visit(real_c *symbol) {return print_token(symbol);} |
182 void *visit(real_c *symbol) {return print_token(symbol);} |
172 void *visit(integer_c *symbol) {return print_token(symbol);} |
183 void *visit(neg_real_c *symbol) {return print_unary_expression(symbol->exp, "-");} |
173 void *visit(binary_integer_c *symbol) {return print_token(symbol);} |
184 void *visit(integer_c *symbol) {return print_token(symbol);} |
174 void *visit(octal_integer_c *symbol) {return print_token(symbol);} |
185 void *visit(neg_integer_c *symbol) {return print_unary_expression(symbol->exp, "-");} |
175 void *visit(hex_integer_c *symbol) {return print_token(symbol);} |
186 void *visit(binary_integer_c *symbol) {return print_token(symbol);} |
176 |
187 void *visit(octal_integer_c *symbol) {return print_token(symbol);} |
177 void *visit(integer_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
188 void *visit(hex_integer_c *symbol) {return print_token(symbol);} |
178 void *visit(real_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
189 |
|
190 void *visit(integer_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
|
191 void *visit(real_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
179 void *visit(bit_string_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
192 void *visit(bit_string_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
180 void *visit(boolean_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
193 void *visit(boolean_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} |
181 void *visit(neg_literal_c *symbol) {return print_unary_expression(symbol->exp, "-");} |
|
182 |
|
183 |
194 |
184 /* helper class for boolean_literal_c */ |
195 /* helper class for boolean_literal_c */ |
185 void *visit(boolean_true_c *symbol) {s4o.print(/*"TRUE"*/"1"); return NULL;} |
196 void *visit(boolean_true_c *symbol) {s4o.print(/*"TRUE"*/"1"); return NULL;} |
186 void *visit(boolean_false_c *symbol) {s4o.print(/*"FALSE"*/"0"); return NULL;} |
197 void *visit(boolean_false_c *symbol) {s4o.print(/*"FALSE"*/"0"); return NULL;} |
187 |
198 |
188 /*******************************/ |
199 /*******************************/ |
189 /* B.1.2.2 Character Strings */ |
200 /* B.1.2.2 Character Strings */ |
190 /*******************************/ |
201 /*******************************/ |
191 void *visit(double_byte_character_string_c *symbol) {return print_token(symbol);} |
202 void *visit(double_byte_character_string_c *symbol) {return print_token(symbol);} |
295 |
306 |
296 |
307 |
297 /***********************************/ |
308 /***********************************/ |
298 /* B 1.3.1 - Elementary Data Types */ |
309 /* B 1.3.1 - Elementary Data Types */ |
299 /***********************************/ |
310 /***********************************/ |
300 void *visit(time_type_name_c *symbol) {s4o.print("TIME"); return NULL;} |
311 void *visit(time_type_name_c *symbol) {s4o.print("TIME"); return NULL;} |
301 void *visit(bool_type_name_c *symbol) {s4o.print("BOOL"); return NULL;} |
312 void *visit(bool_type_name_c *symbol) {s4o.print("BOOL"); return NULL;} |
302 /******************************************************/ |
313 void *visit(sint_type_name_c *symbol) {s4o.print("SINT"); return NULL;} |
303 /* whether we are suporting safe extensions */ |
314 void *visit(int_type_name_c *symbol) {s4o.print("INT"); return NULL;} |
304 /* as defined in PLCopen - Technical Committee 5 */ |
315 void *visit(dint_type_name_c *symbol) {s4o.print("DINT"); return NULL;} |
305 /* Safety Software Technical Specification, */ |
316 void *visit(lint_type_name_c *symbol) {s4o.print("LINT"); return NULL;} |
306 /* Part 1: Concepts and Function Blocks, */ |
317 void *visit(usint_type_name_c *symbol) {s4o.print("USINT"); return NULL;} |
307 /* Version 1.0 – Official Release */ |
318 void *visit(uint_type_name_c *symbol) {s4o.print("UINT"); return NULL;} |
308 /******************************************************/ |
319 void *visit(udint_type_name_c *symbol) {s4o.print("UDINT"); return NULL;} |
309 void *visit(safebool_type_name_c *symbol) {s4o.print("SAFEBOOL"); return NULL;} |
320 void *visit(ulint_type_name_c *symbol) {s4o.print("ULINT"); return NULL;} |
310 void *visit(sint_type_name_c *symbol) {s4o.print("SINT"); return NULL;} |
321 void *visit(real_type_name_c *symbol) {s4o.print("REAL"); return NULL;} |
311 void *visit(int_type_name_c *symbol) {s4o.print("INT"); return NULL;} |
322 void *visit(lreal_type_name_c *symbol) {s4o.print("LREAL"); return NULL;} |
312 void *visit(dint_type_name_c *symbol) {s4o.print("DINT"); return NULL;} |
323 void *visit(date_type_name_c *symbol) {s4o.print("DATE"); return NULL;} |
313 void *visit(lint_type_name_c *symbol) {s4o.print("LINT"); return NULL;} |
324 void *visit(tod_type_name_c *symbol) {s4o.print("TOD"); return NULL;} |
314 void *visit(usint_type_name_c *symbol) {s4o.print("USINT"); return NULL;} |
325 void *visit(dt_type_name_c *symbol) {s4o.print("DT"); return NULL;} |
315 void *visit(uint_type_name_c *symbol) {s4o.print("UINT"); return NULL;} |
326 void *visit(byte_type_name_c *symbol) {s4o.print("BYTE"); return NULL;} |
316 void *visit(udint_type_name_c *symbol) {s4o.print("UDINT"); return NULL;} |
327 void *visit(word_type_name_c *symbol) {s4o.print("WORD"); return NULL;} |
317 void *visit(ulint_type_name_c *symbol) {s4o.print("ULINT"); return NULL;} |
328 void *visit(lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;} |
318 void *visit(real_type_name_c *symbol) {s4o.print("REAL"); return NULL;} |
329 void *visit(dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;} |
319 void *visit(lreal_type_name_c *symbol) {s4o.print("LREAL"); return NULL;} |
330 void *visit(string_type_name_c *symbol) {s4o.print("STRING"); return NULL;} |
320 void *visit(date_type_name_c *symbol) {s4o.print("DATE"); return NULL;} |
331 void *visit(wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;} |
321 void *visit(tod_type_name_c *symbol) {s4o.print("TOD"); return NULL;} |
332 |
322 void *visit(dt_type_name_c *symbol) {s4o.print("DT"); return NULL;} |
333 void *visit(safetime_type_name_c *symbol) {s4o.print("SAFETIME"); return NULL;} |
323 void *visit(byte_type_name_c *symbol) {s4o.print("BYTE"); return NULL;} |
334 void *visit(safebool_type_name_c *symbol) {s4o.print("SAFEBOOL"); return NULL;} |
324 void *visit(word_type_name_c *symbol) {s4o.print("WORD"); return NULL;} |
335 void *visit(safesint_type_name_c *symbol) {s4o.print("SAFESINT"); return NULL;} |
325 void *visit(lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;} |
336 void *visit(safeint_type_name_c *symbol) {s4o.print("SAFEINT"); return NULL;} |
326 void *visit(dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;} |
337 void *visit(safedint_type_name_c *symbol) {s4o.print("SAFEDINT"); return NULL;} |
327 void *visit(string_type_name_c *symbol) {s4o.print("STRING"); return NULL;} |
338 void *visit(safelint_type_name_c *symbol) {s4o.print("SAFELINT"); return NULL;} |
328 void *visit(wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;} |
339 void *visit(safeusint_type_name_c *symbol) {s4o.print("SAFEUSINT"); return NULL;} |
329 /* |
340 void *visit(safeuint_type_name_c *symbol) {s4o.print("SAFEUINT"); return NULL;} |
330 void *visit(constant_int_type_name_c *symbol) {return NULL;} |
341 void *visit(safeudint_type_name_c *symbol) {s4o.print("SAFEUDINT"); return NULL;} |
331 void *visit(constant_real_type_name_c *symbol) {return NULL;} |
342 void *visit(safeulint_type_name_c *symbol) {s4o.print("SAFEULINT"); return NULL;} |
332 */ |
343 void *visit(safereal_type_name_c *symbol) {s4o.print("SAFEREAL"); return NULL;} |
|
344 void *visit(safelreal_type_name_c *symbol) {s4o.print("SAFELREAL"); return NULL;} |
|
345 void *visit(safedate_type_name_c *symbol) {s4o.print("SAFEDATE"); return NULL;} |
|
346 void *visit(safetod_type_name_c *symbol) {s4o.print("SAFETOD"); return NULL;} |
|
347 void *visit(safedt_type_name_c *symbol) {s4o.print("SAFEDT"); return NULL;} |
|
348 void *visit(safebyte_type_name_c *symbol) {s4o.print("SAFEBYTE"); return NULL;} |
|
349 void *visit(safeword_type_name_c *symbol) {s4o.print("SAFEWORD"); return NULL;} |
|
350 void *visit(safelword_type_name_c *symbol) {s4o.print("SAFELWORD"); return NULL;} |
|
351 void *visit(safedword_type_name_c *symbol) {s4o.print("SAFEDWORD"); return NULL;} |
|
352 void *visit(safestring_type_name_c *symbol) {s4o.print("SAFESTRING"); return NULL;} |
|
353 void *visit(safewstring_type_name_c *symbol) {s4o.print("SAFEWSTRING"); return NULL;} |
|
354 |
333 |
355 |
334 /********************************/ |
356 /********************************/ |
335 /* B 1.3.3 - Derived data types */ |
357 /* B 1.3.3 - Derived data types */ |
336 /********************************/ |
358 /********************************/ |
337 /* TYPE type_declaration_list END_TYPE */ |
359 /* TYPE type_declaration_list END_TYPE */ |