# HG changeset patch # User Mario de Sousa # Date 1343734744 -3600 # Node ID 0c7663fdc8d319ff12408c699280dbdfbd1a1158 # Parent 509b79602f7c30a37935d311a581f3269a39bce3 Aloow use of SFC STEPs as variables. diff -r 509b79602f7c -r 0c7663fdc8d3 absyntax_utils/search_varfb_instance_type.cc --- a/absyntax_utils/search_varfb_instance_type.cc Sat Jul 28 09:07:55 2012 +0100 +++ b/absyntax_utils/search_varfb_instance_type.cc Tue Jul 31 12:39:04 2012 +0100 @@ -142,8 +142,12 @@ /* What if the variable has not been declared? Then this should not be a compiler error! * However, currently stage 2 of the compiler already detects when variables have not been delcared, * so if the variable's declaration is not found, then that means that we have an internal compiler error! + * + * Actually, the above is not true anymore. See the use of the any_symbolic_variable in iec_bison.yy + * - when defining the delay of a delayed action association in SFC + * - in program connections inside configurations (will this search_varfb_instance_type_c class be called to handle this??) */ - if (NULL == current_type_id) ERROR; + // if (NULL == current_type_id) ERROR; return NULL; } diff -r 509b79602f7c -r 0c7663fdc8d3 stage1_2/iec_bison.yy --- a/stage1_2/iec_bison.yy Sat Jul 28 09:07:55 2012 +0100 +++ b/stage1_2/iec_bison.yy Tue Jul 31 12:39:04 2012 +0100 @@ -5139,7 +5139,9 @@ 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, locloc(@$));} + {$$ = new initial_step_c($2, $4, locloc(@$)); + variable_name_symtable.insert($2, prev_declared_variable_name_token); // A step name may later be used as a structured variable!! + } /* ERROR_CHECK_BEGIN */ | INITIAL_STEP ':' action_association_list END_STEP {$$ = NULL; print_err_msg(locf(@1), locl(@2), "no step name defined in initial step declaration."); yynerrs++;} @@ -5159,7 +5161,9 @@ step: STEP step_name ':' action_association_list END_STEP // STEP identifier ':' action_association_list END_STEP - {$$ = new step_c($2, $4, locloc(@$));} + {$$ = new step_c($2, $4, locloc(@$)); + variable_name_symtable.insert($2, prev_declared_variable_name_token); // A step name may later be used as a structured variable!! + } /* ERROR_CHECK_BEGIN */ | STEP ':' action_association_list END_STEP {$$ = NULL; print_err_msg(locl(@1), locf(@2), "no step name defined in step declaration."); yynerrs++;} @@ -5261,9 +5265,58 @@ | SL {$$ = new timed_qualifier_c(strdup("SL"), locloc(@$));} ; +/* NOTE: A step_name may be used as a structured vaqriable, in order to access the status bit (e.g. Step1.X) + * or the time it has been active (e.g. Step1.T). + * In order to allow the step name to be used as a variable inside ST expressions (only ST expressions ??) + * when defining transitions, we need to add the step_name to the list of previously declared variables. + * This allows the step name to be used as a variable inside all transition expressions, as the user + * can clearly define the transition _after_ the step itself has been defined/declared, so the + * 'variable' is previously 'declared'. + * + * However, when defining/declaring a step, a variable name can also be used to define a timed + * action association. In this case, we may have a circular reference: + * e.g. + * ... + * STEP step1: + * action1 (D,t#100ms); + * end_step + * + * STEP step2: + * action1 (D,step3.T); <---- forward reference to step3.T !!!!!! + * end_step + * + * STEP step3: + * action1 (D,step2.T); <---- back reference to step2.T + * end_step + * + * + * There is no way the user can always use the step3.T variable only after it has + * been 'declared'. So adding the steps to the list of previously declared variables + * when the steps are declared is not a solution to the above situation. + * + * Fortunately, the standard does not allow ST expressions in the above syntax + * (i.e. when defining the delay of a timed actions), but only either a + * Time literal, or a variable. + * This is why we change the definition of action_time from + * action_time: + * duration + * | variable + * ; + * + * to: + * action_time: + * duration + * | any_symbolic_variable + * ; + * + * NOTE that this same problem does not occur with the 'indicator_name': it does not + * make sense to set/indicate a step1.X variable, as these variables are read-only! + */ + action_time: duration -| variable +//| variable + | any_symbolic_variable ; indicator_name: variable; diff -r 509b79602f7c -r 0c7663fdc8d3 stage1_2/iec_flex.ll --- a/stage1_2/iec_flex.ll Sat Jul 28 09:07:55 2012 +0100 +++ b/stage1_2/iec_flex.ll Tue Jul 31 12:39:04 2012 +0100 @@ -1616,8 +1616,8 @@ {fixed_point}ms {yylval.ID=strdup(yytext); yylval.ID[yyleng-2] = '\0'; return fixed_point_ms_token;} _ /* do nothing - eat it up!*/ -\# {/*fprintf(stderr, "poping from time_literal_state (###)\n");*/ yy_pop_state(); return end_interval_token;} -. {ERROR;} +\# {/*fprintf(stderr, "popping from time_literal_state (###)\n");*/ yy_pop_state(); return end_interval_token;} +. {/*fprintf(stderr, "time_literal_state: found invalid character '%s'. Aborting!\n", yytext);*/ ERROR;} \n {ERROR;} } /*******************************/