stage1_2/iec_bison.yy
changeset 547 dab341e80664
parent 520 fb381d2cd25b
child 584 f95d6561d439
equal deleted inserted replaced
546:8cc4c51c4bfc 547:dab341e80664
    55 /*******                                                        *******/
    55 /*******                                                        *******/
    56 /**********************************************************************/
    56 /**********************************************************************/
    57 /**********************************************************************/
    57 /**********************************************************************/
    58 /**********************************************************************/
    58 /**********************************************************************/
    59 /**********************************************************************/
    59 /**********************************************************************/
       
    60 
       
    61 /* NOTE: the following file contains many rules used merely for detecting errors in
       
    62  * the IEC source code being parsed.
       
    63  * To remove all these rules, simply execute the command (first replace all '%' with '/'):
       
    64  * $sed '\:%\* ERROR_CHECK_BEGIN \*%:,\:%\* ERROR_CHECK_END \*%: d' iec_bison.yy
       
    65  *
       
    66  * The above command had to be edited ('/' replaced by '%') so as not to include the C syntax that closes
       
    67  * comments inside this comment!
       
    68  * If you place the command in a shell script, be sure to remove the backslashes '\' before each asterisk '*' !!
       
    69  */
       
    70 
    60 
    71 
    61 
    72 
    62 
    73 
    63 
    74 
    64 %{
    75 %{
   488 %type  <leaf>	hours
   499 %type  <leaf>	hours
   489 %type  <leaf>	minutes
   500 %type  <leaf>	minutes
   490 %type  <leaf>	seconds
   501 %type  <leaf>	seconds
   491 %type  <leaf>	milliseconds
   502 %type  <leaf>	milliseconds
   492 
   503 
   493 %type  <leaf>	integer_d
       
   494 %type  <leaf>	integer_h
       
   495 %type  <leaf>	integer_m
       
   496 %type  <leaf>	integer_s
       
   497 %type  <leaf>	integer_ms
       
   498 %type  <leaf>	fixed_point_d
       
   499 %type  <leaf>	fixed_point_h
       
   500 %type  <leaf>	fixed_point_m
       
   501 %type  <leaf>	fixed_point_s
       
   502 %type  <leaf>	fixed_point_ms
       
   503 
       
   504 %token <ID>	fixed_point_token
   504 %token <ID>	fixed_point_token
   505 %token <ID>	fixed_point_d_token
   505 %token <ID>	fixed_point_d_token
   506 %token <ID>	integer_d_token
   506 %token <ID>	integer_d_token
   507 %token <ID>	fixed_point_h_token
   507 %token <ID>	fixed_point_h_token
   508 %token <ID>	integer_h_token
   508 %token <ID>	integer_h_token
   510 %token <ID>	integer_m_token
   510 %token <ID>	integer_m_token
   511 %token <ID>	fixed_point_s_token
   511 %token <ID>	fixed_point_s_token
   512 %token <ID>	integer_s_token
   512 %token <ID>	integer_s_token
   513 %token <ID>	fixed_point_ms_token
   513 %token <ID>	fixed_point_ms_token
   514 %token <ID>	integer_ms_token
   514 %token <ID>	integer_ms_token
   515 
   515 %token <ID>	end_interval_token
       
   516 %token <ID>	erroneous_interval_token
   516 // %token TIME
   517 // %token TIME
   517 %token T_SHARP
   518 %token T_SHARP
   518 
   519 
   519 
   520 
   520 /************************************/
   521 /************************************/
  2136 /* ERROR_CHECK_BEGIN */
  2137 /* ERROR_CHECK_BEGIN */
  2137 | TIME interval
  2138 | TIME interval
  2138 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2139 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2139 | TIME '-' interval
  2140 | TIME '-' interval
  2140 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2141 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2141 | TIME '#' error
  2142 | TIME '#' erroneous_interval_token
  2142 	{$$ = NULL;
  2143 	{$$ = NULL; print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yynerrs++;}
  2143 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for duration.");}
  2144 | T_SHARP erroneous_interval_token
  2144 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yyclearin;}
  2145 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yynerrs++;}
  2145 	 yyerrok;
  2146 | TIME '#' '-' erroneous_interval_token
  2146 	}
  2147 	{$$ = NULL; print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yynerrs++;}
  2147 | T_SHARP error
  2148 | T_SHARP '-' erroneous_interval_token
  2148 	{$$ = NULL;
  2149 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yynerrs++;}
  2149 	 if (is_current_syntax_token()) {print_err_msg(locl(@1), locf(@2), "no value defined for duration.");}
  2150 /* ERROR_CHECK_END */
  2150 	 else {print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yyclearin;}
  2151 ;
  2151 	 yyerrok;
  2152 
  2152 	}
  2153 fixed_point:
  2153 /* ERROR_CHECK_END */
  2154   integer
  2154 ;
  2155 | fixed_point_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2155 
  2156 
  2156 
  2157 
  2157 interval:
  2158 interval:
  2158   days
  2159   days hours minutes seconds milliseconds end_interval_token
  2159 | hours
  2160 	{$$ = new interval_c($1, $2, $3, $4, $5, locloc(@$));};
  2160 | minutes
  2161 ;
  2161 | seconds
  2162 
  2162 | milliseconds
  2163 
  2163 ;
  2164 days:   /*  fixed_point ('d') */
  2164 
  2165   /* empty */		{$$ = NULL;}
  2165 integer_d:  integer_d_token  {$$ = new integer_c($1, locloc(@$));};
  2166 | fixed_point_d_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2166 integer_h:  integer_h_token  {$$ = new integer_c($1, locloc(@$));};
  2167 | integer_d_token	{$$ = new integer_c($1, locloc(@$));};
  2167 integer_m:  integer_m_token  {$$ = new integer_c($1, locloc(@$));};
  2168 ;
  2168 integer_s:  integer_s_token  {$$ = new integer_c($1, locloc(@$));};
  2169 
  2169 integer_ms: integer_ms_token {$$ = new integer_c($1, locloc(@$));};
  2170 hours:  /*  fixed_point ('h') */
  2170 
  2171   /* empty */		{$$ = NULL;}
  2171 fixed_point_d:
  2172 | fixed_point_h_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2172   fixed_point_d_token
  2173 | integer_h_token	{$$ = new integer_c($1, locloc(@$));};
  2173 	{$$ = new fixed_point_c($1, locloc(@$));}
  2174 ;
  2174 | integer_d
  2175 
  2175 ;
  2176 minutes: /*  fixed_point ('m') */
  2176 
  2177   /* empty */		{$$ = NULL;}
  2177 fixed_point_h:
  2178 | fixed_point_m_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2178   fixed_point_h_token
  2179 | integer_m_token	{$$ = new integer_c($1, locloc(@$));};
  2179 	{$$ = new fixed_point_c($1, locloc(@$));}
  2180 ;
  2180 | integer_h
  2181 
  2181 ;
  2182 seconds: /*  fixed_point ('s') */
  2182 
  2183   /* empty */		{$$ = NULL;}
  2183 fixed_point_m:
  2184 | fixed_point_s_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2184   fixed_point_m_token
  2185 | integer_s_token	{$$ = new integer_c($1, locloc(@$));};
  2185 	{$$ = new fixed_point_c($1, locloc(@$));}
  2186 ;
  2186 | integer_m
  2187 
  2187 ;
  2188 milliseconds: /*  fixed_point ('ms') */
  2188 
  2189   /* empty */		{$$ = NULL;}
  2189 fixed_point_s:
  2190 | fixed_point_ms_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2190   fixed_point_s_token
  2191 | integer_ms_token	{$$ = new integer_c($1, locloc(@$));};
  2191 	{$$ = new fixed_point_c($1, locloc(@$));}
       
  2192 | integer_s
       
  2193 ;
       
  2194 
       
  2195 fixed_point_ms:
       
  2196   fixed_point_ms_token
       
  2197 	{$$ = new fixed_point_c($1, locloc(@$));}
       
  2198 | integer_ms
       
  2199 ;
       
  2200 
       
  2201 
       
  2202 fixed_point:
       
  2203   fixed_point_token
       
  2204 	{$$ = new fixed_point_c($1, locloc(@$));}
       
  2205 | integer
       
  2206 ;
       
  2207 
       
  2208 
       
  2209 days:
       
  2210 /*  fixed_point ('d') */
       
  2211   fixed_point_d
       
  2212 	{$$ = new days_c($1, NULL, locloc(@$));}
       
  2213 /*| integer ('d') ['_'] hours */
       
  2214 | integer_d hours
       
  2215 	{$$ = new days_c($1, $2, locloc(@$));}
       
  2216 | integer_d '_' hours
       
  2217 	{$$ = new days_c($1, $3, locloc(@$));}
       
  2218 /* ERROR_CHECK_BEGIN */
       
  2219 | integer_d '_' error
       
  2220 	{$$ = NULL;
       
  2221 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for hours in duration.");}
       
  2222 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for hours in duration."); yyclearin;}
       
  2223 	 yyerrok;
       
  2224 	}
       
  2225 /* ERROR_CHECK_END */
       
  2226 ;
       
  2227 
       
  2228 
       
  2229 hours:
       
  2230 /*  fixed_point ('h') */
       
  2231   fixed_point_h
       
  2232 	{$$ = new hours_c($1, NULL, locloc(@$));}
       
  2233 /*| integer ('h') ['_'] minutes */
       
  2234 | integer_h minutes
       
  2235 	{$$ = new hours_c($1, $2, locloc(@$));}
       
  2236 | integer_h '_' minutes
       
  2237 	{$$ = new hours_c($1, $3, locloc(@$));}
       
  2238 /* ERROR_CHECK_BEGIN */
       
  2239 | integer_h '_' error
       
  2240 	{$$ = NULL;
       
  2241 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for minutes in duration.");}
       
  2242 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for minutes in duration."); yyclearin;}
       
  2243 	 yyerrok;
       
  2244 	}
       
  2245 /* ERROR_CHECK_END */
       
  2246 
       
  2247 ;
       
  2248 
       
  2249 minutes:
       
  2250 /*  fixed_point ('m') */
       
  2251   fixed_point_m
       
  2252 	{$$ = new minutes_c($1, NULL, locloc(@$));}
       
  2253 /*| integer ('m') ['_'] seconds */
       
  2254 | integer_m seconds
       
  2255 	{$$ = new minutes_c($1, $2, locloc(@$));}
       
  2256 | integer_m '_' seconds
       
  2257 	{$$ = new minutes_c($1, $3, locloc(@$));}
       
  2258 /* ERROR_CHECK_BEGIN */
       
  2259 | integer_m '_' error
       
  2260 	{$$ = NULL;
       
  2261 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for seconds in duration.");}
       
  2262 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for seconds in duration."); yyclearin;}
       
  2263 	 yyerrok;
       
  2264 	}
       
  2265 /* ERROR_CHECK_END */
       
  2266 ;
       
  2267 
       
  2268 seconds:
       
  2269 /*  fixed_point ('s') */
       
  2270   fixed_point_s
       
  2271 	{$$ = new seconds_c($1, NULL, locloc(@$));}
       
  2272 /*| integer ('s') ['_'] milliseconds */
       
  2273 | integer_s milliseconds
       
  2274 	{$$ = new seconds_c($1, $2, locloc(@$));}
       
  2275 | integer_s '_' milliseconds
       
  2276 	{$$ = new seconds_c($1, $3, locloc(@$));}
       
  2277 /* ERROR_CHECK_BEGIN */
       
  2278 | integer_s '_' error
       
  2279 	{$$ = NULL;
       
  2280 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for milliseconds in duration.");}
       
  2281 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for milliseconds in duration."); yyclearin;}
       
  2282 	 yyerrok;
       
  2283 	}
       
  2284 /* ERROR_CHECK_END */
       
  2285 ;
       
  2286 
       
  2287 milliseconds:
       
  2288 /*  fixed_point ('ms') */
       
  2289   fixed_point_ms
       
  2290 	{$$ = new milliseconds_c($1, locloc(@$));}
       
  2291 ;
  2192 ;
  2292 
  2193 
  2293 
  2194 
  2294 
  2195 
  2295 /************************************/
  2196 /************************************/
  2983 array_initial_elements_list:
  2884 array_initial_elements_list:
  2984   array_initial_elements
  2885   array_initial_elements
  2985 	{$$ = new array_initial_elements_list_c(locloc(@$)); $$->add_element($1);}
  2886 	{$$ = new array_initial_elements_list_c(locloc(@$)); $$->add_element($1);}
  2986 | array_initial_elements_list ',' array_initial_elements
  2887 | array_initial_elements_list ',' array_initial_elements
  2987 	{$$ = $1; $$->add_element($3);}
  2888 	{$$ = $1; $$->add_element($3);}
  2988 /* ERROR_CHECK_BEGIN 
  2889 /* ERROR_CHECK_BEGIN */
       
  2890 /* The following error checking rules have been commented out. Why? Was it a typo? 
       
  2891  * Lets keep them commented out for now...
       
  2892  */
       
  2893 /*
  2989 | array_initial_elements_list ',' error
  2894 | array_initial_elements_list ',' error
  2990 	{$$ = $1;
  2895 	{$$ = $1;
  2991 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no array initial value in array initial values list.");}
  2896 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no array initial value in array initial values list.");}
  2992 	 else {print_err_msg(locf(@3), locl(@3), "invalid array initial value in array initial values list."); yyclearin;}
  2897 	 else {print_err_msg(locf(@3), locl(@3), "invalid array initial value in array initial values list."); yyclearin;}
  2993 	 yyerrok;
  2898 	 yyerrok;
  2994 	}
  2899 	}
       
  2900 */
  2995 /* ERROR_CHECK_END */
  2901 /* ERROR_CHECK_END */
  2996 ;
  2902 ;
  2997 
  2903 
  2998 
  2904 
  2999 array_initial_elements:
  2905 array_initial_elements:
  3143 structure_element_initialization_list:
  3049 structure_element_initialization_list:
  3144   structure_element_initialization
  3050   structure_element_initialization
  3145 	{$$ = new structure_element_initialization_list_c(locloc(@$)); $$->add_element($1);}
  3051 	{$$ = new structure_element_initialization_list_c(locloc(@$)); $$->add_element($1);}
  3146 | structure_element_initialization_list ',' structure_element_initialization
  3052 | structure_element_initialization_list ',' structure_element_initialization
  3147 	{$$ = $1; $$->add_element($3);}
  3053 	{$$ = $1; $$->add_element($3);}
  3148 /* ERROR_CHECK_BEGIN 
  3054 /* ERROR_CHECK_BEGIN */
       
  3055 /* The following error checking rules have been commented out. Why? Was it a typo? 
       
  3056  * Lets keep them commented out for now...
       
  3057  */
       
  3058 /*
  3149 | structure_element_initialization_list structure_element_initialization
  3059 | structure_element_initialization_list structure_element_initialization
  3150 	{$$ = $1; print_err_msg(locl(@1), locf(@2), "',' missing in structure element initialization list in structure initialization."); yynerrs++;}
  3060 	{$$ = $1; print_err_msg(locl(@1), locf(@2), "',' missing in structure element initialization list in structure initialization."); yynerrs++;}
  3151 | structure_element_initialization_list ',' error
  3061 | structure_element_initialization_list ',' error
  3152 	{$$ = $1;
  3062 	{$$ = $1;
  3153 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no structure element initialization defined in structure initialization.");}
  3063 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no structure element initialization defined in structure initialization.");}
  3154 	 else {print_err_msg(locf(@3), locl(@3), "invalid structure element initialization in structure initialization."); yyclearin;}
  3064 	 else {print_err_msg(locf(@3), locl(@3), "invalid structure element initialization in structure initialization."); yyclearin;}
  3155 	 yyerrok;
  3065 	 yyerrok;
  3156 	}
  3066 	}
       
  3067 */
  3157 /* ERROR_CHECK_END */
  3068 /* ERROR_CHECK_END */
  3158 ;
  3069 ;
  3159 
  3070 
  3160 
  3071 
  3161 structure_element_initialization:
  3072 structure_element_initialization:
  5452 transition_priority:
  5363 transition_priority:
  5453   /* empty */
  5364   /* empty */
  5454   {$$ = NULL;}
  5365   {$$ = NULL;}
  5455 | '(' {cmd_goto_sfc_priority_state();} PRIORITY {cmd_pop_state();} ASSIGN integer ')'
  5366 | '(' {cmd_goto_sfc_priority_state();} PRIORITY {cmd_pop_state();} ASSIGN integer ')'
  5456 	{$$ = $6;}
  5367 	{$$ = $6;}
  5457 /* ERROR_CHECK_BEGIN 
  5368 /* ERROR_CHECK_BEGIN */
       
  5369 /* The following error checking rules have been intentionally commented out. */
       
  5370 /*
  5458 | '(' ASSIGN integer ')'
  5371 | '(' ASSIGN integer ')'
  5459 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'PRIORITY' missing between '(' and ':=' in transition declaration with priority."); yynerrs++;}
  5372 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'PRIORITY' missing between '(' and ':=' in transition declaration with priority."); yynerrs++;}
  5460 | '(' error ASSIGN integer ')'
  5373 | '(' error ASSIGN integer ')'
  5461 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "expecting 'PRIORITY' between '(' and ':=' in transition declaration with priority."); yyerrok;}
  5374 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "expecting 'PRIORITY' between '(' and ':=' in transition declaration with priority."); yyerrok;}
  5462  ERROR_CHECK_END */
  5375 */
       
  5376 /* ERROR_CHECK_END */
  5463 ;
  5377 ;
  5464 
  5378 
  5465 
  5379 
  5466 transition_condition:
  5380 transition_condition:
  5467   ':' eol_list simple_instr_list
  5381   ':' eol_list simple_instr_list
  8248     fclose(in_file);
  8162     fclose(in_file);
  8249     return -1;
  8163     return -1;
  8250   }
  8164   }
  8251 
  8165 
  8252   /* first parse the standard library file... */
  8166   /* first parse the standard library file... */
       
  8167   /* Do not debug the standard library, even if debug flag is set! */
  8253   /*
  8168   /*
  8254   #if YYDEBUG
  8169   #if YYDEBUG
  8255     yydebug = 1;
  8170     yydebug = 1;
  8256   #endif
  8171   #endif
  8257   */
  8172   */