stage4/generate_iec/generate_iec.cc
changeset 10 66f4f7f85d0a
parent 8 89902a42698e
child 16 e8b99f896416
equal deleted inserted replaced
9:ebd07483c099 10:66f4f7f85d0a
   907 
   907 
   908 
   908 
   909 /*  AT incompl_location_token */
   909 /*  AT incompl_location_token */
   910 void *visit(incompl_location_c *symbol) {
   910 void *visit(incompl_location_c *symbol) {
   911   s4o.print(" AT ");
   911   s4o.print(" AT ");
   912   return print_token(symbol);;
   912   return print_token(symbol);
   913 }
   913 }
   914 
   914 
   915 
   915 
   916 /* intermediate helper symbol for:
   916 /* intermediate helper symbol for:
   917  *  - non_retentive_var_decls
   917  *  - non_retentive_var_decls
  1011 void *visit(program_declaration_c *symbol) {
  1011 void *visit(program_declaration_c *symbol) {
  1012   s4o.print("PROGRAM ");
  1012   s4o.print("PROGRAM ");
  1013   symbol->program_type_name->accept(*this);
  1013   symbol->program_type_name->accept(*this);
  1014   s4o.print("\n");
  1014   s4o.print("\n");
  1015   s4o.indent_right();
  1015   s4o.indent_right();
  1016   s4o.print(s4o.indent_spaces);
       
  1017   symbol->var_declarations->accept(*this);
  1016   symbol->var_declarations->accept(*this);
  1018   s4o.print("\n");
  1017   s4o.print("\n");
  1019   symbol->function_block_body->accept(*this);
  1018   symbol->function_block_body->accept(*this);
  1020   s4o.indent_left();
  1019   s4o.indent_left();
  1021   s4o.print("\n");
       
  1022   s4o.print("END_PROGRAM\n\n\n");
  1020   s4o.print("END_PROGRAM\n\n\n");
  1023   return NULL;
  1021   return NULL;
  1024 }
  1022 }
  1025 
  1023 
  1026 /***********************************/
  1024 /***********************************/
  1027 /* B 1.6 Sequential Function Chart */
  1025 /* B 1.6 Sequential Function Chart */
  1028 /***********************************/
  1026 /***********************************/
  1029 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1030 
       
  1031 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1032 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1033 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1034 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1035 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1036 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1037 
       
  1038 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
       
  1039 
       
  1040 
       
  1041 
       
  1042 
  1027 
  1043 /* sequential_function_chart {sfc_network} */
  1028 /* sequential_function_chart {sfc_network} */
  1044 void *visit(sequential_function_chart_c *symbol) {
  1029 void *visit(sequential_function_chart_c *symbol) {
  1045   print_list(symbol, "", "\n\n", "");
  1030   print_list(symbol, "", "\n", "");
  1046   return NULL;
  1031   return NULL;
  1047 }
  1032 }
  1048 
  1033 
  1049 /* sfc_network {step | transition | action} */
  1034 /* sfc_network {step | transition | action} */
  1050 void *visit(sfc_network_c *symbol) {
  1035 void *visit(sfc_network_c *symbol) {
  1051   print_list(symbol, "", "\n\n", "");
  1036   print_list(symbol, "", "\n", "");
  1052   return NULL;
  1037   return NULL;
  1053 }
  1038 }
  1054 
  1039 
  1055 /* INITIAL_STEP step_name ':' [action_association_list] END_STEP */
  1040 /* INITIAL_STEP step_name ':' [action_association_list] END_STEP */
  1056 void *visit(initial_step_c *symbol) {
  1041 void *visit(initial_step_c *symbol) {
  1057   s4o.print(s4o.indent_spaces);
  1042   s4o.print(s4o.indent_spaces);
  1058   s4o.print("INITIAL_STEP ");
  1043   s4o.print("INITIAL_STEP ");
  1059   symbol->step_name->accept(*this);
  1044   symbol->step_name->accept(*this);
  1060   s4o.print(" :\n");
  1045   s4o.print(":\n");
  1061   s4o.indent_right();
  1046   s4o.indent_right();
  1062   symbol->action_association_list->accept(*this);
  1047   symbol->action_association_list->accept(*this);
  1063   s4o.print("\n");
  1048   s4o.print("\n");
  1064   s4o.indent_left();
  1049   s4o.indent_left();
  1065   s4o.print(s4o.indent_spaces);
  1050   s4o.print(s4o.indent_spaces);
  1066   s4o.print("END_STEP ");
  1051   s4o.print("END_STEP\n");
  1067   return NULL;
  1052   return NULL;
  1068 }
  1053 }
  1069 
  1054 
  1070 /* STEP step_name ':' [action_association_list] END_STEP */
  1055 /* STEP step_name ':' [action_association_list] END_STEP */
  1071 void *visit(step_c *symbol) {
  1056 void *visit(step_c *symbol) {
  1072   s4o.print(s4o.indent_spaces);
  1057   s4o.print(s4o.indent_spaces);
  1073   s4o.print("STEP ");
  1058   s4o.print("STEP ");
  1074   symbol->step_name->accept(*this);
  1059   symbol->step_name->accept(*this);
  1075   s4o.print(" :\n");
  1060   s4o.print(":\n");
  1076   s4o.indent_right();
  1061   s4o.indent_right();
  1077   symbol->action_association_list->accept(*this);
  1062   symbol->action_association_list->accept(*this);
  1078   s4o.print("\n");
  1063   s4o.print("\n");
  1079   s4o.indent_left();
  1064   s4o.indent_left();
  1080   s4o.print(s4o.indent_spaces);
  1065   s4o.print(s4o.indent_spaces);
  1081   s4o.print("END_STEP ");
  1066   s4o.print("END_STEP\n");
  1082   return NULL;
  1067   return NULL;
  1083 }
  1068 }
  1084 
  1069 
  1085 /* action_association_list {action_association} */
  1070 /* action_association_list {action_association} */
  1086 void *visit(action_association_list_c *symbol) {
  1071 void *visit(action_association_list_c *symbol) {
  1088   return NULL;
  1073   return NULL;
  1089 }
  1074 }
  1090 
  1075 
  1091 /* action_name '(' [action_qualifier] [indicator_name_list] ')' */
  1076 /* action_name '(' [action_qualifier] [indicator_name_list] ')' */
  1092 void *visit(action_association_c *symbol) {
  1077 void *visit(action_association_c *symbol) {
  1093   if(symbol->action_qualifier != NULL){
  1078   s4o.print(s4o.indent_spaces);
  1094     symbol->action_name->accept(*this);
  1079   symbol->action_name->accept(*this);
  1095   }
  1080   s4o.print("(");
  1096   s4o.print(" (");
       
  1097   if(symbol->action_qualifier != NULL){
  1081   if(symbol->action_qualifier != NULL){
  1098     symbol->action_qualifier->accept(*this);
  1082     symbol->action_qualifier->accept(*this);
  1099   }
  1083   }
  1100   s4o.print(" ");
       
  1101   if(symbol->indicator_name_list != NULL){
  1084   if(symbol->indicator_name_list != NULL){
  1102     symbol->indicator_name_list->accept(*this);
  1085   	symbol->indicator_name_list->accept(*this);
  1103   }
  1086   }
  1104   s4o.print(" )");
  1087   s4o.print(");");
  1105   return NULL;
  1088   return NULL;
  1106 }
  1089 }
  1107 
  1090 
  1108 /* indicator_name_list ',' indicator_name */
  1091 /* indicator_name_list ',' indicator_name */
  1109 void *visit(indicator_name_list_c *symbol) {
  1092 void *visit(indicator_name_list_c *symbol) {
  1110   print_list(symbol, "", ", ", "");
  1093   print_list(symbol, ", ", ", ", "");
  1111   return NULL;
  1094   return NULL;
  1112 }
  1095 }
  1113 
  1096 
  1114 /* action_qualifier [',' action_time] */
  1097 /* action_qualifier [',' action_time] */
  1115 void *visit(action_qualifier_c *symbol) {
  1098 void *visit(action_qualifier_c *symbol) {
  1121   return NULL;
  1104   return NULL;
  1122 }
  1105 }
  1123 
  1106 
  1124 /* N | R | S | P */
  1107 /* N | R | S | P */
  1125 void *visit(qualifier_c *symbol) {
  1108 void *visit(qualifier_c *symbol) {
  1126   symbol->accept(*this);
  1109   print_token(symbol);
  1127   return NULL;
  1110   return NULL;
  1128 }
  1111 }
  1129 
  1112 
  1130 /* L | D | SD | DS | SL */
  1113 /* L | D | SD | DS | SL */
  1131 void *visit(timed_qualifier_c *symbol) {
  1114 void *visit(timed_qualifier_c *symbol) {
  1132   symbol->accept(*this);
  1115   print_token(symbol);
  1133   return NULL;
  1116   return NULL;
  1134 }
  1117 }
  1135 
  1118 
  1136 /* TRANSITION [transition_name] ['(' 'PRIORITY' ':=' integer ')']
  1119 /* TRANSITION [transition_name] ['(' 'PRIORITY' ':=' integer ')']
  1137  *   FROM steps TO steps 
  1120  *   FROM steps TO steps 
  1150     symbol->integer->accept(*this);
  1133     symbol->integer->accept(*this);
  1151     s4o.print(") ");
  1134     s4o.print(") ");
  1152   }
  1135   }
  1153   s4o.print("FROM ");
  1136   s4o.print("FROM ");
  1154   symbol->from_steps->accept(*this);
  1137   symbol->from_steps->accept(*this);
  1155   s4o.print("TO ");
  1138   s4o.print(" TO ");
  1156   symbol->to_steps->accept(*this);
  1139   symbol->to_steps->accept(*this);
  1157   s4o.indent_right();
  1140   s4o.indent_right();
  1158   s4o.print(s4o.indent_spaces);
       
  1159   if (symbol->transition_condition_il != NULL) {
  1141   if (symbol->transition_condition_il != NULL) {
  1160   	symbol->transition_condition_il->accept(*this);
  1142   	symbol->transition_condition_il->accept(*this);
  1161   }
  1143   }
  1162   if (symbol->transition_condition_st != NULL) {
  1144   if (symbol->transition_condition_st != NULL) {
  1163   	symbol->transition_condition_st->accept(*this);
  1145   	symbol->transition_condition_st->accept(*this);
  1164   }
  1146   }
  1165   s4o.indent_left();
  1147   s4o.indent_left();
  1166   s4o.print(s4o.indent_spaces);
  1148   s4o.print(s4o.indent_spaces);
  1167   s4o.print("END_TRANSITION");
  1149   s4o.print("END_TRANSITION\n");
  1168   return NULL;
  1150   return NULL;
  1169 }
  1151 }
  1170 
  1152 
  1171 /* step_name | step_name_list */
  1153 /* step_name | step_name_list */
  1172 void *visit(steps_c *symbol) {
  1154 void *visit(steps_c *symbol) {
  1173   if(symbol->step_name != NULL){
  1155   if(symbol->step_name != NULL){
  1174     symbol->step_name->accept(*this);
  1156     symbol->step_name->accept(*this);
  1175     s4o.print(" ");
       
  1176   }
  1157   }
  1177   if(symbol->step_name_list != NULL){
  1158   if(symbol->step_name_list != NULL){
  1178     symbol->step_name_list->accept(*this);
  1159     symbol->step_name_list->accept(*this);
  1179   }
  1160   }
  1180   return NULL;
  1161   return NULL;
  1187 }
  1168 }
  1188 
  1169 
  1189 /* ':' simple_instr_list | ':=' expression */
  1170 /* ':' simple_instr_list | ':=' expression */
  1190 void *visit(transition_condition_c *symbol) {
  1171 void *visit(transition_condition_c *symbol) {
  1191   if (symbol->simple_instr_list != NULL) {
  1172   if (symbol->simple_instr_list != NULL) {
  1192     s4o.print(s4o.indent_spaces);
       
  1193     s4o.print(":\n");
  1173     s4o.print(":\n");
  1194     symbol->simple_instr_list->accept(*this);
  1174     symbol->simple_instr_list->accept(*this);
  1195   }
  1175   }
  1196   if (symbol->expression != NULL) {
  1176   if (symbol->expression != NULL) {
  1197     s4o.print("\n");
  1177     s4o.print("\n");
  1206 /* ACTION action_name ':' function_block_body END_ACTION */
  1186 /* ACTION action_name ':' function_block_body END_ACTION */
  1207 void *visit(action_c *symbol) {
  1187 void *visit(action_c *symbol) {
  1208   s4o.print(s4o.indent_spaces);
  1188   s4o.print(s4o.indent_spaces);
  1209   s4o.print("ACTION ");
  1189   s4o.print("ACTION ");
  1210   symbol->action_name->accept(*this);
  1190   symbol->action_name->accept(*this);
  1211   s4o.print(": ");
  1191   s4o.print(":\n");
  1212   s4o.indent_right();
  1192   s4o.indent_right();
       
  1193   symbol->function_block_body->accept(*this);
       
  1194   s4o.indent_left();
  1213   s4o.print(s4o.indent_spaces);
  1195   s4o.print(s4o.indent_spaces);
  1214   symbol->function_block_body->accept(*this);
  1196   s4o.print("END_ACTION\n");
  1215   s4o.print("\n ");
       
  1216   s4o.indent_left();
       
  1217   s4o.print(s4o.indent_spaces);
       
  1218   s4o.print("END_ACTION");
       
  1219   return NULL;
  1197   return NULL;
  1220 }
  1198 }
  1221  
  1199  
  1222  
  1200  
  1223  
  1201  
  1496     symbol->il_operand->accept(*this);
  1474     symbol->il_operand->accept(*this);
  1497   if (symbol->simple_instr_list != NULL) {
  1475   if (symbol->simple_instr_list != NULL) {
  1498     s4o.print("\n");
  1476     s4o.print("\n");
  1499     s4o.indent_right();
  1477     s4o.indent_right();
  1500     symbol->simple_instr_list->accept(*this);
  1478     symbol->simple_instr_list->accept(*this);
       
  1479     s4o.print(s4o.indent_spaces);
  1501     s4o.indent_left();
  1480     s4o.indent_left();
  1502   }
  1481   }
  1503   s4o.print(")");
  1482   s4o.print(")");
  1504   return NULL;
  1483   return NULL;
  1505 }
  1484 }
  1551 /* | il_operand_list ',' il_operand */
  1530 /* | il_operand_list ',' il_operand */
  1552 void *visit(il_operand_list_c *symbol) {return print_list(symbol, "", ", ");}
  1531 void *visit(il_operand_list_c *symbol) {return print_list(symbol, "", ", ");}
  1553 
  1532 
  1554 /* | simple_instr_list il_simple_instruction */
  1533 /* | simple_instr_list il_simple_instruction */
  1555 void *visit(simple_instr_list_c *symbol) {
  1534 void *visit(simple_instr_list_c *symbol) {
  1556   return print_list(symbol,  s4o.indent_spaces, "\n" + s4o.indent_spaces, "\n" + s4o.indent_spaces);
  1535   return print_list(symbol,  s4o.indent_spaces, "\n" + s4o.indent_spaces, "\n");
  1557 }
  1536 }
  1558 
  1537 
  1559 /* | il_initial_param_list il_param_instruction */
  1538 /* | il_initial_param_list il_param_instruction */
  1560 void *visit(il_param_list_c *symbol) {return print_list(symbol);}
  1539 void *visit(il_param_list_c *symbol) {return print_list(symbol);}
  1561 
  1540 
  1569     symbol->il_operand->accept(*this);
  1548     symbol->il_operand->accept(*this);
  1570   if (symbol->simple_instr_list != NULL) {
  1549   if (symbol->simple_instr_list != NULL) {
  1571     s4o.print("(\n");
  1550     s4o.print("(\n");
  1572     s4o.indent_right();
  1551     s4o.indent_right();
  1573     symbol->simple_instr_list->accept(*this);
  1552     symbol->simple_instr_list->accept(*this);
       
  1553     s4o.print(s4o.indent_spaces);
  1574     s4o.indent_left();
  1554     s4o.indent_left();
  1575     s4o.print(")");
  1555     s4o.print(")");
  1576   }
  1556   }
  1577   return NULL;
  1557   return NULL;
  1578 }
  1558 }