Adding support for EN/ENO parameters in bison rules
authorlbessard
Mon, 15 Sep 2008 13:36:24 +0200
changeset 143 73372bdeeffb
parent 142 120772c527f3
child 144 0ee0055a8ffe
Adding support for EN/ENO parameters in bison rules
absyntax/absyntax.def
stage1_2/iec.y
stage4/generate_iec/generate_iec.cc
--- a/absyntax/absyntax.def	Mon Sep 08 10:34:24 2008 +0200
+++ b/absyntax/absyntax.def	Mon Sep 15 13:36:24 2008 +0200
@@ -37,12 +37,15 @@
  */
 
 
+/* EN/ENO */
+SYM_REF0(en_param_c)
+SYM_REF0(eno_param_c)
+
 /***************************/
 /* 2.1.6 - Pragmas */
 /***************************/
 SYM_TOKEN(pragma_c)
 
-
 /***************************/
 /* B 0 - Programming Model */
 /***************************/
@@ -800,6 +803,9 @@
 SYM_REF0(JMPC_operator_c)
 SYM_REF0(JMPCN_operator_c)
 
+/*  any_identifier ASSIGN */
+SYM_REF1(il_assign_operator_c, variable_name)
+
 /*| [NOT] any_identifier SENDTO */
 SYM_REF2(il_assign_out_operator_c, option, variable_name)
 
@@ -847,6 +853,7 @@
 /*****************************************/
 /* B 3.2.2 Subprogram Control Statements */
 /*****************************************/
+
 /*  RETURN */
 SYM_REF0(return_statement_c)
 
--- a/stage1_2/iec.y	Mon Sep 08 10:34:24 2008 +0200
+++ b/stage1_2/iec.y	Mon Sep 15 13:36:24 2008 +0200
@@ -272,6 +272,8 @@
 /* TODO: get the syntax parser to handle these tokens... */
 %token	EN
 %token	ENO
+%type <leaf>	en_param
+%type <leaf>	eno_param
 
 
 
@@ -1305,6 +1307,15 @@
 pragma:
   pragma_token	{$$ = new pragma_c($1, locloc(@$));}
 
+/* EN/ENO */
+en_param:
+  EN	{$$ = new en_param_c(locloc(@$));}
+;
+
+eno_param:
+  ENO	{$$ = new eno_param_c(locloc(@$));}
+;
+
 
 
 /* NOTE:
@@ -6386,6 +6397,9 @@
 il_assign_operator:
 /*  variable_name ASSIGN */
   any_identifier ASSIGN
+	{$$ = new il_assign_operator_c($1, locloc(@$));}
+| en_param ASSIGN
+	{$$ = new il_assign_operator_c($1, locloc(@$));}
 /* ERROR_CHECK_BEGIN */
 | error ASSIGN
   {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid parameter defined in parameter assignment."); yyerrok;}
@@ -6398,9 +6412,13 @@
 /*  any_identifier SENDTO */
   sendto_identifier SENDTO
 	{$$ = new il_assign_out_operator_c(NULL, $1, locloc(@$));}
+| eno_param SENDTO
+	{$$ = new il_assign_out_operator_c(NULL, $1, locloc(@$));}
 /*| NOT variable_name SENDTO */
 | NOT sendto_identifier SENDTO
 	{$$ = new il_assign_out_operator_c(new not_paramassign_c(locloc(@1)), $2, locloc(@$));}
+| NOT eno_param SENDTO
+	{$$ = new il_assign_out_operator_c(new not_paramassign_c(locloc(@1)), $2, locloc(@$));}
 /* ERROR_CHECK_BEGIN */
 | error SENDTO
   {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid parameter defined in parameter out assignment."); yyerrok;}
@@ -6815,7 +6833,6 @@
 | return_statement
 ;
 
-
 return_statement:
   RETURN	{$$ = new return_statement_c(locloc(@$));}
 ;
@@ -6920,14 +6937,20 @@
 param_assignment_formal:
   any_identifier ASSIGN expression
 	{$$ = new input_variable_param_assignment_c($1, $3, locloc(@$));}
+| en_param ASSIGN expression
+	{$$ = new input_variable_param_assignment_c($1, $3, locloc(@$));}
 /*| variable_name SENDTO variable */
 /*| any_identifier SENDTO variable */
 | sendto_identifier SENDTO variable
-	{$$ = new output_variable_param_assignment_c(NULL,$1, $3, locloc(@$));}
+	{$$ = new output_variable_param_assignment_c(NULL, $1, $3, locloc(@$));}
+| eno_param SENDTO variable
+	{$$ = new output_variable_param_assignment_c(NULL, $1, $3, locloc(@$));}
 /*| NOT variable_name SENDTO variable */
 /*| NOT any_identifier SENDTO variable*/
 | NOT sendto_identifier SENDTO variable
-	{$$ = new output_variable_param_assignment_c(new not_paramassign_c(locloc(@$)),$2, $4, locloc(@$));}
+	{$$ = new output_variable_param_assignment_c(new not_paramassign_c(locloc(@$)), $2, $4, locloc(@$));}
+| NOT eno_param SENDTO variable
+	{$$ = new output_variable_param_assignment_c(new not_paramassign_c(locloc(@$)), $2, $4, locloc(@$));}
 /* ERROR_CHECK_BEGIN */
 | any_identifier ASSIGN error
   {$$ = NULL;
@@ -6935,12 +6958,24 @@
 	 else {print_err_msg(locf(@3), locl(@3), "invalid expression in ST formal parameter assignment."); yyclearin;}
 	 yyerrok;
 	}
+| en_param ASSIGN error
+  {$$ = NULL;
+	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no expression defined in ST formal parameter assignment.");}
+	 else {print_err_msg(locf(@3), locl(@3), "invalid expression in ST formal parameter assignment."); yyclearin;}
+	 yyerrok;
+	}
 | sendto_identifier SENDTO error
   {$$ = NULL;
 	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no expression defined in ST formal parameter out assignment.");}
 	 else {print_err_msg(locf(@3), locl(@3), "invalid expression in ST formal parameter out assignment."); yyclearin;}
 	 yyerrok;
 	}
+| eno_param SENDTO error
+  {$$ = NULL;
+	 if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no expression defined in ST formal parameter out assignment.");}
+	 else {print_err_msg(locf(@3), locl(@3), "invalid expression in ST formal parameter out assignment."); yyclearin;}
+	 yyerrok;
+	}
 | NOT SENDTO variable
   {$$ = NULL; print_err_msg(locl(@1), locf(@2), "no parameter name defined in ST formal parameter out negated assignment."); yynerrs++;}
 | NOT error SENDTO variable
@@ -6951,6 +6986,12 @@
 	 else {print_err_msg(locf(@4), locl(@4), "invalid expression in ST formal parameter out negated assignment."); yyclearin;}
 	 yyerrok;
 	}
+| NOT eno_param SENDTO error
+  {$$ = NULL;
+	 if (is_current_syntax_token()) {print_err_msg(locl(@3), locf(@4), "no expression defined in ST formal parameter out negated assignment.");}
+	 else {print_err_msg(locf(@4), locl(@4), "invalid expression in ST formal parameter out negated assignment."); yyclearin;}
+	 yyerrok;
+	}
 /* ERROR_CHECK_END */
 ;
 
--- a/stage4/generate_iec/generate_iec.cc	Mon Sep 08 10:34:24 2008 +0200
+++ b/stage4/generate_iec/generate_iec.cc	Mon Sep 15 13:36:24 2008 +0200
@@ -120,6 +120,18 @@
 
 
   public:
+
+/*  EN/ENO */
+void *visit(en_param_c *symbol) {
+  s4o.print("EN");
+  return NULL;
+}
+
+void *visit(eno_param_c *symbol) {
+  s4o.print("ENO");
+  return NULL;
+}
+
 /***************************/
 /* 2.1.6 Pragmas */
 /***************************/
@@ -1617,6 +1629,13 @@
 void *visit(JMPC_operator_c *symbol) {s4o.print("JMPC "); return NULL;}
 void *visit(JMPCN_operator_c *symbol) {s4o.print("JMPCN "); return NULL;}
 
+/*| any_identifier ASSIGN */
+void *visit(il_assign_operator_c *symbol) {
+  symbol->variable_name->accept(*this);
+  s4o.print(" := ");
+  return NULL;
+}
+
 /*| [NOT] any_identifier SENDTO */
 void *visit(il_assign_out_operator_c *symbol) {
   if (symbol->option != NULL)
@@ -1676,6 +1695,7 @@
 /*****************************************/
 /* B 3.2.2 Subprogram Control Statements */
 /*****************************************/
+
 /*  RETURN */
 void *visit(return_statement_c *symbol) {
   s4o.print("RETURN");