stage1_2/iec_bison.yy
changeset 547 dab341e80664
parent 520 fb381d2cd25b
child 584 f95d6561d439
--- a/stage1_2/iec_bison.yy	Wed May 09 22:59:10 2012 +0100
+++ b/stage1_2/iec_bison.yy	Wed May 09 23:00:10 2012 +0100
@@ -58,6 +58,17 @@
 /**********************************************************************/
 /**********************************************************************/
 
+/* NOTE: the following file contains many rules used merely for detecting errors in
+ * the IEC source code being parsed.
+ * To remove all these rules, simply execute the command (first replace all '%' with '/'):
+ * $sed '\:%\* ERROR_CHECK_BEGIN \*%:,\:%\* ERROR_CHECK_END \*%: d' iec_bison.yy
+ *
+ * The above command had to be edited ('/' replaced by '%') so as not to include the C syntax that closes
+ * comments inside this comment!
+ * If you place the command in a shell script, be sure to remove the backslashes '\' before each asterisk '*' !!
+ */
+
+
 
 
 
@@ -490,17 +501,6 @@
 %type  <leaf>	seconds
 %type  <leaf>	milliseconds
 
-%type  <leaf>	integer_d
-%type  <leaf>	integer_h
-%type  <leaf>	integer_m
-%type  <leaf>	integer_s
-%type  <leaf>	integer_ms
-%type  <leaf>	fixed_point_d
-%type  <leaf>	fixed_point_h
-%type  <leaf>	fixed_point_m
-%type  <leaf>	fixed_point_s
-%type  <leaf>	fixed_point_ms
-
 %token <ID>	fixed_point_token
 %token <ID>	fixed_point_d_token
 %token <ID>	integer_d_token
@@ -512,7 +512,8 @@
 %token <ID>	integer_s_token
 %token <ID>	fixed_point_ms_token
 %token <ID>	integer_ms_token
-
+%token <ID>	end_interval_token
+%token <ID>	erroneous_interval_token
 // %token TIME
 %token T_SHARP
 
@@ -2138,156 +2139,56 @@
 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
 | TIME '-' interval
 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'#' missing between 'TIME' and interval in duration."); yynerrs++;}
-| TIME '#' error
-	{$$ = NULL;
-	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for duration.");}
-	 else {print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yyclearin;}
-	 yyerrok;
-	}
-| T_SHARP error
-	{$$ = NULL;
-	 if (is_current_syntax_token()) {print_err_msg(locl(@1), locf(@2), "no value defined for duration.");}
-	 else {print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yyclearin;}
-	 yyerrok;
-	}
-/* ERROR_CHECK_END */
-;
+| TIME '#' erroneous_interval_token
+	{$$ = NULL; print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yynerrs++;}
+| T_SHARP erroneous_interval_token
+	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yynerrs++;}
+| TIME '#' '-' erroneous_interval_token
+	{$$ = NULL; print_err_msg(locf(@3), locl(@3), "invalid value for duration."); yynerrs++;}
+| T_SHARP '-' erroneous_interval_token
+	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "invalid value for duration."); yynerrs++;}
+/* ERROR_CHECK_END */
+;
+
+fixed_point:
+  integer
+| fixed_point_token	{$$ = new fixed_point_c($1, locloc(@$));};
 
 
 interval:
-  days
-| hours
-| minutes
-| seconds
-| milliseconds
-;
-
-integer_d:  integer_d_token  {$$ = new integer_c($1, locloc(@$));};
-integer_h:  integer_h_token  {$$ = new integer_c($1, locloc(@$));};
-integer_m:  integer_m_token  {$$ = new integer_c($1, locloc(@$));};
-integer_s:  integer_s_token  {$$ = new integer_c($1, locloc(@$));};
-integer_ms: integer_ms_token {$$ = new integer_c($1, locloc(@$));};
-
-fixed_point_d:
-  fixed_point_d_token
-	{$$ = new fixed_point_c($1, locloc(@$));}
-| integer_d
-;
-
-fixed_point_h:
-  fixed_point_h_token
-	{$$ = new fixed_point_c($1, locloc(@$));}
-| integer_h
-;
-
-fixed_point_m:
-  fixed_point_m_token
-	{$$ = new fixed_point_c($1, locloc(@$));}
-| integer_m
-;
-
-fixed_point_s:
-  fixed_point_s_token
-	{$$ = new fixed_point_c($1, locloc(@$));}
-| integer_s
-;
-
-fixed_point_ms:
-  fixed_point_ms_token
-	{$$ = new fixed_point_c($1, locloc(@$));}
-| integer_ms
-;
-
-
-fixed_point:
-  fixed_point_token
-	{$$ = new fixed_point_c($1, locloc(@$));}
-| integer
-;
-
-
-days:
-/*  fixed_point ('d') */
-  fixed_point_d
-	{$$ = new days_c($1, NULL, locloc(@$));}
-/*| integer ('d') ['_'] hours */
-| integer_d hours
-	{$$ = new days_c($1, $2, locloc(@$));}
-| integer_d '_' hours
-	{$$ = new days_c($1, $3, locloc(@$));}
-/* ERROR_CHECK_BEGIN */
-| integer_d '_' error
-	{$$ = NULL;
-	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for hours in duration.");}
-	 else {print_err_msg(locf(@3), locl(@3), "invalid value for hours in duration."); yyclearin;}
-	 yyerrok;
-	}
-/* ERROR_CHECK_END */
-;
-
-
-hours:
-/*  fixed_point ('h') */
-  fixed_point_h
-	{$$ = new hours_c($1, NULL, locloc(@$));}
-/*| integer ('h') ['_'] minutes */
-| integer_h minutes
-	{$$ = new hours_c($1, $2, locloc(@$));}
-| integer_h '_' minutes
-	{$$ = new hours_c($1, $3, locloc(@$));}
-/* ERROR_CHECK_BEGIN */
-| integer_h '_' error
-	{$$ = NULL;
-	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for minutes in duration.");}
-	 else {print_err_msg(locf(@3), locl(@3), "invalid value for minutes in duration."); yyclearin;}
-	 yyerrok;
-	}
-/* ERROR_CHECK_END */
-
-;
-
-minutes:
-/*  fixed_point ('m') */
-  fixed_point_m
-	{$$ = new minutes_c($1, NULL, locloc(@$));}
-/*| integer ('m') ['_'] seconds */
-| integer_m seconds
-	{$$ = new minutes_c($1, $2, locloc(@$));}
-| integer_m '_' seconds
-	{$$ = new minutes_c($1, $3, locloc(@$));}
-/* ERROR_CHECK_BEGIN */
-| integer_m '_' error
-	{$$ = NULL;
-	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for seconds in duration.");}
-	 else {print_err_msg(locf(@3), locl(@3), "invalid value for seconds in duration."); yyclearin;}
-	 yyerrok;
-	}
-/* ERROR_CHECK_END */
-;
-
-seconds:
-/*  fixed_point ('s') */
-  fixed_point_s
-	{$$ = new seconds_c($1, NULL, locloc(@$));}
-/*| integer ('s') ['_'] milliseconds */
-| integer_s milliseconds
-	{$$ = new seconds_c($1, $2, locloc(@$));}
-| integer_s '_' milliseconds
-	{$$ = new seconds_c($1, $3, locloc(@$));}
-/* ERROR_CHECK_BEGIN */
-| integer_s '_' error
-	{$$ = NULL;
-	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for milliseconds in duration.");}
-	 else {print_err_msg(locf(@3), locl(@3), "invalid value for milliseconds in duration."); yyclearin;}
-	 yyerrok;
-	}
-/* ERROR_CHECK_END */
-;
-
-milliseconds:
-/*  fixed_point ('ms') */
-  fixed_point_ms
-	{$$ = new milliseconds_c($1, locloc(@$));}
+  days hours minutes seconds milliseconds end_interval_token
+	{$$ = new interval_c($1, $2, $3, $4, $5, locloc(@$));};
+;
+
+
+days:   /*  fixed_point ('d') */
+  /* empty */		{$$ = NULL;}
+| fixed_point_d_token	{$$ = new fixed_point_c($1, locloc(@$));};
+| integer_d_token	{$$ = new integer_c($1, locloc(@$));};
+;
+
+hours:  /*  fixed_point ('h') */
+  /* empty */		{$$ = NULL;}
+| fixed_point_h_token	{$$ = new fixed_point_c($1, locloc(@$));};
+| integer_h_token	{$$ = new integer_c($1, locloc(@$));};
+;
+
+minutes: /*  fixed_point ('m') */
+  /* empty */		{$$ = NULL;}
+| fixed_point_m_token	{$$ = new fixed_point_c($1, locloc(@$));};
+| integer_m_token	{$$ = new integer_c($1, locloc(@$));};
+;
+
+seconds: /*  fixed_point ('s') */
+  /* empty */		{$$ = NULL;}
+| fixed_point_s_token	{$$ = new fixed_point_c($1, locloc(@$));};
+| integer_s_token	{$$ = new integer_c($1, locloc(@$));};
+;
+
+milliseconds: /*  fixed_point ('ms') */
+  /* empty */		{$$ = NULL;}
+| fixed_point_ms_token	{$$ = new fixed_point_c($1, locloc(@$));};
+| integer_ms_token	{$$ = new integer_c($1, locloc(@$));};
 ;
 
 
