stage1_2/iec_bison.yy
changeset 625 c0bda77b37a0
parent 616 0c7663fdc8d3
child 627 e7caa7d32ef5
child 643 1cc0e1ca2aad
equal deleted inserted replaced
412:aad38592bdde 625:c0bda77b37a0
    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 %{
   148                  YYRHSLOC(Rhs, 0).last_order;                                \
   159                  YYRHSLOC(Rhs, 0).last_order;                                \
   149              }                                                               \
   160              }                                                               \
   150          while (0)
   161          while (0)
   151 
   162 
   152 
   163 
   153 /* A macro for printing out internal parser errors... */
   164 #include "../main.hh" // required for ERROR() and ERROR_MSG() macros.
   154 #define ERROR error_exit(__FILE__,__LINE__)
       
   155 /* function defined in main.cc */
       
   156 extern void error_exit(const char *file_name, int line_no);
       
   157 
   165 
   158 
   166 
   159 
   167 
   160 /*************************/
   168 /*************************/
   161 /* global variables...   */
   169 /* global variables...   */
   248  * declaring the typedef struct yyltype__local here would result in a 
   256  * declaring the typedef struct yyltype__local here would result in a 
   249  * compilation error when compiling iec.cc, as this struct would be
   257  * compilation error when compiling iec.cc, as this struct would be
   250  * declared twice.
   258  * declared twice.
   251  * We therefore use the #if !defined YYLTYPE ...
   259  * We therefore use the #if !defined YYLTYPE ...
   252  * to make sure only the first declaration is parsed by the C++ compiler.
   260  * to make sure only the first declaration is parsed by the C++ compiler.
   253  *
       
   254  * At first glance it seems that what we really should do is delcare the
       
   255  * YYLTYPE directly as an anonymous struct, thus:
       
   256  * #define YYLTYPE struct{ ...}
       
   257  * however, this also results in compilation errors.
       
   258  *
       
   259  * I (Mario) think this is kind of a hack. If you know how to
       
   260  * do this re-declaration of YYLTYPE properly, please let me know!
       
   261  */
   261  */
   262 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
   262 #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
   263   typedef struct {
   263 typedef struct YYLTYPE {
   264     int         first_line;
   264     int         first_line;
   265     int         first_column;
   265     int         first_column;
   266     const char *first_file;
   266     const char *first_file;
   267     long int    first_order;
   267     long int    first_order;
   268     int         last_line;
   268     int         last_line;
   269     int         last_column;
   269     int         last_column;
   270     const char *last_file;
   270     const char *last_file;
   271     long int    last_order;
   271     long int    last_order;
   272   } yyltype__local;
   272 } YYLTYPE;
   273   #define YYLTYPE yyltype__local
   273 #define YYLTYPE_IS_DECLARED 1
       
   274 #define YYLTYPE_IS_TRIVIAL 1
   274 #endif
   275 #endif
       
   276 
   275 }
   277 }
   276 
   278 
   277 
   279 
   278 
   280 
   279 %union {
   281 %union {
   494 %type  <leaf>	hours
   496 %type  <leaf>	hours
   495 %type  <leaf>	minutes
   497 %type  <leaf>	minutes
   496 %type  <leaf>	seconds
   498 %type  <leaf>	seconds
   497 %type  <leaf>	milliseconds
   499 %type  <leaf>	milliseconds
   498 
   500 
   499 %type  <leaf>	integer_d
       
   500 %type  <leaf>	integer_h
       
   501 %type  <leaf>	integer_m
       
   502 %type  <leaf>	integer_s
       
   503 %type  <leaf>	integer_ms
       
   504 %type  <leaf>	fixed_point_d
       
   505 %type  <leaf>	fixed_point_h
       
   506 %type  <leaf>	fixed_point_m
       
   507 %type  <leaf>	fixed_point_s
       
   508 %type  <leaf>	fixed_point_ms
       
   509 
       
   510 %token <ID>	fixed_point_token
   501 %token <ID>	fixed_point_token
   511 %token <ID>	fixed_point_d_token
   502 %token <ID>	fixed_point_d_token
   512 %token <ID>	integer_d_token
   503 %token <ID>	integer_d_token
   513 %token <ID>	fixed_point_h_token
   504 %token <ID>	fixed_point_h_token
   514 %token <ID>	integer_h_token
   505 %token <ID>	integer_h_token
   516 %token <ID>	integer_m_token
   507 %token <ID>	integer_m_token
   517 %token <ID>	fixed_point_s_token
   508 %token <ID>	fixed_point_s_token
   518 %token <ID>	integer_s_token
   509 %token <ID>	integer_s_token
   519 %token <ID>	fixed_point_ms_token
   510 %token <ID>	fixed_point_ms_token
   520 %token <ID>	integer_ms_token
   511 %token <ID>	integer_ms_token
   521 
   512 %token <ID>	end_interval_token
       
   513 %token <ID>	erroneous_interval_token
   522 // %token TIME
   514 // %token TIME
   523 %token T_SHARP
   515 %token T_SHARP
   524 
   516 
   525 
   517 
   526 /************************************/
   518 /************************************/
  1913 ;
  1905 ;
  1914 
  1906 
  1915 
  1907 
  1916 integer_literal:
  1908 integer_literal:
  1917   integer_type_name '#' signed_integer
  1909   integer_type_name '#' signed_integer
  1918 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1910 	{$$ = new integer_literal_c($1, $3, locloc(@$));}
  1919 | integer_type_name '#' binary_integer
  1911 | integer_type_name '#' binary_integer
  1920 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1912 	{$$ = new integer_literal_c($1, $3, locloc(@$));}
  1921 | integer_type_name '#' octal_integer
  1913 | integer_type_name '#' octal_integer
  1922 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1914 	{$$ = new integer_literal_c($1, $3, locloc(@$));}
  1923 | integer_type_name '#' hex_integer
  1915 | integer_type_name '#' hex_integer
  1924 	{$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));}
  1916 	{$$ = new integer_literal_c($1, $3, locloc(@$));}
  1925 /* NOTE: see note in the definition of constant for reason
  1917 /* NOTE: see note in the definition of constant for reason
  1926  * why signed_integer, binary_integer, octal_integer
  1918  * why signed_integer, binary_integer, octal_integer
  1927  * and hex_integer are missing here!
  1919  * and hex_integer are missing here!
  1928  */
  1920  */
  1929 /* ERROR_CHECK_BEGIN */
  1921 /* ERROR_CHECK_BEGIN */
  1955 /* NOTE: see note in the definition of constant for reason
  1947 /* NOTE: see note in the definition of constant for reason
  1956  * why signed_real is missing here!
  1948  * why signed_real is missing here!
  1957  */
  1949  */
  1958 /*  signed_real */
  1950 /*  signed_real */
  1959   real_type_name '#' signed_real
  1951   real_type_name '#' signed_real
  1960 	{$$ = new real_literal_c($1, $3, locf(@1), locl(@3));}
  1952 	{$$ = new real_literal_c($1, $3, locloc(@$));}
  1961 /* ERROR_CHECK_BEGIN */
  1953 /* ERROR_CHECK_BEGIN */
  1962 | real_type_name signed_real
  1954 | real_type_name signed_real
  1963 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between real type name and value in real literal."); yynerrs++;}
  1955 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between real type name and value in real literal."); yynerrs++;}
  1964 | real_type_name '#' error
  1956 | real_type_name '#' error
  1965   {$$ = NULL;
  1957   {$$ = NULL;
  1979 
  1971 
  1980 
  1972 
  1981 
  1973 
  1982 bit_string_literal:
  1974 bit_string_literal:
  1983   bit_string_type_name '#' integer  /* i.e. unsigned_integer */
  1975   bit_string_type_name '#' integer  /* i.e. unsigned_integer */
  1984 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1976 	{$$ = new bit_string_literal_c($1, $3, locloc(@$));}
  1985 | bit_string_type_name '#' binary_integer
  1977 | bit_string_type_name '#' binary_integer
  1986 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1978 	{$$ = new bit_string_literal_c($1, $3, locloc(@$));}
  1987 | bit_string_type_name '#' octal_integer
  1979 | bit_string_type_name '#' octal_integer
  1988 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1980 	{$$ = new bit_string_literal_c($1, $3, locloc(@$));}
  1989 | bit_string_type_name '#' hex_integer
  1981 | bit_string_type_name '#' hex_integer
  1990 	{$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));}
  1982 	{$$ = new bit_string_literal_c($1, $3, locloc(@$));}
  1991 /* NOTE: see note in the definition of constant for reason
  1983 /* NOTE: see note in the definition of constant for reason
  1992  * why unsigned_integer, binary_integer, octal_integer
  1984  * why unsigned_integer, binary_integer, octal_integer
  1993  * and hex_integer are missing here!
  1985  * and hex_integer are missing here!
  1994  */
  1986  */
  1995 /* NOTE: see note under the B 1.2.1 section of token
  1987 /* NOTE: see note under the B 1.2.1 section of token
  2142 /* ERROR_CHECK_BEGIN */
  2134 /* ERROR_CHECK_BEGIN */
  2143 | TIME interval
  2135 | TIME interval
  2144 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2136 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2145 | TIME '-' interval
  2137 | TIME '-' interval
  2146 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2138 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
  2147 | TIME '#' error
  2139 | TIME '#' erroneous_interval_token
  2148 	{$$ = NULL;
  2140 	{$$ = NULL; print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yynerrs++;}
  2149 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for duration.");}
  2141 | T_SHARP erroneous_interval_token
  2150 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yyclearin;}
  2142 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yynerrs++;}
  2151 	 yyerrok;
  2143 | TIME '#' '-' erroneous_interval_token
  2152 	}
  2144 	{$$ = NULL; print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yynerrs++;}
  2153 | T_SHARP error
  2145 | T_SHARP '-' erroneous_interval_token
  2154 	{$$ = NULL;
  2146 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yynerrs++;}
  2155 	 if (is_current_syntax_token()) {print_err_msg(locl(@1), locf(@2), "no value defined for duration.");}
  2147 /* ERROR_CHECK_END */
  2156 	 else {print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yyclearin;}
  2148 ;
  2157 	 yyerrok;
  2149 
  2158 	}
  2150 fixed_point:
  2159 /* ERROR_CHECK_END */
  2151   integer
  2160 ;
  2152 | fixed_point_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2161 
  2153 
  2162 
  2154 
  2163 interval:
  2155 interval:
  2164   days
  2156   days hours minutes seconds milliseconds end_interval_token
  2165 | hours
  2157 	{$$ = new interval_c($1, $2, $3, $4, $5, locloc(@$));};
  2166 | minutes
  2158 ;
  2167 | seconds
  2159 
  2168 | milliseconds
  2160 
  2169 ;
  2161 days:   /*  fixed_point ('d') */
  2170 
  2162   /* empty */		{$$ = NULL;}
  2171 integer_d:  integer_d_token  {$$ = new integer_c($1, locloc(@$));};
  2163 | fixed_point_d_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2172 integer_h:  integer_h_token  {$$ = new integer_c($1, locloc(@$));};
  2164 | integer_d_token	{$$ = new integer_c($1, locloc(@$));};
  2173 integer_m:  integer_m_token  {$$ = new integer_c($1, locloc(@$));};
  2165 ;
  2174 integer_s:  integer_s_token  {$$ = new integer_c($1, locloc(@$));};
  2166 
  2175 integer_ms: integer_ms_token {$$ = new integer_c($1, locloc(@$));};
  2167 hours:  /*  fixed_point ('h') */
  2176 
  2168   /* empty */		{$$ = NULL;}
  2177 fixed_point_d:
  2169 | fixed_point_h_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2178   fixed_point_d_token
  2170 | integer_h_token	{$$ = new integer_c($1, locloc(@$));};
  2179 	{$$ = new fixed_point_c($1, locloc(@$));}
  2171 ;
  2180 | integer_d
  2172 
  2181 ;
  2173 minutes: /*  fixed_point ('m') */
  2182 
  2174   /* empty */		{$$ = NULL;}
  2183 fixed_point_h:
  2175 | fixed_point_m_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2184   fixed_point_h_token
  2176 | integer_m_token	{$$ = new integer_c($1, locloc(@$));};
  2185 	{$$ = new fixed_point_c($1, locloc(@$));}
  2177 ;
  2186 | integer_h
  2178 
  2187 ;
  2179 seconds: /*  fixed_point ('s') */
  2188 
  2180   /* empty */		{$$ = NULL;}
  2189 fixed_point_m:
  2181 | fixed_point_s_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2190   fixed_point_m_token
  2182 | integer_s_token	{$$ = new integer_c($1, locloc(@$));};
  2191 	{$$ = new fixed_point_c($1, locloc(@$));}
  2183 ;
  2192 | integer_m
  2184 
  2193 ;
  2185 milliseconds: /*  fixed_point ('ms') */
  2194 
  2186   /* empty */		{$$ = NULL;}
  2195 fixed_point_s:
  2187 | fixed_point_ms_token	{$$ = new fixed_point_c($1, locloc(@$));};
  2196   fixed_point_s_token
  2188 | integer_ms_token	{$$ = new integer_c($1, locloc(@$));};
  2197 	{$$ = new fixed_point_c($1, locloc(@$));}
       
  2198 | integer_s
       
  2199 ;
       
  2200 
       
  2201 fixed_point_ms:
       
  2202   fixed_point_ms_token
       
  2203 	{$$ = new fixed_point_c($1, locloc(@$));}
       
  2204 | integer_ms
       
  2205 ;
       
  2206 
       
  2207 
       
  2208 fixed_point:
       
  2209   fixed_point_token
       
  2210 	{$$ = new fixed_point_c($1, locloc(@$));}
       
  2211 | integer
       
  2212 ;
       
  2213 
       
  2214 
       
  2215 days:
       
  2216 /*  fixed_point ('d') */
       
  2217   fixed_point_d
       
  2218 	{$$ = new days_c($1, NULL, locloc(@$));}
       
  2219 /*| integer ('d') ['_'] hours */
       
  2220 | integer_d hours
       
  2221 	{$$ = new days_c($1, $2, locloc(@$));}
       
  2222 | integer_d '_' hours
       
  2223 	{$$ = new days_c($1, $3, locloc(@$));}
       
  2224 /* ERROR_CHECK_BEGIN */
       
  2225 | integer_d '_' error
       
  2226 	{$$ = NULL;
       
  2227 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for hours in duration.");}
       
  2228 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for hours in duration."); yyclearin;}
       
  2229 	 yyerrok;
       
  2230 	}
       
  2231 /* ERROR_CHECK_END */
       
  2232 ;
       
  2233 
       
  2234 
       
  2235 hours:
       
  2236 /*  fixed_point ('h') */
       
  2237   fixed_point_h
       
  2238 	{$$ = new hours_c($1, NULL, locloc(@$));}
       
  2239 /*| integer ('h') ['_'] minutes */
       
  2240 | integer_h minutes
       
  2241 	{$$ = new hours_c($1, $2, locloc(@$));}
       
  2242 | integer_h '_' minutes
       
  2243 	{$$ = new hours_c($1, $3, locloc(@$));}
       
  2244 /* ERROR_CHECK_BEGIN */
       
  2245 | integer_h '_' error
       
  2246 	{$$ = NULL;
       
  2247 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for minutes in duration.");}
       
  2248 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for minutes in duration."); yyclearin;}
       
  2249 	 yyerrok;
       
  2250 	}
       
  2251 /* ERROR_CHECK_END */
       
  2252 
       
  2253 ;
       
  2254 
       
  2255 minutes:
       
  2256 /*  fixed_point ('m') */
       
  2257   fixed_point_m
       
  2258 	{$$ = new minutes_c($1, NULL, locloc(@$));}
       
  2259 /*| integer ('m') ['_'] seconds */
       
  2260 | integer_m seconds
       
  2261 	{$$ = new minutes_c($1, $2, locloc(@$));}
       
  2262 | integer_m '_' seconds
       
  2263 	{$$ = new minutes_c($1, $3, locloc(@$));}
       
  2264 /* ERROR_CHECK_BEGIN */
       
  2265 | integer_m '_' error
       
  2266 	{$$ = NULL;
       
  2267 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for seconds in duration.");}
       
  2268 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for seconds in duration."); yyclearin;}
       
  2269 	 yyerrok;
       
  2270 	}
       
  2271 /* ERROR_CHECK_END */
       
  2272 ;
       
  2273 
       
  2274 seconds:
       
  2275 /*  fixed_point ('s') */
       
  2276   fixed_point_s
       
  2277 	{$$ = new seconds_c($1, NULL, locloc(@$));}
       
  2278 /*| integer ('s') ['_'] milliseconds */
       
  2279 | integer_s milliseconds
       
  2280 	{$$ = new seconds_c($1, $2, locloc(@$));}
       
  2281 | integer_s '_' milliseconds
       
  2282 	{$$ = new seconds_c($1, $3, locloc(@$));}
       
  2283 /* ERROR_CHECK_BEGIN */
       
  2284 | integer_s '_' error
       
  2285 	{$$ = NULL;
       
  2286 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for milliseconds in duration.");}
       
  2287 	 else {print_err_msg(locf(@3), locl(@3), "invalid value for milliseconds in duration."); yyclearin;}
       
  2288 	 yyerrok;
       
  2289 	}
       
  2290 /* ERROR_CHECK_END */
       
  2291 ;
       
  2292 
       
  2293 milliseconds:
       
  2294 /*  fixed_point ('ms') */
       
  2295   fixed_point_ms
       
  2296 	{$$ = new milliseconds_c($1, locloc(@$));}
       
  2297 ;
  2189 ;
  2298 
  2190 
  2299 
  2191 
  2300 
  2192 
  2301 /************************************/
  2193 /************************************/
  2989 array_initial_elements_list:
  2881 array_initial_elements_list:
  2990   array_initial_elements
  2882   array_initial_elements
  2991 	{$$ = new array_initial_elements_list_c(locloc(@$)); $$->add_element($1);}
  2883 	{$$ = new array_initial_elements_list_c(locloc(@$)); $$->add_element($1);}
  2992 | array_initial_elements_list ',' array_initial_elements
  2884 | array_initial_elements_list ',' array_initial_elements
  2993 	{$$ = $1; $$->add_element($3);}
  2885 	{$$ = $1; $$->add_element($3);}
  2994 /* ERROR_CHECK_BEGIN 
  2886 /* ERROR_CHECK_BEGIN */
       
  2887 /* The following error checking rules have been commented out. Why? Was it a typo? 
       
  2888  * Lets keep them commented out for now...
       
  2889  */
       
  2890 /*
  2995 | array_initial_elements_list ',' error
  2891 | array_initial_elements_list ',' error
  2996 	{$$ = $1;
  2892 	{$$ = $1;
  2997 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no array initial value in array initial values list.");}
  2893 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no array initial value in array initial values list.");}
  2998 	 else {print_err_msg(locf(@3), locl(@3), "invalid array initial value in array initial values list."); yyclearin;}
  2894 	 else {print_err_msg(locf(@3), locl(@3), "invalid array initial value in array initial values list."); yyclearin;}
  2999 	 yyerrok;
  2895 	 yyerrok;
  3000 	}
  2896 	}
       
  2897 */
  3001 /* ERROR_CHECK_END */
  2898 /* ERROR_CHECK_END */
  3002 ;
  2899 ;
  3003 
  2900 
  3004 
  2901 
  3005 array_initial_elements:
  2902 array_initial_elements:
  3149 structure_element_initialization_list:
  3046 structure_element_initialization_list:
  3150   structure_element_initialization
  3047   structure_element_initialization
  3151 	{$$ = new structure_element_initialization_list_c(locloc(@$)); $$->add_element($1);}
  3048 	{$$ = new structure_element_initialization_list_c(locloc(@$)); $$->add_element($1);}
  3152 | structure_element_initialization_list ',' structure_element_initialization
  3049 | structure_element_initialization_list ',' structure_element_initialization
  3153 	{$$ = $1; $$->add_element($3);}
  3050 	{$$ = $1; $$->add_element($3);}
  3154 /* ERROR_CHECK_BEGIN 
  3051 /* ERROR_CHECK_BEGIN */
       
  3052 /* The following error checking rules have been commented out. Why? Was it a typo? 
       
  3053  * Lets keep them commented out for now...
       
  3054  */
       
  3055 /*
  3155 | structure_element_initialization_list structure_element_initialization
  3056 | structure_element_initialization_list structure_element_initialization
  3156 	{$$ = $1; print_err_msg(locl(@1), locf(@2), "',' missing in structure element initialization list in structure initialization."); yynerrs++;}
  3057 	{$$ = $1; print_err_msg(locl(@1), locf(@2), "',' missing in structure element initialization list in structure initialization."); yynerrs++;}
  3157 | structure_element_initialization_list ',' error
  3058 | structure_element_initialization_list ',' error
  3158 	{$$ = $1;
  3059 	{$$ = $1;
  3159 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no structure element initialization defined in structure initialization.");}
  3060 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no structure element initialization defined in structure initialization.");}
  3160 	 else {print_err_msg(locf(@3), locl(@3), "invalid structure element initialization in structure initialization."); yyclearin;}
  3061 	 else {print_err_msg(locf(@3), locl(@3), "invalid structure element initialization in structure initialization."); yyclearin;}
  3161 	 yyerrok;
  3062 	 yyerrok;
  3162 	}
  3063 	}
       
  3064 */
  3163 /* ERROR_CHECK_END */
  3065 /* ERROR_CHECK_END */
  3164 ;
  3066 ;
  3165 
  3067 
  3166 
  3068 
  3167 structure_element_initialization:
  3069 structure_element_initialization:
  3405 
  3307 
  3406 structured_variable:
  3308 structured_variable:
  3407   record_variable '.' field_selector
  3309   record_variable '.' field_selector
  3408 	{$$ = new structured_variable_c($1, $3, locloc(@$));}
  3310 	{$$ = new structured_variable_c($1, $3, locloc(@$));}
  3409 | record_variable '.' il_simple_operator_clash3
  3311 | record_variable '.' il_simple_operator_clash3
  3410     {$$ = new structured_variable_c($1, $3, locloc(@$));}
  3312     {$$ = new structured_variable_c($1, il_operator_c_2_identifier_c($3), locloc(@$));}
  3411 ;
  3313 ;
  3412 
  3314 
  3413 
  3315 
  3414 /* please see note above any_symbolic_variable */
  3316 /* please see note above any_symbolic_variable */
  3415 any_structured_variable:
  3317 any_structured_variable:
  5235 ;
  5137 ;
  5236 
  5138 
  5237 initial_step:
  5139 initial_step:
  5238   INITIAL_STEP step_name ':' action_association_list END_STEP
  5140   INITIAL_STEP step_name ':' action_association_list END_STEP
  5239 //  INITIAL_STEP identifier ':' action_association_list END_STEP
  5141 //  INITIAL_STEP identifier ':' action_association_list END_STEP
  5240 	{$$ = new initial_step_c($2, $4, locloc(@$));}
  5142 	{$$ = new initial_step_c($2, $4, locloc(@$));
       
  5143 	 variable_name_symtable.insert($2, prev_declared_variable_name_token); // A step name may later be used as a structured variable!!
       
  5144 	}
  5241 /* ERROR_CHECK_BEGIN */
  5145 /* ERROR_CHECK_BEGIN */
  5242 | INITIAL_STEP ':' action_association_list END_STEP
  5146 | INITIAL_STEP ':' action_association_list END_STEP
  5243   {$$ = NULL; print_err_msg(locf(@1), locl(@2), "no step name defined in initial step declaration."); yynerrs++;}
  5147   {$$ = NULL; print_err_msg(locf(@1), locl(@2), "no step name defined in initial step declaration."); yynerrs++;}
  5244 | INITIAL_STEP error ':' action_association_list END_STEP
  5148 | INITIAL_STEP error ':' action_association_list END_STEP
  5245 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid step name defined in initial step declaration."); yyerrok;}
  5149 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid step name defined in initial step declaration."); yyerrok;}
  5255 ;
  5159 ;
  5256 
  5160 
  5257 step:
  5161 step:
  5258   STEP step_name ':' action_association_list END_STEP
  5162   STEP step_name ':' action_association_list END_STEP
  5259 //  STEP identifier ':' action_association_list END_STEP
  5163 //  STEP identifier ':' action_association_list END_STEP
  5260 	{$$ = new step_c($2, $4, locloc(@$));}
  5164 	{$$ = new step_c($2, $4, locloc(@$));
       
  5165 	 variable_name_symtable.insert($2, prev_declared_variable_name_token); // A step name may later be used as a structured variable!!
       
  5166 	}
  5261 /* ERROR_CHECK_BEGIN */
  5167 /* ERROR_CHECK_BEGIN */
  5262 | STEP ':' action_association_list END_STEP
  5168 | STEP ':' action_association_list END_STEP
  5263   {$$ = NULL; print_err_msg(locl(@1), locf(@2), "no step name defined in step declaration."); yynerrs++;}
  5169   {$$ = NULL; print_err_msg(locl(@1), locf(@2), "no step name defined in step declaration."); yynerrs++;}
  5264 | STEP error ':' action_association_list END_STEP
  5170 | STEP error ':' action_association_list END_STEP
  5265 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid step name defined in step declaration."); yyerrok;}
  5171 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid step name defined in step declaration."); yyerrok;}
  5357 | SD		{$$ = new timed_qualifier_c(strdup("SD"), locloc(@$));}
  5263 | SD		{$$ = new timed_qualifier_c(strdup("SD"), locloc(@$));}
  5358 | DS		{$$ = new timed_qualifier_c(strdup("DS"), locloc(@$));}
  5264 | DS		{$$ = new timed_qualifier_c(strdup("DS"), locloc(@$));}
  5359 | SL		{$$ = new timed_qualifier_c(strdup("SL"), locloc(@$));}
  5265 | SL		{$$ = new timed_qualifier_c(strdup("SL"), locloc(@$));}
  5360 ;
  5266 ;
  5361 
  5267 
       
  5268 /* NOTE: A step_name may be used as a structured vaqriable, in order to access the status bit (e.g. Step1.X) 
       
  5269  *       or the time it has been active (e.g. Step1.T). 
       
  5270  *       In order to allow the step name to be used as a variable inside ST expressions (only ST expressions ??)
       
  5271  *       when defining transitions, we need to add the step_name to the list of previously declared variables.
       
  5272  *       This allows the step name to be used as a variable inside all transition expressions, as the user
       
  5273  *       can clearly define the transition _after_ the step itself has been defined/declared, so the 
       
  5274  *       'variable' is previously 'declared'.
       
  5275  *
       
  5276  *       However, when defining/declaring a step, a variable name can also be used to define a timed
       
  5277  *       action association. In this case, we may have a circular reference:
       
  5278  *        e.g.
       
  5279  *            ...
       
  5280  *             STEP step1:
       
  5281  *                action1 (D,t#100ms);
       
  5282  *             end_step
       
  5283  *
       
  5284  *             STEP step2:
       
  5285  *                action1 (D,step3.T);  <---- forward reference to step3.T !!!!!!
       
  5286  *             end_step
       
  5287  *
       
  5288  *             STEP step3:
       
  5289  *                action1 (D,step2.T);  <---- back reference to step2.T
       
  5290  *             end_step
       
  5291  *
       
  5292  *
       
  5293  *         There is no way the user can always use the step3.T variable only after it has
       
  5294  *         been 'declared'. So adding the steps to the list of previously declared variables 
       
  5295  *         when the steps are declared is not a solution to the above situation.
       
  5296  *
       
  5297  *         Fortunately, the standard does not allow ST expressions in the above syntax
       
  5298  *         (i.e. when defining the delay of a timed actions), but only either a 
       
  5299  *         Time literal, or a variable.
       
  5300  *         This is why we change the definition of action_time from
       
  5301  *         action_time:
       
  5302  *           duration
       
  5303  *         | variable
       
  5304  *         ;
       
  5305  *
       
  5306  *         to:
       
  5307  *         action_time:
       
  5308  *           duration
       
  5309  *         | any_symbolic_variable
       
  5310  *         ;
       
  5311  *
       
  5312  *       NOTE that this same problem does not occur with the 'indicator_name': it does not
       
  5313  *       make sense to set/indicate a step1.X variable, as these variables are read-only!
       
  5314  */     
       
  5315     
  5362 action_time:
  5316 action_time:
  5363   duration
  5317   duration
  5364 | variable
  5318 //| variable
       
  5319   | any_symbolic_variable
  5365 ;
  5320 ;
  5366 
  5321 
  5367 indicator_name: variable;
  5322 indicator_name: variable;
  5368 
  5323 
  5369 // transition_name: identifier;
  5324 // transition_name: identifier;
  5458 transition_priority:
  5413 transition_priority:
  5459   /* empty */
  5414   /* empty */
  5460   {$$ = NULL;}
  5415   {$$ = NULL;}
  5461 | '(' {cmd_goto_sfc_priority_state();} PRIORITY {cmd_pop_state();} ASSIGN integer ')'
  5416 | '(' {cmd_goto_sfc_priority_state();} PRIORITY {cmd_pop_state();} ASSIGN integer ')'
  5462 	{$$ = $6;}
  5417 	{$$ = $6;}
  5463 /* ERROR_CHECK_BEGIN 
  5418 /* ERROR_CHECK_BEGIN */
       
  5419 /* The following error checking rules have been intentionally commented out. */
       
  5420 /*
  5464 | '(' ASSIGN integer ')'
  5421 | '(' ASSIGN integer ')'
  5465 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'PRIORITY' missing between '(' and ':=' in transition declaration with priority."); yynerrs++;}
  5422 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'PRIORITY' missing between '(' and ':=' in transition declaration with priority."); yynerrs++;}
  5466 | '(' error ASSIGN integer ')'
  5423 | '(' error ASSIGN integer ')'
  5467 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "expecting 'PRIORITY' between '(' and ':=' in transition declaration with priority."); yyerrok;}
  5424 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "expecting 'PRIORITY' between '(' and ':=' in transition declaration with priority."); yyerrok;}
  5468  ERROR_CHECK_END */
  5425 */
       
  5426 /* ERROR_CHECK_END */
  5469 ;
  5427 ;
  5470 
  5428 
  5471 
  5429 
  5472 transition_condition:
  5430 transition_condition:
  5473   ':' eol_list simple_instr_list
  5431   ':' eol_list simple_instr_list
  6291 
  6249 
  6292 instruction_list:
  6250 instruction_list:
  6293   il_instruction
  6251   il_instruction
  6294 	{$$ = new instruction_list_c(locloc(@$)); $$->add_element($1);}
  6252 	{$$ = new instruction_list_c(locloc(@$)); $$->add_element($1);}
  6295 | any_pragma eol_list
  6253 | any_pragma eol_list
  6296 	{$$ = new instruction_list_c(locloc(@$)); $$->add_element($1);}
  6254 	{$$ = new instruction_list_c(locloc(@1)); $$->add_element($1);} /* locloc(@1) is not a bug! We ignore trailing EOLs when determining symbol location! */
  6297 | instruction_list il_instruction
  6255 | instruction_list il_instruction
  6298 	{$$ = $1; $$->add_element($2);}
  6256 	{$$ = $1; $$->add_element($2);}
  6299 | instruction_list any_pragma
  6257 | instruction_list any_pragma
  6300 	{$$ = $1; $$->add_element($2);}
  6258 	{$$ = $1; $$->add_element($2);}
  6301 ;
  6259 ;
  6302 
  6260 
  6303 
  6261 
  6304 
  6262 
  6305 il_instruction:
  6263 il_instruction:
  6306   il_incomplete_instruction eol_list
  6264   il_incomplete_instruction eol_list
  6307 	{$$ = new il_instruction_c(NULL, $1, locloc(@$));}
  6265 	{$$ = new il_instruction_c(NULL, $1, locloc(@1));} /* locloc(@1) is not a bug! We ignore trailing EOLs when determining symbol location! */
  6308 | label ':' il_incomplete_instruction eol_list
  6266 | label ':' il_incomplete_instruction eol_list
  6309 	{$$ = new il_instruction_c($1, $3, locloc(@$));}
  6267 	{$$ = new il_instruction_c($1, $3, locf(@1), locl(@3));} /* locf(@1), locl(@3) is not a bug! We ignore trailing EOLs when determining symbol location! */
  6310 | label ':' eol_list
  6268 | label ':' eol_list
  6311 	{$$ = new il_instruction_c($1, NULL, locloc(@$));}
  6269 	{$$ = new il_instruction_c($1, NULL, locf(@1), locl(@2));} /* locf(@1), locl(@2) is not a bug! We ignore trailing EOLs when determining symbol location! */
  6312 /* ERROR_CHECK_BEGIN */
  6270 /* ERROR_CHECK_BEGIN */
  6313 | error eol_list
  6271 | error eol_list
  6314 	{$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid IL instruction."); yyerrok;}
  6272 	{$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid IL instruction."); yyerrok;}
  6315 | il_incomplete_instruction error
  6273 | il_incomplete_instruction error
  6316 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "EOL missing at the end of IL instruction."); yyerrok;}
  6274 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "EOL missing at the end of IL instruction."); yyerrok;}
  6641 ;
  6599 ;
  6642 
  6600 
  6643 
  6601 
  6644 il_simple_instruction:
  6602 il_simple_instruction:
  6645   il_simple_operation eol_list
  6603   il_simple_operation eol_list
       
  6604 	{$$ = new il_simple_instruction_c($1, locloc(@1));} /* locloc(@1) is not a bug! We ignore trailing EOLs when determining symbol location! */
  6646 | il_expression eol_list
  6605 | il_expression eol_list
       
  6606 	{$$ = new il_simple_instruction_c($1, locloc(@1));} /* locloc(@1) is not a bug! We ignore trailing EOLs when determining symbol location! */
  6647 | il_formal_funct_call eol_list
  6607 | il_formal_funct_call eol_list
       
  6608 	{$$ = new il_simple_instruction_c($1, locloc(@1));} /* locloc(@1) is not a bug! We ignore trailing EOLs when determining symbol location! */
  6648 /* ERROR_CHECK_BEGIN */
  6609 /* ERROR_CHECK_BEGIN */
  6649 | il_expression error
  6610 | il_expression error
  6650   {$$ = NULL; print_err_msg(locl(@1), locf(@2), "EOL missing after expression IL instruction."); yyerrok;}
  6611   {$$ = NULL; print_err_msg(locl(@1), locf(@2), "EOL missing after expression IL instruction."); yyerrok;}
  6651 | il_formal_funct_call error
  6612 | il_formal_funct_call error
  6652   {$$ = NULL; print_err_msg(locl(@1), locf(@2), "EOL missing after formal function call IL instruction."); yyerrok;}
  6613   {$$ = NULL; print_err_msg(locl(@1), locf(@2), "EOL missing after formal function call IL instruction."); yyerrok;}
  8060   if (first_filename == NULL) first_filename = unknown_file;
  8021   if (first_filename == NULL) first_filename = unknown_file;
  8061   if ( last_filename == NULL)  last_filename = unknown_file;
  8022   if ( last_filename == NULL)  last_filename = unknown_file;
  8062 
  8023 
  8063   if (full_token_loc) {
  8024   if (full_token_loc) {
  8064     if (first_filename == last_filename)
  8025     if (first_filename == last_filename)
  8065       fprintf(stderr, "%s:%d-%d..%d-%d: error : %s\n", first_filename, first_line, first_column, last_line, last_column, additional_error_msg);
  8026       fprintf(stderr, "%s:%d-%d..%d-%d: error: %s\n", first_filename, first_line, first_column, last_line, last_column, additional_error_msg);
  8066     else
  8027     else
  8067       fprintf(stderr, "%s:%d-%d..%s:%d-%d: error : %s\n", first_filename, first_line, first_column, last_filename, last_line, last_column, additional_error_msg);
  8028       fprintf(stderr, "%s:%d-%d..%s:%d-%d: error: %s\n", first_filename, first_line, first_column, last_filename, last_line, last_column, additional_error_msg);
  8068   } else {
  8029   } else {
  8069       fprintf(stderr, "%s:%d: error : %s\n", first_filename, first_line, additional_error_msg);
  8030       fprintf(stderr, "%s:%d: error: %s\n", first_filename, first_line, additional_error_msg);
  8070   }
  8031   }
  8071   //fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg);
  8032   //fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg);
  8072   print_include_stack();
  8033   print_include_stack();
  8073   //fprintf(stderr, "%s(%d-%d): %s\n", current_filename, first_line, last_line, current_error_msg);
  8034   //fprintf(stderr, "%s(%d-%d): %s\n", current_filename, first_line, last_line, current_error_msg);
  8074 }
  8035 }
  8251     fclose(in_file);
  8212     fclose(in_file);
  8252     return -1;
  8213     return -1;
  8253   }
  8214   }
  8254 
  8215 
  8255   /* first parse the standard library file... */
  8216   /* first parse the standard library file... */
       
  8217   /* Do not debug the standard library, even if debug flag is set! */
  8256   /*
  8218   /*
  8257   #if YYDEBUG
  8219   #if YYDEBUG
  8258     yydebug = 1;
  8220     yydebug = 1;
  8259   #endif
  8221   #endif
  8260   */
  8222   */
  8266   current_tracking = GetNewTracking(yyin);
  8228   current_tracking = GetNewTracking(yyin);
  8267   if (yyparse() != 0)
  8229   if (yyparse() != 0)
  8268       ERROR;
  8230       ERROR;
  8269 
  8231 
  8270   if (yynerrs > 0) {
  8232   if (yynerrs > 0) {
  8271     fprintf (stderr, "\nFound %d error(s) in %s. Bailing out!\n", yynerrs /* global variable */, libfilename);
  8233     fprintf (stderr, "\n%d error(s) found in %s. Bailing out!\n", yynerrs /* global variable */, libfilename);
  8272     ERROR;
  8234     ERROR;
  8273   }
  8235   }
  8274   free(libfilename);
  8236   free(libfilename);
  8275   fclose(lib_file);
  8237   fclose(lib_file);
  8276 
  8238 
  8299   		exit(EXIT_FAILURE);
  8261   		exit(EXIT_FAILURE);
  8300   	}
  8262   	}
  8301   }
  8263   }
  8302 
  8264 
  8303   if (yynerrs > 0) {
  8265   if (yynerrs > 0) {
  8304     fprintf (stderr, "\nFound %d error(s). Bailing out!\n", yynerrs /* global variable */);
  8266     fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */);
  8305     exit(EXIT_FAILURE);
  8267     exit(EXIT_FAILURE);
  8306   }
  8268   }
  8307   
  8269   
  8308   if (tree_root_ref != NULL)
  8270   if (tree_root_ref != NULL)
  8309     *tree_root_ref = tree_root;
  8271     *tree_root_ref = tree_root;