# HG changeset patch # User mjsousa # Date 1416684647 0 # Node ID 27063736913fe64553f6540aab85b1f30e616bbf # Parent aca1ab9fcb6d69954af2de0bc57d3fbc7880ff14 Allow variables to be used when declaring the dimension of an array. diff -r aca1ab9fcb6d -r 27063736913f stage1_2/iec_bison.yy --- a/stage1_2/iec_bison.yy Sun Nov 16 15:37:12 2014 +0000 +++ b/stage1_2/iec_bison.yy Sat Nov 22 19:30:47 2014 +0000 @@ -736,6 +736,8 @@ %type subrange_spec_init %type subrange_specification %type subrange +/* A non standard construct, used to support the use of variables in array subranges. e.g.: ARRAY [12..max] OF INT */ +%type subrange_with_var %type enumerated_type_declaration %type enumerated_spec_init @@ -2728,9 +2730,16 @@ ; -subrange: +/* a non standard construct, used to allow the declaration of array subranges using a variable */ +subrange_with_var: signed_integer DOTDOT signed_integer {$$ = new subrange_c($1, $3, locloc(@$));} +| any_identifier DOTDOT signed_integer + {$$ = new subrange_c($1, $3, locloc(@$));} +| signed_integer DOTDOT any_identifier + {$$ = new subrange_c($1, $3, locloc(@$));} +| any_identifier DOTDOT any_identifier + {$$ = new subrange_c($1, $3, locloc(@$));} /* ERROR_CHECK_BEGIN */ | signed_integer signed_integer {$$ = NULL; print_err_msg(locl(@1), locf(@2), "'..' missing between bounds in subrange definition."); yynerrs++;} @@ -2743,6 +2752,23 @@ /* ERROR_CHECK_END */ ; + +subrange: + signed_integer DOTDOT signed_integer + {$$ = new subrange_c($1, $3, locloc(@$));} +/* ERROR_CHECK_BEGIN */ +| signed_integer signed_integer + {$$ = NULL; print_err_msg(locl(@1), locf(@2), "'..' missing between bounds in subrange definition."); yynerrs++;} +| signed_integer DOTDOT error + {$$ = NULL; + if (is_current_syntax_token()) {print_err_msg(locl(@2), locf(@3), "no value defined for upper bound in subrange definition.");} + else {print_err_msg(locf(@3), locl(@3), "invalid value for upper bound in subrange definition."); yyclearin;} + yyerrok; + } +/* ERROR_CHECK_END */ +; + + enumerated_type_declaration: /* enumerated_type_name ':' enumerated_spec_init */ /* NOTE: The 'identifier' used for the name of the new enumerated type is inserted early into the library_element_symtable so it may be used @@ -2924,9 +2950,10 @@ /* helper symbol for array_specification */ array_subrange_list: - subrange +/* the construct 'subrange' has been replaced with 'subrange_with_var' in order to support the declaration of array ranges using a varable: e.g. ARRAY [2..max] OF INT */ + subrange_with_var {$$ = new array_subrange_list_c(locloc(@$)); $$->add_element($1);} -| array_subrange_list ',' subrange +| array_subrange_list ',' subrange_with_var {$$ = $1; $$->add_element($3);} /* ERROR_CHECK_BEGIN */ | array_subrange_list subrange