etisserant@0: /* etisserant@0: * (c) 2003 Mario de Sousa etisserant@0: * etisserant@0: * Offered to the public under the terms of the GNU General Public License etisserant@0: * as published by the Free Software Foundation; either version 2 of the etisserant@0: * License, or (at your option) any later version. etisserant@0: * etisserant@0: * This program is distributed in the hope that it will be useful, but etisserant@0: * WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General etisserant@0: * Public License for more details. etisserant@0: * etisserant@0: * This code is made available on the understanding that it will not be etisserant@0: * used in safety-critical situations without a full and competent review. etisserant@0: */ etisserant@0: etisserant@0: /* etisserant@0: * An IEC 61131-3 IL and ST compiler. etisserant@0: * etisserant@0: * Based on the etisserant@0: * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) etisserant@0: * etisserant@0: */ etisserant@0: etisserant@0: etisserant@0: /* etisserant@0: * Code to be included into the code generated by the 4th stage. etisserant@0: * etisserant@0: * This is part of the 4th stage that generates etisserant@0: * a ST and IL source program equivalent to the IL and ST etisserant@0: * code. etisserant@0: * This is expected to be used mainly in debuging the syntax etisserant@0: * and lexical parser, and as a starting point for other etisserant@0: * 4th stages. etisserant@0: */ etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: // #include /* required for NULL */ etisserant@0: #include etisserant@0: #include etisserant@27: #include etisserant@0: #include "generate_iec.hh" etisserant@0: etisserant@0: #include "../stage4.hh" etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: //class generate_iec_c: public iterator_visitor_c { etisserant@0: class generate_iec_c: public visitor_c { etisserant@0: private: etisserant@0: stage4out_c &s4o; etisserant@0: etisserant@0: etisserant@0: public: etisserant@0: generate_iec_c(stage4out_c *s4o_ptr): s4o(*s4o_ptr) {} etisserant@0: ~generate_iec_c(void) {} etisserant@0: etisserant@0: etisserant@0: private: etisserant@0: etisserant@0: void *print_token(token_c *token) { etisserant@0: return s4o.print(token->value); etisserant@0: } etisserant@0: etisserant@0: void *print_literal(symbol_c *type, symbol_c *value) { etisserant@0: type->accept(*this); etisserant@0: s4o.print("#"); etisserant@0: value->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *print_list(list_c *list, etisserant@0: std::string pre_elem_str = "", etisserant@0: std::string inter_elem_str = "", etisserant@0: std::string post_elem_str = "") { etisserant@0: if (list->n > 0) { etisserant@0: s4o.print(pre_elem_str); etisserant@0: list->elements[0]->accept(*this); etisserant@0: } etisserant@0: etisserant@0: for(int i = 1; i < list->n; i++) { etisserant@0: s4o.print(inter_elem_str); etisserant@0: list->elements[i]->accept(*this); etisserant@0: } etisserant@0: etisserant@0: if (list->n > 0) etisserant@0: s4o.print(post_elem_str); etisserant@0: etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void *print_binary_expression(symbol_c *l_exp, etisserant@0: symbol_c *r_exp, etisserant@0: const char *operation) { etisserant@0: s4o.print("("); etisserant@0: l_exp->accept(*this); etisserant@0: s4o.print(operation); etisserant@0: r_exp->accept(*this); etisserant@0: s4o.print(")"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *print_unary_expression(symbol_c *exp, etisserant@0: const char *operation) { etisserant@0: s4o.print(operation); etisserant@0: exp->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: public: lbessard@143: lbessard@143: /* EN/ENO */ lbessard@143: void *visit(en_param_c *symbol) { lbessard@143: s4o.print("EN"); lbessard@143: return NULL; lbessard@143: } lbessard@143: lbessard@143: void *visit(eno_param_c *symbol) { lbessard@143: s4o.print("ENO"); lbessard@143: return NULL; lbessard@143: } lbessard@143: etisserant@0: /***************************/ etisserant@0: /* 2.1.6 Pragmas */ etisserant@0: /***************************/ etisserant@0: void *visit(pragma_c *symbol) {return print_token(symbol);} etisserant@0: etisserant@0: etisserant@0: /***************************/ etisserant@0: /* B 0 - Programming Model */ etisserant@0: /***************************/ etisserant@0: void *visit(library_c *symbol) {return print_list(symbol);} etisserant@0: etisserant@0: /*******************************************/ etisserant@0: /* B 1.1 - Letters, digits and identifiers */ etisserant@0: /*******************************************/ etisserant@0: void *visit(identifier_c *symbol) {return print_token(symbol);} etisserant@0: etisserant@0: /*********************/ etisserant@0: /* B 1.2 - Constants */ etisserant@0: /*********************/ etisserant@0: etisserant@0: /******************************/ etisserant@0: /* B 1.2.1 - Numeric Literals */ etisserant@0: /******************************/ etisserant@0: void *visit(real_c *symbol) {return print_token(symbol);} etisserant@0: void *visit(integer_c *symbol) {return print_token(symbol);} etisserant@0: void *visit(binary_integer_c *symbol) {return print_token(symbol);} etisserant@0: void *visit(octal_integer_c *symbol) {return print_token(symbol);} etisserant@0: void *visit(hex_integer_c *symbol) {return print_token(symbol);} etisserant@0: etisserant@0: void *visit(numeric_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} etisserant@0: void *visit(integer_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} etisserant@0: void *visit(real_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} etisserant@0: void *visit(bit_string_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} etisserant@0: void *visit(boolean_literal_c *symbol) {return print_literal(symbol->type, symbol->value);} lbessard@118: void *visit(neg_literal_c *symbol) {return print_unary_expression(symbol->exp, "-");} lbessard@118: etisserant@0: etisserant@0: /* helper class for boolean_literal_c */ etisserant@0: void *visit(boolean_true_c *symbol) {s4o.print(/*"TRUE"*/"1"); return NULL;} etisserant@0: void *visit(boolean_false_c *symbol) {s4o.print(/*"FALSE"*/"0"); return NULL;} etisserant@0: etisserant@0: /*******************************/ etisserant@0: /* B.1.2.2 Character Strings */ etisserant@0: /*******************************/ etisserant@0: void *visit(double_byte_character_string_c *symbol) {return print_token(symbol);} etisserant@0: void *visit(single_byte_character_string_c *symbol) {return print_token(symbol);} etisserant@0: etisserant@0: etisserant@0: /***************************/ etisserant@0: /* B 1.2.3 - Time Literals */ etisserant@0: /***************************/ etisserant@0: etisserant@0: /************************/ etisserant@0: /* B 1.2.3.1 - Duration */ etisserant@0: /************************/ etisserant@0: void *visit(neg_time_c *symbol) {s4o.print("-"); return NULL;} etisserant@0: etisserant@0: void *visit(duration_c *symbol) { etisserant@0: s4o.print("TIME#"); etisserant@0: if (symbol->neg != NULL) etisserant@0: symbol->neg->accept(*this); etisserant@0: symbol->interval->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(fixed_point_c *symbol) {return print_token(symbol);} etisserant@0: etisserant@0: void *visit(days_c *symbol) { etisserant@0: symbol->days->accept(*this); etisserant@0: s4o.print("d"); etisserant@0: if (symbol->hours != NULL) etisserant@0: symbol->hours->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(hours_c *symbol) { etisserant@0: symbol->hours->accept(*this); etisserant@0: s4o.print("h"); etisserant@0: if (symbol->minutes != NULL) etisserant@0: symbol->minutes->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(minutes_c *symbol) { etisserant@0: symbol->minutes->accept(*this); etisserant@0: s4o.print("m"); etisserant@0: if (symbol->seconds != NULL) etisserant@0: symbol->seconds->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(seconds_c *symbol) { etisserant@0: symbol->seconds->accept(*this); etisserant@0: s4o.print("s"); etisserant@0: if (symbol->milliseconds != NULL) etisserant@0: symbol->milliseconds->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(milliseconds_c *symbol) { etisserant@0: symbol->milliseconds->accept(*this); etisserant@0: s4o.print("ms"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /************************************/ etisserant@0: /* B 1.2.3.2 - Time of day and Date */ etisserant@0: /************************************/ etisserant@0: etisserant@0: void *visit(time_of_day_c *symbol) { etisserant@0: s4o.print("TIME_OF_DAY#"); etisserant@0: symbol->daytime->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(daytime_c *symbol) { etisserant@0: symbol->day_hour->accept(*this); etisserant@0: s4o.print(":"); etisserant@0: symbol->day_minute->accept(*this); etisserant@0: s4o.print(":"); etisserant@0: symbol->day_second->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void *visit(date_c *symbol) { etisserant@0: s4o.print("DATE#"); etisserant@0: symbol->date_literal->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(date_literal_c *symbol) { etisserant@0: symbol->year->accept(*this); etisserant@0: s4o.print("-"); etisserant@0: symbol->month->accept(*this); etisserant@0: s4o.print("-"); etisserant@0: symbol->day->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(date_and_time_c *symbol) { etisserant@0: s4o.print("DATE_AND_TIME#"); etisserant@0: symbol->date_literal->accept(*this); etisserant@0: s4o.print("-"); etisserant@0: symbol->daytime->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: etisserant@0: /***********************************/ etisserant@0: /* B 1.3.1 - Elementary Data Types */ etisserant@0: /***********************************/ etisserant@0: void *visit(time_type_name_c *symbol) {s4o.print("TIME"); return NULL;} etisserant@0: void *visit(bool_type_name_c *symbol) {s4o.print("BOOL"); return NULL;} mario@177: /******************************************************/ mario@177: /* whether we are suporting safe extensions */ mario@177: /* as defined in PLCopen - Technical Committee 5 */ mario@177: /* Safety Software Technical Specification, */ mario@177: /* Part 1: Concepts and Function Blocks, */ mario@177: /* Version 1.0 – Official Release */ mario@177: /******************************************************/ mario@177: void *visit(safebool_type_name_c *symbol) {s4o.print("SAFEBOOL"); return NULL;} etisserant@0: void *visit(sint_type_name_c *symbol) {s4o.print("SINT"); return NULL;} etisserant@0: void *visit(int_type_name_c *symbol) {s4o.print("INT"); return NULL;} etisserant@0: void *visit(dint_type_name_c *symbol) {s4o.print("DINT"); return NULL;} etisserant@0: void *visit(lint_type_name_c *symbol) {s4o.print("LINT"); return NULL;} etisserant@0: void *visit(usint_type_name_c *symbol) {s4o.print("USINT"); return NULL;} etisserant@0: void *visit(uint_type_name_c *symbol) {s4o.print("UINT"); return NULL;} etisserant@0: void *visit(udint_type_name_c *symbol) {s4o.print("UDINT"); return NULL;} etisserant@0: void *visit(ulint_type_name_c *symbol) {s4o.print("ULINT"); return NULL;} etisserant@0: void *visit(real_type_name_c *symbol) {s4o.print("REAL"); return NULL;} etisserant@0: void *visit(lreal_type_name_c *symbol) {s4o.print("LREAL"); return NULL;} etisserant@0: void *visit(date_type_name_c *symbol) {s4o.print("DATE"); return NULL;} etisserant@0: void *visit(tod_type_name_c *symbol) {s4o.print("TOD"); return NULL;} etisserant@0: void *visit(dt_type_name_c *symbol) {s4o.print("DT"); return NULL;} etisserant@0: void *visit(byte_type_name_c *symbol) {s4o.print("BYTE"); return NULL;} etisserant@0: void *visit(word_type_name_c *symbol) {s4o.print("WORD"); return NULL;} etisserant@0: void *visit(lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;} etisserant@0: void *visit(dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;} etisserant@0: void *visit(string_type_name_c *symbol) {s4o.print("STRING"); return NULL;} etisserant@0: void *visit(wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;} lbessard@32: void *visit(constant_int_type_name_c *symbol) {return NULL;} lbessard@32: void *visit(constant_real_type_name_c *symbol) {return NULL;} etisserant@0: etisserant@0: etisserant@0: /********************************/ etisserant@0: /* B 1.3.3 - Derived data types */ etisserant@0: /********************************/ etisserant@0: /* TYPE type_declaration_list END_TYPE */ etisserant@0: void *visit(data_type_declaration_c *symbol) { etisserant@0: s4o.print("TYPE\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->type_declaration_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print("END_TYPE\n\n\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* helper symbol for data_type_declaration */ etisserant@0: /*| type_declaration_list type_declaration ';' */ etisserant@0: void *visit(type_declaration_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* simple_type_name ':' simple_spec_init */ etisserant@0: void *visit(simple_type_declaration_c *symbol) { etisserant@0: symbol->simple_type_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->simple_spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* simple_specification ASSIGN constant */ etisserant@0: void *visit(simple_spec_init_c *symbol) { etisserant@0: symbol->simple_specification->accept(*this); etisserant@0: if (symbol->constant != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->constant->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* subrange_type_name ':' subrange_spec_init */ etisserant@0: void *visit(subrange_type_declaration_c *symbol) { etisserant@0: symbol->subrange_type_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->subrange_spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* subrange_specification ASSIGN signed_integer */ etisserant@0: void *visit(subrange_spec_init_c *symbol) { etisserant@0: symbol->subrange_specification->accept(*this); etisserant@0: if (symbol->signed_integer != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->signed_integer->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* integer_type_name '(' subrange')' */ etisserant@0: void *visit(subrange_specification_c *symbol) { etisserant@0: symbol->integer_type_name->accept(*this); lbessard@98: if (symbol->subrange != NULL) { lbessard@98: s4o.print("("); lbessard@98: symbol->subrange->accept(*this); lbessard@98: s4o.print(")"); lbessard@98: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* signed_integer DOTDOT signed_integer */ etisserant@0: void *visit(subrange_c *symbol) { etisserant@0: symbol->lower_limit->accept(*this); etisserant@0: s4o.print(" .. "); etisserant@0: symbol->upper_limit->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* enumerated_type_name ':' enumerated_spec_init */ etisserant@0: void *visit(enumerated_type_declaration_c *symbol) { etisserant@0: symbol->enumerated_type_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->enumerated_spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* enumerated_specification ASSIGN enumerated_value */ etisserant@0: void *visit(enumerated_spec_init_c *symbol) { etisserant@0: symbol->enumerated_specification->accept(*this); etisserant@0: if (symbol->enumerated_value != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->enumerated_value->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for enumerated_specification->enumerated_spec_init */ etisserant@0: /* enumerated_value_list ',' enumerated_value */ etisserant@0: void *visit(enumerated_value_list_c *symbol) {print_list(symbol, "(", ", ", ")"); return NULL;} etisserant@0: etisserant@0: /* enumerated_type_name '#' identifier */ etisserant@0: void *visit(enumerated_value_c *symbol) { lbessard@144: if (symbol->type != NULL) { lbessard@144: symbol->type->accept(*this); lbessard@144: s4o.print("#"); lbessard@144: } etisserant@0: symbol->value->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* identifier ':' array_spec_init */ etisserant@0: void *visit(array_type_declaration_c *symbol) { etisserant@0: symbol->identifier->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->array_spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* array_specification [ASSIGN array_initialization} */ etisserant@0: /* array_initialization may be NULL ! */ etisserant@0: void *visit(array_spec_init_c *symbol) { etisserant@0: symbol->array_specification->accept(*this); etisserant@0: if (symbol->array_initialization != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->array_initialization->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */ etisserant@0: void *visit(array_specification_c *symbol) { etisserant@0: s4o.print("ARRAY ["); etisserant@0: symbol->array_subrange_list->accept(*this); etisserant@0: s4o.print("] OF "); etisserant@0: symbol->non_generic_type_name->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for array_specification */ etisserant@0: /* array_subrange_list ',' subrange */ etisserant@0: void *visit(array_subrange_list_c *symbol) {print_list(symbol, "", ", "); return NULL;} etisserant@0: etisserant@0: /* helper symbol for array_initialization */ etisserant@0: /* array_initial_elements_list ',' array_initial_elements */ etisserant@0: void *visit(array_initial_elements_list_c *symbol) {print_list(symbol, "[", ", ", "]"); return NULL;} etisserant@0: etisserant@0: /* integer '(' [array_initial_element] ')' */ etisserant@0: /* array_initial_element may be NULL ! */ etisserant@0: void *visit(array_initial_elements_c *symbol) { etisserant@0: symbol->integer->accept(*this); etisserant@0: s4o.print("("); etisserant@0: if (symbol->array_initial_element != NULL) etisserant@0: symbol->array_initial_element->accept(*this); etisserant@0: s4o.print(")"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* structure_type_name ':' structure_specification */ etisserant@0: void *visit(structure_type_declaration_c *symbol) { etisserant@0: symbol->structure_type_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->structure_specification->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* structure_type_name ASSIGN structure_initialization */ etisserant@0: /* structure_initialization may be NULL ! */ etisserant@0: void *visit(initialized_structure_c *symbol) { etisserant@0: symbol->structure_type_name->accept(*this); etisserant@0: if (symbol->structure_initialization != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->structure_initialization->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for structure_declaration */ etisserant@0: /* structure_declaration: STRUCT structure_element_declaration_list END_STRUCT */ etisserant@0: /* structure_element_declaration_list structure_element_declaration ';' */ etisserant@0: void *visit(structure_element_declaration_list_c *symbol) { etisserant@0: s4o.print("STRUCT\n"); etisserant@0: s4o.indent_right(); etisserant@0: print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n" + s4o.indent_spaces); etisserant@0: s4o.print("END_STRUCT"); etisserant@0: s4o.indent_left(); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* structure_element_name ':' *_spec_init */ etisserant@0: void *visit(structure_element_declaration_c *symbol) { etisserant@0: symbol->structure_element_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for structure_initialization */ etisserant@0: /* structure_initialization: '(' structure_element_initialization_list ')' */ etisserant@0: /* structure_element_initialization_list ',' structure_element_initialization */ etisserant@0: void *visit(structure_element_initialization_list_c *symbol) {print_list(symbol, "(", ", ", ")"); return NULL;} etisserant@0: etisserant@0: /* structure_element_name ASSIGN value */ etisserant@0: void *visit(structure_element_initialization_c *symbol) { etisserant@0: symbol->structure_element_name->accept(*this); etisserant@0: s4o.print(" := "); etisserant@0: symbol->value->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ etisserant@0: void *visit(string_type_declaration_c *symbol) { etisserant@0: symbol->string_type_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->elementary_string_type_name->accept(*this); etisserant@0: symbol->string_type_declaration_size->accept(*this); etisserant@0: if (symbol->string_type_declaration_init != NULL) etisserant@0: symbol->string_type_declaration_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: /*********************/ etisserant@0: /* B 1.4 - Variables */ etisserant@0: /*********************/ etisserant@0: void *visit(symbolic_variable_c *symbol) { etisserant@0: symbol->var_name->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /********************************************/ etisserant@0: /* B.1.4.1 Directly Represented Variables */ etisserant@0: /********************************************/ etisserant@0: void *visit(direct_variable_c *symbol) {return print_token(symbol);} etisserant@0: etisserant@0: etisserant@0: /*************************************/ etisserant@0: /* B.1.4.2 Multi-element Variables */ etisserant@0: /*************************************/ etisserant@0: /* subscripted_variable '[' subscript_list ']' */ etisserant@0: void *visit(array_variable_c *symbol) { etisserant@0: symbol->subscripted_variable->accept(*this); etisserant@0: s4o.print("["); etisserant@0: symbol->subscript_list->accept(*this); etisserant@0: s4o.print("]"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* subscript_list ',' subscript */ etisserant@0: void *visit(subscript_list_c *symbol) {return print_list(symbol, "", ", ");} etisserant@0: etisserant@0: /* record_variable '.' field_selector */ etisserant@0: void *visit(structured_variable_c *symbol) { etisserant@0: symbol->record_variable->accept(*this); etisserant@0: s4o.print("."); etisserant@0: symbol->field_selector->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /******************************************/ etisserant@0: /* B 1.4.3 - Declaration & Initialisation */ etisserant@0: /******************************************/ etisserant@0: void *visit(constant_option_c *symbol) {s4o.print("CONSTANT"); return NULL;} etisserant@0: void *visit(retain_option_c *symbol) {s4o.print("RETAIN"); return NULL;} etisserant@0: void *visit(non_retain_option_c *symbol) {s4o.print("NON_RETAIN"); return NULL;} etisserant@0: etisserant@0: /* VAR_INPUT [RETAIN | NON_RETAIN] input_declaration_list END_VAR */ etisserant@0: /* option -> the RETAIN/NON_RETAIN/ directive... */ etisserant@0: void *visit(input_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR_INPUT "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->input_declaration_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for input_declarations */ etisserant@0: /*| input_declaration_list input_declaration ';' */ etisserant@0: void *visit(input_declaration_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /* edge -> The F_EDGE or R_EDGE directive */ etisserant@0: void *visit(edge_declaration_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : BOOL "); etisserant@0: symbol->edge->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: lbessard@146: void *visit(en_param_declaration_c *symbol) { lbessard@146: s4o.print("EN : BOOL := 1"); lbessard@146: return NULL; lbessard@146: } etisserant@0: etisserant@0: void *visit(raising_edge_option_c *symbol) { etisserant@0: s4o.print("R_EDGE"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(falling_edge_option_c *symbol) { etisserant@0: s4o.print("F_EDGE"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* var1_list is one of the following... etisserant@0: * simple_spec_init_c * etisserant@0: * subrange_spec_init_c * etisserant@0: * enumerated_spec_init_c * etisserant@0: */ etisserant@0: void *visit(var1_init_decl_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void *visit(var1_list_c *symbol) {return print_list(symbol, "", ", ");} etisserant@0: etisserant@0: etisserant@0: /* var1_list ':' array_spec_init */ etisserant@0: void *visit(array_var_init_decl_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->array_spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* var1_list ':' initialized_structure */ etisserant@0: void *visit(structured_var_init_decl_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->initialized_structure->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* name_list ':' function_block_type_name ASSIGN structure_initialization */ etisserant@0: /* structure_initialization -> may be NULL ! */ etisserant@0: void *visit(fb_name_decl_c *symbol) { etisserant@0: symbol->fb_name_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->function_block_type_name->accept(*this); etisserant@0: if (symbol->structure_initialization != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->structure_initialization->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* name_list ',' fb_name */ etisserant@0: void *visit(fb_name_list_c *symbol) {return print_list(symbol, "", ", ");} etisserant@0: etisserant@0: /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */ etisserant@0: /* option -> may be NULL ! */ etisserant@0: void *visit(output_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR_OUTPUT "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_init_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: lbessard@146: void *visit(eno_param_declaration_c *symbol) { lbessard@146: s4o.print("EN0 : BOOL"); lbessard@146: return NULL; lbessard@146: } lbessard@146: etisserant@0: /* VAR_IN_OUT END_VAR */ etisserant@0: void *visit(input_output_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR_IN_OUT "); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_declaration_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for input_output_declarations */ etisserant@0: /* var_declaration_list var_declaration ';' */ etisserant@0: void *visit(var_declaration_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /* var1_list ':' array_specification */ etisserant@0: void *visit(array_var_declaration_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->array_specification->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* var1_list ':' structure_type_name */ etisserant@0: void *visit(structured_var_declaration_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->structure_type_name->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* VAR [CONSTANT] var_init_decl_list END_VAR */ etisserant@0: /* option -> may be NULL ! */ etisserant@0: void *visit(var_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_init_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* VAR RETAIN var_init_decl_list END_VAR */ etisserant@0: void *visit(retentive_var_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR RETAIN "); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_init_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */ etisserant@0: /* option -> may be NULL ! */ etisserant@0: void *visit(located_var_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->located_var_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for located_var_declarations */ etisserant@0: /* located_var_decl_list located_var_decl ';' */ etisserant@0: void *visit(located_var_decl_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /* [variable_name] location ':' located_var_spec_init */ etisserant@0: /* variable_name -> may be NULL ! */ etisserant@0: void *visit(located_var_decl_c *symbol) { etisserant@0: if (symbol->variable_name != NULL) { etisserant@0: symbol->variable_name->accept(*this); etisserant@0: s4o.print(" "); etisserant@0: } etisserant@0: symbol->location->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->located_var_spec_init->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */ etisserant@0: /* option -> may be NULL ! */ etisserant@0: void *visit(external_var_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR_EXTERNAL "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->external_declaration_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for external_var_declarations */ etisserant@0: /*| external_declaration_list external_declaration';' */ etisserant@0: void *visit(external_declaration_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /* global_var_name ':' (simple_specification|subrange_specification|enumerated_specification|array_specification|prev_declared_structure_type_name|function_block_type_name) */ etisserant@0: void *visit(external_declaration_c *symbol) { etisserant@0: symbol->global_var_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->specification->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */ etisserant@0: /* option -> may be NULL ! */ etisserant@0: void *visit(global_var_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR_GLOBAL "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->global_var_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for global_var_declarations */ etisserant@0: /*| global_var_decl_list global_var_decl ';' */ etisserant@0: void *visit(global_var_decl_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /*| global_var_spec ':' [located_var_spec_init|function_block_type_name] */ etisserant@0: /* type_specification ->may be NULL ! */ etisserant@0: void *visit(global_var_decl_c *symbol) { etisserant@0: symbol->global_var_spec->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: if (symbol->type_specification != NULL) etisserant@0: symbol->type_specification->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /*| global_var_name location */ etisserant@0: void *visit(global_var_spec_c *symbol) { etisserant@0: symbol->global_var_name->accept(*this); etisserant@0: s4o.print(" "); etisserant@0: symbol->location->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* AT direct_variable */ etisserant@0: void *visit(location_c *symbol) { etisserant@0: s4o.print("AT "); etisserant@0: symbol->direct_variable->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /*| global_var_list ',' global_var_name */ etisserant@0: void *visit(global_var_list_c *symbol) {return print_list(symbol, "", ", ");} etisserant@0: etisserant@0: /* var1_list ':' single_byte_string_spec */ etisserant@0: void *visit(single_byte_string_var_declaration_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->single_byte_string_spec->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* STRING ['[' integer ']'] [ASSIGN single_byte_character_string] */ etisserant@0: /* integer ->may be NULL ! */ etisserant@0: /* single_byte_character_string ->may be NULL ! */ etisserant@0: void *visit(single_byte_string_spec_c *symbol) { etisserant@0: s4o.print("STRING ["); etisserant@0: if (symbol->integer != NULL) etisserant@0: symbol->integer->accept(*this); etisserant@0: s4o.print("]"); etisserant@0: if (symbol->single_byte_character_string != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->single_byte_character_string->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* var1_list ':' double_byte_string_spec */ etisserant@0: void *visit(double_byte_string_var_declaration_c *symbol) { etisserant@0: symbol->var1_list->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->double_byte_string_spec->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* WSTRING ['[' integer ']'] [ASSIGN double_byte_character_string] */ etisserant@0: /* integer ->may be NULL ! */ etisserant@0: /* double_byte_character_string ->may be NULL ! */ etisserant@0: void *visit(double_byte_string_spec_c *symbol) { etisserant@0: s4o.print("WSTRING ["); etisserant@0: if (symbol->integer != NULL) etisserant@0: symbol->integer->accept(*this); etisserant@0: s4o.print("]"); etisserant@0: if (symbol->double_byte_character_string != NULL) { etisserant@0: s4o.print(" := "); etisserant@0: symbol->double_byte_character_string->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /*| VAR [RETAIN|NON_RETAIN] incompl_located_var_decl_list END_VAR */ etisserant@0: /* option ->may be NULL ! */ etisserant@0: void *visit(incompl_located_var_declarations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("VAR "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->incompl_located_var_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for incompl_located_var_declarations */ etisserant@0: /*| incompl_located_var_decl_list incompl_located_var_decl ';' */ etisserant@0: void *visit(incompl_located_var_decl_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /* variable_name incompl_location ':' var_spec */ etisserant@0: void *visit(incompl_located_var_decl_c *symbol) { etisserant@0: symbol->variable_name->accept(*this); etisserant@0: s4o.print(" "); etisserant@0: symbol->incompl_location->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->var_spec->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* AT incompl_location_token */ etisserant@0: void *visit(incompl_location_c *symbol) { etisserant@0: s4o.print(" AT "); lbessard@10: return print_token(symbol); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* intermediate helper symbol for: etisserant@0: * - non_retentive_var_decls etisserant@0: * - output_declarations etisserant@0: */ etisserant@0: /* | var_init_decl_list var_init_decl ';' */ etisserant@0: void *visit(var_init_decl_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /***********************/ etisserant@0: /* B 1.5.1 - Functions */ etisserant@0: /***********************/ etisserant@0: void *visit(function_declaration_c *symbol) { etisserant@0: s4o.print("FUNCTION "); etisserant@0: symbol->derived_function_name->accept(*this); etisserant@0: s4o.print(" : "); etisserant@0: symbol->type_name->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_declarations_list->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: symbol->function_body->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces + "END_FUNCTION\n\n\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* intermediate helper symbol for function_declaration */ etisserant@0: void *visit(var_declarations_list_c *symbol) {return print_list(symbol);} etisserant@0: etisserant@0: void *visit(function_var_decls_c *symbol) { etisserant@1: //s4o.print(s4o.indent_spaces); etisserant@1: s4o.print("VAR "); etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* intermediate helper symbol for function_var_decls */ etisserant@0: void *visit(var2_init_decl_list_c *symbol) { etisserant@0: print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /*****************************/ etisserant@0: /* B 1.5.2 - Function Blocks */ etisserant@0: /*****************************/ etisserant@0: /* FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */ etisserant@0: void *visit(function_block_declaration_c *symbol) { etisserant@0: s4o.print("FUNCTION_BLOCK "); etisserant@0: symbol->fblock_name->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_declarations->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: symbol->fblock_body->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces + "END_FUNCTION_BLOCK\n\n\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* VAR_TEMP temp_var_decl_list END_VAR */ etisserant@0: void *visit(temp_var_decls_c *symbol) { etisserant@0: s4o.print("VAR_TEMP\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* intermediate helper symbol for temp_var_decls */ etisserant@0: void *visit(temp_var_decls_list_c *symbol) {return print_list(symbol);} etisserant@0: etisserant@0: /* VAR NON_RETAIN var_init_decl_list END_VAR */ etisserant@0: void *visit(non_retentive_var_decls_c *symbol) { etisserant@0: s4o.print("VAR NON_RETAIN\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_decl_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print("END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /**********************/ etisserant@0: /* B 1.5.3 - Programs */ etisserant@0: /**********************/ etisserant@0: /* PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */ etisserant@0: void *visit(program_declaration_c *symbol) { etisserant@0: s4o.print("PROGRAM "); etisserant@0: symbol->program_type_name->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->var_declarations->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: symbol->function_block_body->accept(*this); etisserant@0: s4o.indent_left(); etisserant@1: s4o.print("END_PROGRAM\n\n\n"); etisserant@1: return NULL; etisserant@1: } etisserant@1: etisserant@1: /***********************************/ etisserant@1: /* B 1.6 Sequential Function Chart */ etisserant@1: /***********************************/ mario@8: mario@7: /* sequential_function_chart {sfc_network} */ etisserant@1: void *visit(sequential_function_chart_c *symbol) { lbessard@10: print_list(symbol, "", "\n", ""); etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@7: /* sfc_network {step | transition | action} */ etisserant@1: void *visit(sfc_network_c *symbol) { lbessard@10: print_list(symbol, "", "\n", ""); etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@7: /* INITIAL_STEP step_name ':' [action_association_list] END_STEP */ etisserant@1: void *visit(initial_step_c *symbol) { etisserant@1: s4o.print(s4o.indent_spaces); etisserant@1: s4o.print("INITIAL_STEP "); etisserant@1: symbol->step_name->accept(*this); lbessard@10: s4o.print(":\n"); etisserant@1: s4o.indent_right(); etisserant@1: symbol->action_association_list->accept(*this); etisserant@1: s4o.print("\n"); etisserant@1: s4o.indent_left(); etisserant@1: s4o.print(s4o.indent_spaces); lbessard@10: s4o.print("END_STEP\n"); etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@7: /* STEP step_name ':' [action_association_list] END_STEP */ etisserant@1: void *visit(step_c *symbol) { etisserant@1: s4o.print(s4o.indent_spaces); etisserant@1: s4o.print("STEP "); etisserant@1: symbol->step_name->accept(*this); lbessard@10: s4o.print(":\n"); etisserant@1: s4o.indent_right(); etisserant@1: symbol->action_association_list->accept(*this); etisserant@1: s4o.print("\n"); etisserant@1: s4o.indent_left(); etisserant@1: s4o.print(s4o.indent_spaces); lbessard@10: s4o.print("END_STEP\n"); etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@7: /* action_association_list {action_association} */ etisserant@1: void *visit(action_association_list_c *symbol) { etisserant@1: print_list(symbol, "", "\n", ""); etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@7: /* action_name '(' [action_qualifier] [indicator_name_list] ')' */ etisserant@1: void *visit(action_association_c *symbol) { lbessard@10: s4o.print(s4o.indent_spaces); lbessard@10: symbol->action_name->accept(*this); lbessard@10: s4o.print("("); etisserant@1: if(symbol->action_qualifier != NULL){ etisserant@1: symbol->action_qualifier->accept(*this); etisserant@1: } mario@7: if(symbol->indicator_name_list != NULL){ lbessard@10: symbol->indicator_name_list->accept(*this); lbessard@10: } lbessard@10: s4o.print(");"); etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@7: /* indicator_name_list ',' indicator_name */ etisserant@1: void *visit(indicator_name_list_c *symbol) { lbessard@10: print_list(symbol, ", ", ", ", ""); mario@7: return NULL; mario@7: } mario@7: mario@7: /* action_qualifier [',' action_time] */ etisserant@1: void *visit(action_qualifier_c *symbol) { mario@7: symbol->action_qualifier->accept(*this); mario@7: if(symbol->action_time != NULL){ mario@7: s4o.print(", "); mario@7: symbol->action_time->accept(*this); mario@7: } mario@7: return NULL; mario@7: } mario@7: mario@7: /* N | R | S | P */ etisserant@1: void *visit(qualifier_c *symbol) { lbessard@10: print_token(symbol); mario@8: return NULL; etisserant@1: } etisserant@1: mario@7: /* L | D | SD | DS | SL */ etisserant@1: void *visit(timed_qualifier_c *symbol) { lbessard@10: print_token(symbol); mario@8: return NULL; mario@8: } mario@8: mario@71: /* TRANSITION [transition_name] ['(''PRIORITY'':='integer')'] mario@71: * FROMstepsTO steps lbessard@17: * ':' simple_instr_list | ':=' expression mario@8: * END_TRANSITION mario@8: */ etisserant@1: void *visit(transition_c *symbol) { etisserant@1: s4o.print(s4o.indent_spaces); etisserant@1: s4o.print("TRANSITION "); etisserant@1: if (symbol->transition_name != NULL){ etisserant@1: symbol->transition_name->accept(*this); etisserant@1: s4o.print(" "); etisserant@1: } etisserant@1: if (symbol->integer != NULL){ etisserant@1: s4o.print("(PRIORITY := "); etisserant@1: symbol->integer->accept(*this); etisserant@1: s4o.print(") "); etisserant@1: } etisserant@1: s4o.print("FROM "); etisserant@1: symbol->from_steps->accept(*this); lbessard@10: s4o.print(" TO "); etisserant@1: symbol->to_steps->accept(*this); etisserant@1: s4o.indent_right(); lbessard@87: symbol->transition_condition->accept(*this); lbessard@87: s4o.indent_left(); lbessard@87: s4o.print(s4o.indent_spaces); lbessard@87: s4o.print("END_TRANSITION\n"); lbessard@87: return NULL; lbessard@87: } lbessard@87: lbessard@87: void *visit(transition_condition_c *symbol) { lbessard@3: if (symbol->transition_condition_il != NULL) { lbessard@87: s4o.print(":\n"); lbessard@17: symbol->transition_condition_il->accept(*this); lbessard@3: } lbessard@3: if (symbol->transition_condition_st != NULL) { lbessard@87: s4o.print("\n"); lbessard@17: s4o.print(s4o.indent_spaces); lbessard@17: s4o.print(":= "); lbessard@17: symbol->transition_condition_st->accept(*this); lbessard@17: s4o.print(";\n"); lbessard@3: } etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@8: /* step_name | step_name_list */ etisserant@1: void *visit(steps_c *symbol) { etisserant@1: if(symbol->step_name != NULL){ etisserant@1: symbol->step_name->accept(*this); etisserant@1: } etisserant@1: if(symbol->step_name_list != NULL){ etisserant@1: symbol->step_name_list->accept(*this); etisserant@1: } etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@8: /* '(' step_name ',' step_name {',' step_name} ')' */ etisserant@1: void *visit(step_name_list_c *symbol) { lbessard@16: print_list(symbol, "(", ", ", ")"); etisserant@1: return NULL; etisserant@1: } etisserant@1: mario@8: /* ACTION action_name ':' function_block_body END_ACTION */ etisserant@1: void *visit(action_c *symbol) { mario@8: s4o.print(s4o.indent_spaces); mario@8: s4o.print("ACTION "); mario@8: symbol->action_name->accept(*this); lbessard@10: s4o.print(":\n"); lbessard@10: s4o.indent_right(); lbessard@10: symbol->function_block_body->accept(*this); lbessard@10: s4o.indent_left(); mario@8: s4o.print(s4o.indent_spaces); lbessard@10: s4o.print("END_ACTION\n"); mario@8: return NULL; mario@8: } mario@8: mario@8: mario@8: etisserant@0: /********************************/ etisserant@0: /* B 1.7 Configuration elements */ etisserant@0: /********************************/ etisserant@0: /* etisserant@0: CONFIGURATION configuration_name etisserant@0: optional_global_var_declarations etisserant@0: (resource_declaration_list | single_resource_declaration) etisserant@0: optional_access_declarations etisserant@0: optional_instance_specific_initializations etisserant@0: END_CONFIGURATION etisserant@0: */ etisserant@0: void *visit(configuration_declaration_c *symbol) { etisserant@0: s4o.print("CONFIGURATION "); etisserant@0: symbol->configuration_name->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: if (symbol->global_var_declarations != NULL) etisserant@0: symbol->global_var_declarations->accept(*this); etisserant@0: symbol->resource_declarations->accept(*this); etisserant@0: if (symbol->access_declarations != NULL) etisserant@0: symbol->access_declarations->accept(*this); etisserant@0: if (symbol->instance_specific_initializations != NULL) etisserant@0: symbol->instance_specific_initializations->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces + "END_CONFIGURATION\n\n\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* helper symbol for configuration_declaration */ etisserant@0: /*| resource_declaration_list resource_declaration */ etisserant@0: void *visit(resource_declaration_list_c *symbol) {return print_list(symbol);} etisserant@0: etisserant@0: etisserant@0: /* etisserant@0: RESOURCE resource_name ON resource_type_name etisserant@0: optional_global_var_declarations etisserant@0: single_resource_declaration etisserant@0: END_RESOURCE etisserant@0: */ etisserant@0: void *visit(resource_declaration_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces + "RESOURCE "); etisserant@0: symbol->resource_name->accept(*this); etisserant@0: s4o.print(" ON "); etisserant@0: symbol->resource_type_name->accept(*this); etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: if (symbol->global_var_declarations != NULL) etisserant@0: symbol->global_var_declarations->accept(*this); etisserant@0: symbol->resource_declaration->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces + "END_RESOURCE\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* task_configuration_list program_configuration_list */ etisserant@0: void *visit(single_resource_declaration_c *symbol) { etisserant@0: symbol->task_configuration_list->accept(*this); etisserant@0: symbol->program_configuration_list->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for single_resource_declaration */ etisserant@0: /*| task_configuration_list task_configuration ';'*/ etisserant@0: void *visit(task_configuration_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* helper symbol for single_resource_declaration */ etisserant@0: /*| program_configuration_list program_configuration ';'*/ etisserant@0: void *visit(program_configuration_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* helper symbol for etisserant@0: * - access_path etisserant@0: * - instance_specific_init etisserant@0: */ etisserant@0: /* | any_fb_name_list any_identifier '.'*/ etisserant@0: void *visit(any_fb_name_list_c *symbol) {return print_list(symbol, ".", ".");} etisserant@0: etisserant@0: etisserant@0: /* [resource_name '.'] global_var_name ['.' structure_element_name] */ etisserant@0: void *visit(global_var_reference_c *symbol) { etisserant@0: if (symbol->resource_name != NULL) { etisserant@0: symbol->resource_name->accept(*this); etisserant@0: s4o.print("."); etisserant@0: } etisserant@0: symbol->global_var_name->accept(*this); etisserant@0: if (symbol->structure_element_name != NULL) { etisserant@0: s4o.print("."); etisserant@0: symbol->structure_element_name->accept(*this); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* program_name '.' symbolic_variable */ etisserant@0: void *visit(program_output_reference_c *symbol) { etisserant@0: symbol->program_name->accept(*this); etisserant@0: s4o.print("."); etisserant@0: symbol->symbolic_variable->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* TASK task_name task_initialization */ etisserant@0: void *visit(task_configuration_c *symbol) { etisserant@0: s4o.print("TASK "); etisserant@0: symbol->task_name->accept(*this); etisserant@0: s4o.print(" "); etisserant@0: symbol->task_initialization->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */ etisserant@0: void *visit(task_initialization_c *symbol) { etisserant@0: s4o.print("("); etisserant@0: if (symbol->single_data_source != NULL) { etisserant@0: s4o.print("SINGLE := "); etisserant@0: symbol->single_data_source->accept(*this); etisserant@0: s4o.print(", "); etisserant@0: } etisserant@0: if (symbol->interval_data_source != NULL) { etisserant@0: s4o.print("INTERVAL := "); etisserant@0: symbol->interval_data_source->accept(*this); etisserant@0: s4o.print(", "); etisserant@0: } etisserant@0: s4o.print("PRIORITY := "); etisserant@0: symbol->priority_data_source->accept(*this); etisserant@0: s4o.print(")"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */ etisserant@0: void *visit(program_configuration_c *symbol) { etisserant@0: s4o.print("PROGRAM "); etisserant@0: if (symbol->retain_option != NULL) etisserant@0: symbol->retain_option->accept(*this); etisserant@0: symbol->program_name->accept(*this); etisserant@0: if (symbol->task_name != NULL) { etisserant@0: s4o.print(" WITH "); etisserant@0: symbol->task_name->accept(*this); etisserant@0: } etisserant@0: s4o.print(" : "); etisserant@0: symbol->program_type_name->accept(*this); etisserant@0: if (symbol->prog_conf_elements != NULL) { etisserant@0: s4o.print("("); etisserant@0: symbol->prog_conf_elements->accept(*this); etisserant@0: s4o.print(")"); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* prog_conf_elements ',' prog_conf_element */ etisserant@0: void *visit(prog_conf_elements_c *symbol) {return print_list(symbol, "", ", ");} etisserant@0: etisserant@0: /* fb_name WITH task_name */ etisserant@0: void *visit(fb_task_c *symbol) { etisserant@0: symbol->fb_name->accept(*this); etisserant@0: s4o.print(" WITH "); etisserant@0: symbol->task_name->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* any_symbolic_variable ASSIGN prog_data_source */ etisserant@0: void *visit(prog_cnxn_assign_c *symbol) { etisserant@0: symbol->symbolic_variable->accept(*this); etisserant@0: s4o.print(" := "); etisserant@0: symbol->prog_data_source->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* any_symbolic_variable SENDTO data_sink */ etisserant@0: void *visit(prog_cnxn_sendto_c *symbol) { etisserant@0: symbol->symbolic_variable->accept(*this); etisserant@0: s4o.print(" => "); lbessard@28: symbol->data_sink->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* VAR_CONFIG instance_specific_init_list END_VAR */ etisserant@0: void *visit(instance_specific_initializations_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces + "VAR_CONFIG\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->instance_specific_init_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces + "END_VAR\n"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for instance_specific_initializations */ etisserant@0: /*| instance_specific_init_list instance_specific_init ';'*/ etisserant@0: void *visit(instance_specific_init_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /* resource_name '.' program_name '.' optional_fb_name_list '.' etisserant@0: ((variable_name [location] ':' located_var_spec_init) | (fb_name ':' fb_initialization)) etisserant@0: */ etisserant@0: void *visit(instance_specific_init_c *symbol) { etisserant@0: symbol->resource_name->accept(*this); etisserant@0: s4o.print("."); etisserant@0: symbol->program_name->accept(*this); etisserant@0: symbol->any_fb_name_list->accept(*this); etisserant@0: if (symbol->variable_name != NULL) { etisserant@0: s4o.print("."); etisserant@0: symbol->variable_name->accept(*this); etisserant@0: } etisserant@0: if (symbol->location != NULL) { etisserant@0: s4o.print(" "); etisserant@0: symbol->location->accept(*this); etisserant@0: } etisserant@0: s4o.print(" : "); etisserant@0: symbol->initialization->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for instance_specific_init */ etisserant@0: /* function_block_type_name ':=' structure_initialization */ etisserant@0: void *visit(fb_initialization_c *symbol) { etisserant@0: symbol->function_block_type_name->accept(*this); etisserant@0: s4o.print(" := "); etisserant@0: symbol->structure_initialization->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /***********************************/ etisserant@0: /* B 2.1 Instructions and Operands */ etisserant@0: /***********************************/ etisserant@0: /*| instruction_list il_instruction */ etisserant@0: void *visit(instruction_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, "\n" + s4o.indent_spaces, "\n"); etisserant@0: } etisserant@0: etisserant@0: /* | label ':' [il_incomplete_instruction] eol_list */ etisserant@0: void *visit(il_instruction_c *symbol) { etisserant@0: if (symbol->label != NULL) { etisserant@0: symbol->label->accept(*this); etisserant@0: s4o.print(": "); etisserant@0: } etisserant@0: symbol->il_instruction->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* | il_simple_operator [il_operand] */ etisserant@0: void *visit(il_simple_operation_c *symbol) { etisserant@0: symbol->il_simple_operator->accept(*this); etisserant@0: if (symbol->il_operand != NULL) etisserant@0: symbol->il_operand->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* | function_name [il_operand_list] */ etisserant@0: void *visit(il_function_call_c *symbol) { etisserant@0: symbol->function_name->accept(*this); etisserant@0: s4o.print(" "); etisserant@0: if (symbol->il_operand_list != NULL) etisserant@0: symbol->il_operand_list->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */ etisserant@0: void *visit(il_expression_c *symbol) { etisserant@0: symbol->il_expr_operator->accept(*this); etisserant@0: s4o.print("("); etisserant@0: if (symbol->il_operand != NULL) etisserant@0: symbol->il_operand->accept(*this); etisserant@0: if (symbol->simple_instr_list != NULL) { etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->simple_instr_list->accept(*this); lbessard@10: s4o.print(s4o.indent_spaces); etisserant@0: s4o.indent_left(); etisserant@0: } etisserant@0: s4o.print(")"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* il_jump_operator label */ etisserant@0: void *visit(il_jump_operation_c *symbol) { etisserant@0: symbol->il_jump_operator->accept(*this); etisserant@0: symbol->label->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* il_call_operator prev_declared_fb_name etisserant@0: * | il_call_operator prev_declared_fb_name '(' ')' etisserant@0: * | il_call_operator prev_declared_fb_name '(' eol_list ')' etisserant@0: * | il_call_operator prev_declared_fb_name '(' il_operand_list ')' etisserant@0: * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' etisserant@0: */ etisserant@0: void *visit(il_fb_call_c *symbol) { etisserant@0: symbol->il_call_operator->accept(*this); etisserant@0: symbol->fb_name->accept(*this); etisserant@0: s4o.print("("); etisserant@0: if (symbol->il_operand_list != NULL) etisserant@0: symbol->il_operand_list->accept(*this); etisserant@0: if (symbol->il_param_list != NULL) { etisserant@0: s4o.print("\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->il_param_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: } etisserant@0: s4o.print(")"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* | function_name '(' eol_list [il_param_list] ')' */ etisserant@0: void *visit(il_formal_funct_call_c *symbol) { etisserant@0: symbol->function_name->accept(*this); etisserant@0: s4o.print("("); mario@71: s4o.print("\n"); etisserant@0: if (symbol->il_param_list != NULL) { etisserant@0: s4o.indent_right(); etisserant@0: symbol->il_param_list->accept(*this); etisserant@0: s4o.print(")"); mario@71: s4o.indent_left(); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* | il_operand_list ',' il_operand */ mario@71: void *visit(il_operand_list_c *symbol) { mario@71: return print_list(symbol, "", ", "); mario@71: } etisserant@0: etisserant@0: /* | simple_instr_list il_simple_instruction */ etisserant@0: void *visit(simple_instr_list_c *symbol) { lbessard@10: return print_list(symbol, s4o.indent_spaces, "\n" + s4o.indent_spaces, "\n"); etisserant@0: } etisserant@0: etisserant@0: /* | il_initial_param_list il_param_instruction */ mario@71: void *visit(il_param_list_c *symbol) { mario@71: // return print_list(symbol); mario@71: return print_list(symbol, s4o.indent_spaces, ",\n" + s4o.indent_spaces, "\n" + s4o.indent_spaces); mario@71: } etisserant@0: etisserant@0: /* il_assign_operator il_operand etisserant@0: * | il_assign_operator '(' eol_list simple_instr_list ')' etisserant@0: */ etisserant@0: void *visit(il_param_assignment_c *symbol) { etisserant@0: symbol->il_assign_operator->accept(*this); mario@71: s4o.print(" := "); etisserant@0: if (symbol->il_operand != NULL) etisserant@0: symbol->il_operand->accept(*this); etisserant@0: if (symbol->simple_instr_list != NULL) { etisserant@0: s4o.print("(\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->simple_instr_list->accept(*this); lbessard@10: s4o.print(s4o.indent_spaces); mario@71: s4o.print(")"); etisserant@0: s4o.indent_left(); etisserant@0: } etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* il_assign_out_operator variable */ etisserant@0: void *visit(il_param_out_assignment_c *symbol) { etisserant@0: symbol->il_assign_out_operator->accept(*this); mario@71: s4o.print(" => "); etisserant@0: symbol->variable->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /*******************/ etisserant@0: /* B 2.2 Operators */ etisserant@0: /*******************/ etisserant@0: void *visit(LD_operator_c *symbol) {s4o.print("LD "); return NULL;} etisserant@0: void *visit(LDN_operator_c *symbol) {s4o.print("LDN "); return NULL;} etisserant@0: void *visit(ST_operator_c *symbol) {s4o.print("ST "); return NULL;} etisserant@0: void *visit(STN_operator_c *symbol) {s4o.print("STN "); return NULL;} etisserant@0: void *visit(NOT_operator_c *symbol) {s4o.print("NOT "); return NULL;} etisserant@0: void *visit(S_operator_c *symbol) {s4o.print("S "); return NULL;} etisserant@0: void *visit(R_operator_c *symbol) {s4o.print("R "); return NULL;} etisserant@0: void *visit(S1_operator_c *symbol) {s4o.print("S1 "); return NULL;} etisserant@0: void *visit(R1_operator_c *symbol) {s4o.print("R1 "); return NULL;} etisserant@0: void *visit(CLK_operator_c *symbol) {s4o.print("CLK "); return NULL;} etisserant@0: void *visit(CU_operator_c *symbol) {s4o.print("CU "); return NULL;} etisserant@0: void *visit(CD_operator_c *symbol) {s4o.print("CD "); return NULL;} etisserant@0: void *visit(PV_operator_c *symbol) {s4o.print("PV "); return NULL;} etisserant@0: void *visit(IN_operator_c *symbol) {s4o.print("IN "); return NULL;} etisserant@0: void *visit(PT_operator_c *symbol) {s4o.print("PT "); return NULL;} etisserant@0: void *visit(AND_operator_c *symbol) {s4o.print("AND "); return NULL;} etisserant@0: void *visit(OR_operator_c *symbol) {s4o.print("OR "); return NULL;} etisserant@0: void *visit(XOR_operator_c *symbol) {s4o.print("XOR "); return NULL;} etisserant@0: void *visit(ANDN_operator_c *symbol) {s4o.print("ANDN "); return NULL;} etisserant@0: void *visit(ORN_operator_c *symbol) {s4o.print("ORN "); return NULL;} etisserant@0: void *visit(XORN_operator_c *symbol) {s4o.print("XORN "); return NULL;} etisserant@0: void *visit(ADD_operator_c *symbol) {s4o.print("ADD "); return NULL;} etisserant@0: void *visit(SUB_operator_c *symbol) {s4o.print("SUB "); return NULL;} etisserant@0: void *visit(MUL_operator_c *symbol) {s4o.print("MUL "); return NULL;} etisserant@0: void *visit(DIV_operator_c *symbol) {s4o.print("DIV "); return NULL;} etisserant@0: void *visit(MOD_operator_c *symbol) {s4o.print("MOD "); return NULL;} etisserant@0: void *visit(GT_operator_c *symbol) {s4o.print("GT "); return NULL;} etisserant@0: void *visit(GE_operator_c *symbol) {s4o.print("GE "); return NULL;} etisserant@0: void *visit(EQ_operator_c *symbol) {s4o.print("EQ "); return NULL;} etisserant@0: void *visit(LT_operator_c *symbol) {s4o.print("LT "); return NULL;} etisserant@0: void *visit(LE_operator_c *symbol) {s4o.print("LE "); return NULL;} etisserant@0: void *visit(NE_operator_c *symbol) {s4o.print("NE "); return NULL;} etisserant@0: void *visit(CAL_operator_c *symbol) {s4o.print("CAL "); return NULL;} etisserant@0: void *visit(CALC_operator_c *symbol) {s4o.print("CALC "); return NULL;} etisserant@0: void *visit(CALCN_operator_c *symbol) {s4o.print("CALCN "); return NULL;} etisserant@0: void *visit(RET_operator_c *symbol) {s4o.print("RET "); return NULL;} etisserant@0: void *visit(RETC_operator_c *symbol) {s4o.print("RETC "); return NULL;} etisserant@0: void *visit(RETCN_operator_c *symbol) {s4o.print("RETCN "); return NULL;} etisserant@0: void *visit(JMP_operator_c *symbol) {s4o.print("JMP "); return NULL;} etisserant@0: void *visit(JMPC_operator_c *symbol) {s4o.print("JMPC "); return NULL;} etisserant@0: void *visit(JMPCN_operator_c *symbol) {s4o.print("JMPCN "); return NULL;} etisserant@0: lbessard@143: /*| any_identifier ASSIGN */ lbessard@143: void *visit(il_assign_operator_c *symbol) { lbessard@143: symbol->variable_name->accept(*this); lbessard@143: s4o.print(" := "); lbessard@143: return NULL; lbessard@143: } lbessard@143: etisserant@0: /*| [NOT] any_identifier SENDTO */ etisserant@0: void *visit(il_assign_out_operator_c *symbol) { etisserant@0: if (symbol->option != NULL) etisserant@0: symbol->option->accept(*this); etisserant@0: symbol->variable_name->accept(*this); etisserant@0: s4o.print(" => "); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /***********************/ etisserant@0: /* B 3.1 - Expressions */ etisserant@0: /***********************/ etisserant@0: void *visit(or_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " OR ");} etisserant@0: void *visit(xor_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " XOR ");} etisserant@0: void *visit(and_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " AND ");} etisserant@0: void *visit(equ_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " = ");} etisserant@0: void *visit(notequ_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " <> ");} etisserant@0: void *visit(lt_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " < ");} etisserant@0: void *visit(gt_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " > ");} etisserant@0: void *visit(le_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " <= ");} etisserant@0: void *visit(ge_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " >= ");} etisserant@0: void *visit(add_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " + ");} etisserant@0: void *visit(sub_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " - ");} etisserant@0: void *visit(mul_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " * ");} etisserant@0: void *visit(div_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " / ");} etisserant@0: void *visit(mod_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " MOD ");} etisserant@0: void *visit(power_expression_c *symbol) {return print_binary_expression(symbol->l_exp, symbol->r_exp, " ** ");} etisserant@0: void *visit(neg_expression_c *symbol) {return print_unary_expression(symbol->exp, "-");} etisserant@0: void *visit(not_expression_c *symbol) {return print_unary_expression(symbol->exp, "NOT ");} etisserant@0: etisserant@0: void *visit(function_invocation_c *symbol) { etisserant@0: symbol->function_name->accept(*this); etisserant@0: s4o.print("("); etisserant@0: symbol->parameter_assignment_list->accept(*this); etisserant@0: s4o.print(")"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /********************/ etisserant@0: /* B 3.2 Statements */ etisserant@0: /********************/ etisserant@0: void *visit(statement_list_c *symbol) { etisserant@0: return print_list(symbol, s4o.indent_spaces, ";\n" + s4o.indent_spaces, ";\n"); etisserant@0: } etisserant@0: etisserant@0: /*********************************/ etisserant@0: /* B 3.2.1 Assignment Statements */ etisserant@0: /*********************************/ etisserant@0: void *visit( assignment_statement_c *symbol) { etisserant@0: symbol->l_exp->accept(*this); etisserant@0: s4o.print(" := "); etisserant@0: symbol->r_exp->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /*****************************************/ etisserant@0: /* B 3.2.2 Subprogram Control Statements */ etisserant@0: /*****************************************/ lbessard@143: etisserant@0: /* RETURN */ etisserant@0: void *visit(return_statement_c *symbol) { etisserant@0: s4o.print("RETURN"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* fb_name '(' [param_assignment_list] ')' */ etisserant@0: void *visit(fb_invocation_c *symbol) { etisserant@0: symbol->fb_name->accept(*this); etisserant@0: s4o.print("("); etisserant@0: if (symbol->param_assignment_list != NULL) etisserant@0: symbol->param_assignment_list->accept(*this); etisserant@0: s4o.print(")"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /* helper symbol for fb_invocation */ etisserant@0: /* param_assignment_list ',' param_assignment */ etisserant@0: void *visit(param_assignment_list_c *symbol) {return print_list(symbol, "", ", ");} etisserant@0: etisserant@0: etisserant@0: void *visit(input_variable_param_assignment_c *symbol) { etisserant@0: symbol->variable_name->accept(*this); etisserant@0: s4o.print(" := "); etisserant@0: symbol->expression->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void *visit(output_variable_param_assignment_c *symbol) { etisserant@0: if (symbol->not_param != NULL) etisserant@0: symbol->not_param->accept(*this); etisserant@0: symbol->variable_name->accept(*this); etisserant@0: s4o.print(" => "); etisserant@0: symbol->variable->accept(*this); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: void *visit(not_paramassign_c *symbol) { etisserant@0: s4o.print("NOT "); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: /********************************/ etisserant@0: /* B 3.2.3 Selection Statements */ etisserant@0: /********************************/ etisserant@0: void *visit(if_statement_c *symbol) { etisserant@0: s4o.print("IF "); etisserant@0: symbol->expression->accept(*this); etisserant@0: s4o.print(" THEN\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: symbol->elseif_statement_list->accept(*this); etisserant@0: etisserant@0: if (symbol->else_statement_list != NULL) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("ELSE\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->else_statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: } etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_IF"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for if_statement */ etisserant@0: void *visit(elseif_statement_list_c *symbol) {return print_list(symbol);} etisserant@0: etisserant@0: /* helper symbol for elseif_statement_list */ etisserant@0: void *visit(elseif_statement_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("ELSIF "); etisserant@0: symbol->expression->accept(*this); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("THEN\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(case_statement_c *symbol) { etisserant@0: s4o.print("CASE "); etisserant@0: symbol->expression->accept(*this); etisserant@0: s4o.print(" OF\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->case_element_list->accept(*this); etisserant@0: if (symbol->statement_list != NULL) { etisserant@0: s4o.print(s4o.indent_spaces + "ELSE\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: } etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces + "END_CASE"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: /* helper symbol for case_statement */ etisserant@0: void *visit(case_element_list_c *symbol) { etisserant@0: return print_list(symbol); etisserant@0: } etisserant@0: etisserant@0: void *visit(case_element_c *symbol) { etisserant@0: s4o.print(s4o.indent_spaces); etisserant@0: symbol->case_list->accept(*this); etisserant@0: s4o.print(":\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(case_list_c *symbol) {return print_list(symbol, "", ", ");} etisserant@0: etisserant@0: /********************************/ etisserant@0: /* B 3.2.4 Iteration Statements */ etisserant@0: /********************************/ etisserant@0: void *visit(for_statement_c *symbol) { etisserant@0: s4o.print("FOR "); etisserant@0: symbol->control_variable->accept(*this); etisserant@0: s4o.print(" := "); etisserant@0: symbol->beg_expression->accept(*this); etisserant@0: s4o.print(" TO "); etisserant@0: symbol->end_expression->accept(*this); etisserant@0: if (symbol->by_expression != NULL) { etisserant@0: s4o.print(" BY "); etisserant@0: symbol->by_expression->accept(*this); etisserant@0: } etisserant@0: s4o.print(" DO\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_FOR"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(while_statement_c *symbol) { etisserant@0: s4o.print("WHILE "); etisserant@0: symbol->expression->accept(*this); etisserant@0: s4o.print(" DO\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("END_WHILE"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(repeat_statement_c *symbol) { etisserant@0: s4o.print("REPEAT\n"); etisserant@0: s4o.indent_right(); etisserant@0: symbol->statement_list->accept(*this); etisserant@0: s4o.indent_left(); etisserant@0: s4o.print(s4o.indent_spaces); s4o.print("UNTIL "); etisserant@0: symbol->expression->accept(*this); etisserant@0: s4o.print("\n" + s4o.indent_spaces + "END_REPEAT"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: void *visit(exit_statement_c *symbol) { etisserant@0: s4o.print("EXIT"); etisserant@0: return NULL; etisserant@0: } etisserant@0: etisserant@0: etisserant@0: }; /* class generate_iec_c */ etisserant@0: etisserant@0: etisserant@0: etisserant@0: /***********************************************************************/ etisserant@0: /***********************************************************************/ etisserant@0: /***********************************************************************/ etisserant@0: /***********************************************************************/ etisserant@0: /***********************************************************************/ etisserant@0: /***********************************************************************/ etisserant@0: /***********************************************************************/ etisserant@0: /***********************************************************************/ etisserant@0: etisserant@0: etisserant@0: etisserant@0: lbessard@46: visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir) {return new generate_iec_c(s4o);} etisserant@0: void delete_code_generator(visitor_c *code_generator) {delete code_generator;} etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: etisserant@0: