Many major changes to support SFC!
authormario
Fri, 09 Feb 2007 19:25:46 +0100
changeset 13 77174ccc5471
parent 12 f01522b04810
child 14 d926ee71f228
Many major changes to support SFC!
stage1_2/iec.flex
stage1_2/iec.y
--- a/stage1_2/iec.flex	Fri Feb 09 08:26:32 2007 +0100
+++ b/stage1_2/iec.flex	Fri Feb 09 19:25:46 2007 +0100
@@ -635,9 +635,9 @@
 	/*****************************************************/
 	/*****************************************************/
 
-	if (goto_body_state__) {
+	if (get_goto_body_state()) {
 	  yy_push_state(il_st_state);
-	  goto_body_state__ = 0;
+	  rst_goto_body_state();
 	}
 
 	/*********************************/
@@ -648,14 +648,14 @@
 <INITIAL>{file_include_pragma}	unput_text(0); yy_push_state(include_beg);
 
 	/* Any other pragma we find, we just pass it up to the syntax parser...   */
-	/* Note that the <body> state is exclusive, so we have to include it here too. */
+	/* Note that the <il_st_state> state is exclusive, so we have to include it here too. */
 {pragma}	{/* return the pragmma without the enclosing '{' and '}' */
-		 yytext[strlen(yytext)-2] = '\0';
+		 yytext[strlen(yytext)-1] = '\0';
 		 yylval.ID=strdup(yytext+1);
 		 return pragma_token;
 		}
 <il_st_state>{pragma} {/* return the pragmma without the enclosing '{' and '}' */
-		 yytext[strlen(yytext)-2] = '\0';
+		 yytext[strlen(yytext)-1] = '\0';
 		 yylval.ID=strdup(yytext+1);
 		 return pragma_token;
 		}
@@ -786,6 +786,7 @@
 
 	/* il_st_state -> (il_state | st_state) */
 <il_st_state>{
+{st_whitespace_no_pragma}			/* Eat any whitespace */
 {qualified_identifier}{st_whitespace}":="	unput_text(0); BEGIN(st_state);
 {qualified_identifier}"["			unput_text(0); BEGIN(st_state);
 
@@ -810,7 +811,6 @@
 		 unput_text(0);
 		}
 .		unput_text(0); BEGIN(il_state);
-
 }	/* end of il_st_state lexical parser */
 
 	/* (il_state | st_state) -> $previous_state (decl_state or sfc_state) */
@@ -845,8 +845,8 @@
 	/***************************************/
 	/* NOTE: pragmas are handled right at the beginning... */
 
-<INITIAL,config_state,decl_state,st_state,sfc_state,il_st_state>{st_whitespace_no_pragma}	/* Eat any whitespace */
-<il_state,il_st_state>{il_whitespace_no_pragma}		/* Eat any whitespace */
+<INITIAL,config_state,decl_state,st_state,sfc_state>{st_whitespace_no_pragma}	/* Eat any whitespace */
+<il_state>{il_whitespace_no_pragma}		/* Eat any whitespace */
 
 
 	/*****************************************/
@@ -865,16 +865,28 @@
 	 *       checking whether they may be a 'keyword', is to check whether
 	 *       they have been previously declared as a variable name,
 	 *
-	 *      TODO: how about function names?
+	 *       However, we have a dilema! Should we here also check for
+	 *       prev_declared_derived_function_name_token?
+	 *       If we do, then the 'MOD' default library function (defined in
+	 *       the standard) will always be returned as a function name, and
+	 *       it will therefore not be possible to use it as an operator as 
+	 *       in the following ST expression 'X := Y MOD Z;' !
+	 *       If we don't, then even it will not be possible to use 'MOD'
+	 *       as a funtion as in 'X := MOD(Y, Z);'
+	 *       We solve this by NOT testing for function names here, and
+	 *       handling this function and keyword clash in bison!
 	 */
 {identifier} 	{int token = get_identifier_token(yytext);
 		 if ((token == prev_declared_variable_name_token) ||
+//		     (token == prev_declared_derived_function_name_token) || // DO NOT add this condition!
 		     (token == prev_declared_fb_name_token)) {
 		 /*
 		 if (token != identifier_token)
 		 */
-		 /* NOTE: if we use the above line, then 'MOD' et al must be removed
-		  * from the library_symbol_table as a default function name!
+		 /* NOTE: if we replace the above uncommented conditions with
+                  *       the simple test of (token != identifier_token), then 
+                  *       'MOD' et al must be removed from the 
+                  *       library_symbol_table as a default function name!
 		  */
 		   yylval.ID=strdup(yytext);
 		   return token;
--- a/stage1_2/iec.y	Fri Feb 09 08:26:32 2007 +0100
+++ b/stage1_2/iec.y	Fri Feb 09 19:25:46 2007 +0100
@@ -176,6 +176,12 @@
 
 
 
+%glr-parser
+// %expect-rr 1
+
+
+
+
 %union {
     symbol_c 	*leaf;
     list_c	*list;
@@ -543,6 +549,7 @@
 /* helper symbol for enumerated_value */
 %type  <list>	enumerated_value_list
 %type  <leaf>	enumerated_value
+%type  <leaf>	enumerated_value_without_identifier
 
 %type  <leaf>	array_type_declaration
 %type  <leaf>	array_spec_init
@@ -797,7 +804,6 @@
 /********************************************/
 /* B 1.6 Sequential Function Chart elements */
 /********************************************/
-/* TODO */
 
 %type  <list>	sequential_function_chart
 %type  <list>	sfc_network
@@ -2315,6 +2321,11 @@
 ;
 
 
+enumerated_value_without_identifier:
+  prev_declared_enumerated_type_name '#' any_identifier
+	{$$ = new enumerated_value_c($1, $3);}
+;
+
 
 array_type_declaration:
 /*  array_type_name ':' array_spec_init */
@@ -2524,12 +2535,14 @@
 /* NOTE: To be entirely correct, variable_name should be replacemed by
  *         prev_declared_variable_name | prev_declared_fb_name | prev_declared_global_var_name
  */
-  prev_declared_variable_name
+ identifier
 	{$$ = new symbolic_variable_c($1);}
 | prev_declared_fb_name
 	{$$ = new symbolic_variable_c($1);}
 | prev_declared_global_var_name
 	{$$ = new symbolic_variable_c($1);}
+| prev_declared_variable_name
+	{$$ = new symbolic_variable_c($1);}
 | multi_element_variable
 ;
 
@@ -3662,11 +3675,13 @@
 
 initial_step:
   INITIAL_STEP step_name ':' action_association_list END_STEP
+//  INITIAL_STEP identifier ':' action_association_list END_STEP
 	{$$ = new initial_step_c($2, $4);}
 ;
 
 step:
   STEP step_name ':' action_association_list END_STEP
+//  STEP identifier ':' action_association_list END_STEP
 	{$$ = new step_c($2, $4);}
 ;
 
@@ -3682,7 +3697,8 @@
 ;
 
 
-step_name: identifier;
+// step_name: identifier;
+step_name: any_identifier;
 
 action_association:
   action_name '(' action_qualifier indicator_name_list ')'
@@ -3697,7 +3713,8 @@
 	{$$ = $1; $$->add_element($3);}
 ;
 
-action_name: identifier;
+// action_name: identifier;
+action_name: any_identifier;
 
 action_qualifier:
   /* empty */
@@ -3735,7 +3752,9 @@
 
 indicator_name: variable;
 
-transition_name: identifier;
+// transition_name: identifier;
+transition_name: any_identifier;
+
 
 steps:
   step_name
@@ -3751,14 +3770,17 @@
 	{$$ = $1; $$->add_element($3);}
 ;
 
+
 transition_header:
   TRANSITION FROM steps TO steps
 	{$$.first = NULL; $$.second = NULL; $$.third = $3; $$.fourth = $5; cmd_goto_body_state();}
 | TRANSITION transition_name FROM steps TO steps 
+//| TRANSITION identifier FROM steps TO steps 
 	{$$.first = $2; $$.second = NULL; $$.third = $4; $$.fourth = $6; cmd_goto_body_state();}
 | TRANSITION '(' PRIORITY ASSIGN integer ')' FROM steps TO steps
 	{$$.first = NULL; $$.second = $5; $$.third = $8; $$.fourth = $10; cmd_goto_body_state();}
 | TRANSITION transition_name '(' PRIORITY ASSIGN integer ')' FROM steps TO steps
+//| TRANSITION identifier '(' PRIORITY ASSIGN integer ')' FROM steps TO steps
 	{$$.first = $2; $$.second = $6; $$.third = $9; $$.fourth = $11; cmd_goto_body_state();}
 ;
 
@@ -3781,6 +3803,7 @@
 
 action_header:
   ACTION action_name ':' 
+//  ACTION identifier ':' 
 	{$$.first = $2; cmd_goto_body_state();}
 ;
 
@@ -3925,7 +3948,7 @@
    single_resource_declaration
   END_RESOURCE
 	{$$ = new resource_declaration_c($3, $5, $6, $7);
-         variable_name_symtable.pop();
+	 variable_name_symtable.pop();
 	 variable_name_symtable.insert($3, prev_declared_resource_name_token);
 	}
 ;
@@ -4258,6 +4281,8 @@
 instruction_list:
   il_instruction
 	{$$ = new instruction_list_c(); $$->add_element($1);}
+| pragma eol_list
+	{$$ = new instruction_list_c(); $$->add_element($1);}
 | instruction_list il_instruction
 	{$$ = $1; $$->add_element($2);}
 | instruction_list pragma
@@ -4458,9 +4483,13 @@
 ;
 
 
+/* NOTE: We use enumerated_value_without_identifier instead of enumerated_value
+ *       in order to remove a reduce/reduce conflict between reducing an
+ *       identifier to a variable or an enumerated_value.
+ */
 il_operand:
   variable
-| enumerated_value
+| enumerated_value_without_identifier
 | constant
 ;
 
@@ -4855,10 +4884,14 @@
  *       To remove the conlfict, we only allow constants without
  *       a preceding '-' to be used in primary_expression
  */
+/* NOTE: We use enumerated_value_without_identifier instead of enumerated_value
+ *       in order to remove a reduce/reduce conflict between reducing an
+ *       identifier to a variable or an enumerated_value.
+ */
 primary_expression:
 /* constant */
   non_negative_constant
-| enumerated_value
+| enumerated_value_without_identifier
 | variable
 | '(' expression ')'
 	{$$ = $2;}
@@ -4903,8 +4936,10 @@
 /* B 3.2 Statements */
 /********************/
 statement_list:
-  /* empty */
-	{$$ = new statement_list_c();}
+  statement ';'
+	{$$ = new statement_list_c(); $$->add_element($1);}
+| pragma
+	{$$ = new statement_list_c(); $$->add_element($1);}
 | statement_list statement ';'
 	{$$ = $1; $$->add_element($2);}
 | statement_list pragma
@@ -5058,6 +5093,12 @@
   signed_integer
 | enumerated_value
 | subrange
+/*
+| identifier
+	{$$ = $1;}
+| prev_declared_enumerated_type_name '#' any_identifier
+	{$$ = new enumerated_value_c($1, $3);}
+*/
 ;
 
 
@@ -5090,10 +5131,14 @@
  *
  * Obviously this presuposes that the control_variable
  * must have been declared in some VAR .. END_VAR
- * construct, so I (Mario) changed the syntax to read
+ * We could therefore change the syntax to read
  * control_variable: prev_declared_variable_name;
+ * 
+ * However, it is probaly best if we leave the semantic checks
+ * to the semantic analyser of pass 2.
 */
-control_variable: prev_declared_variable_name {$$ = $1;};
+// control_variable: prev_declared_variable_name {$$ = $1;};
+control_variable: identifier {$$ = $1;};
 
 /* Integrated directly into for_statement */
 /*