@@ -2985,13 +2886,18 @@
 	{$$ = new array_initial_elements_list_c(locloc(@$)); $$->add_element($1);}
 | array_initial_elements_list ',' array_initial_elements
 	{$$ = $1; $$->add_element($3);}
-/* ERROR_CHECK_BEGIN 
+/* ERROR_CHECK_BEGIN */
+/* The following error checking rules have been commented out. Why? Was it a typo? 
+ * Lets keep them commented out for now...
+ */
+/*
 | array_initial_elements_list ',' error
 	{$$ = $1;
 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no array initial value in array initial values list.");}
 	 else {print_err_msg(locf(@3), locl(@3), "invalid array initial value in array initial values list."); yyclearin;}
 	 yyerrok;
 	}
+*/
 /* ERROR_CHECK_END */
 ;
 
@@ -3145,7 +3051,11 @@
 	{$$ = new structure_element_initialization_list_c(locloc(@$)); $$->add_element($1);}
 | structure_element_initialization_list ',' structure_element_initialization
 	{$$ = $1; $$->add_element($3);}
-/* ERROR_CHECK_BEGIN 
+/* ERROR_CHECK_BEGIN */
+/* The following error checking rules have been commented out. Why? Was it a typo? 
+ * Lets keep them commented out for now...
+ */
+/*
 | structure_element_initialization_list structure_element_initialization
 	{$$ = $1; print_err_msg(locl(@1), locf(@2), "',' missing in structure element initialization list in structure initialization."); yynerrs++;}
 | structure_element_initialization_list ',' error
@@ -3154,6 +3064,7 @@
 	 else {print_err_msg(locf(@3), locl(@3), "invalid structure element initialization in structure initialization."); yyclearin;}
 	 yyerrok;
 	}
+*/
 /* ERROR_CHECK_END */
 ;
 
@@ -5454,12 +5365,15 @@
   {$$ = NULL;}
 | '(' {cmd_goto_sfc_priority_state();} PRIORITY {cmd_pop_state();} ASSIGN integer ')'
 	{$$ = $6;}
-/* ERROR_CHECK_BEGIN 
+/* ERROR_CHECK_BEGIN */
+/* The following error checking rules have been intentionally commented out. */
+/*
 | '(' ASSIGN integer ')'
 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'PRIORITY' missing between '(' and ':=' in transition declaration with priority."); yynerrs++;}
 | '(' error ASSIGN integer ')'
 	{$$ = NULL; print_err_msg(locf(@2), locl(@2), "expecting 'PRIORITY' between '(' and ':=' in transition declaration with priority."); yyerrok;}
- ERROR_CHECK_END */
+*/
+/* ERROR_CHECK_END */
 ;
 
 
@@ -8250,6 +8164,7 @@
   }
 
   /* first parse the standard library file... */
+  /* Do not debug the standard library, even if debug flag is set! */
   /*
   #if YYDEBUG
     yydebug = 1;