stage1_2/iec_bison.yy
changeset 876 e2c4f6f4abe2
parent 873 dea39ef02847
child 881 e05d69c1ccb3
child 891 58109ca87903
equal deleted inserted replaced
875:4e7f95fab6d7 876:e2c4f6f4abe2
   354 %token  <ID>	prev_declared_subrange_type_name_token
   354 %token  <ID>	prev_declared_subrange_type_name_token
   355 %token  <ID>	prev_declared_enumerated_type_name_token
   355 %token  <ID>	prev_declared_enumerated_type_name_token
   356 %token  <ID>	prev_declared_array_type_name_token
   356 %token  <ID>	prev_declared_array_type_name_token
   357 %token  <ID>	prev_declared_structure_type_name_token
   357 %token  <ID>	prev_declared_structure_type_name_token
   358 %token  <ID>	prev_declared_string_type_name_token
   358 %token  <ID>	prev_declared_string_type_name_token
       
   359 %token  <ID>	prev_declared_ref_type_name_token  /* defined in IEC 61131-3 v3 */
   359 
   360 
   360 %type  <leaf>	prev_declared_simple_type_name
   361 %type  <leaf>	prev_declared_simple_type_name
   361 %type  <leaf>	prev_declared_subrange_type_name
   362 %type  <leaf>	prev_declared_subrange_type_name
   362 %type  <leaf>	prev_declared_enumerated_type_name
   363 %type  <leaf>	prev_declared_enumerated_type_name
   363 %type  <leaf>	prev_declared_array_type_name
   364 %type  <leaf>	prev_declared_array_type_name
   364 %type  <leaf>	prev_declared_structure_type_name
   365 %type  <leaf>	prev_declared_structure_type_name
   365 %type  <leaf>	prev_declared_string_type_name
   366 %type  <leaf>	prev_declared_string_type_name
       
   367 %type  <leaf>	prev_declared_ref_type_name  /* defined in IEC 61131-3 v3 */
   366 
   368 
   367 %token <ID>	prev_declared_derived_function_name_token
   369 %token <ID>	prev_declared_derived_function_name_token
   368 %token <ID>	prev_declared_derived_function_block_name_token
   370 %token <ID>	prev_declared_derived_function_block_name_token
   369 %token <ID>	prev_declared_program_type_name_token
   371 %token <ID>	prev_declared_program_type_name_token
   370 %type  <leaf>	prev_declared_derived_function_name
   372 %type  <leaf>	prev_declared_derived_function_name
   412 %type <leaf>	en_identifier
   414 %type <leaf>	en_identifier
   413 %type <leaf>	eno_identifier
   415 %type <leaf>	eno_identifier
   414 
   416 
   415 /* Keyword in IEC 61131-3 v3 */
   417 /* Keyword in IEC 61131-3 v3 */
   416 %token	REF
   418 %token	REF
       
   419 %token	REF_TO
   417 
   420 
   418 
   421 
   419 
   422 
   420 /***************************/
   423 /***************************/
   421 /* B 0 - Programming Model */
   424 /* B 0 - Programming Model */
   757 %token END_TYPE
   760 %token END_TYPE
   758 %token ARRAY
   761 %token ARRAY
   759 %token OF
   762 %token OF
   760 %token STRUCT
   763 %token STRUCT
   761 %token END_STRUCT
   764 %token END_STRUCT
       
   765 
       
   766 
       
   767 %type  <leaf>	ref_spec      /* defined in IEC 61131-3 v3 */
       
   768 %type  <leaf>	ref_spec_init /* defined in IEC 61131-3 v3 */
       
   769 %type  <leaf>	ref_type_decl /* defined in IEC 61131-3 v3 */
   762 
   770 
   763 
   771 
   764 
   772 
   765 /*********************/
   773 /*********************/
   766 /* B 1.4 - Variables */
   774 /* B 1.4 - Variables */
  1560 | prev_declared_simple_type_name
  1568 | prev_declared_simple_type_name
  1561 | prev_declared_subrange_type_name
  1569 | prev_declared_subrange_type_name
  1562 | prev_declared_array_type_name
  1570 | prev_declared_array_type_name
  1563 | prev_declared_structure_type_name
  1571 | prev_declared_structure_type_name
  1564 | prev_declared_string_type_name
  1572 | prev_declared_string_type_name
       
  1573 | prev_declared_ref_type_name  /* defined in IEC 61131-3 v3 */
  1565 | prev_declared_derived_function_name
  1574 | prev_declared_derived_function_name
  1566 | prev_declared_derived_function_block_name
  1575 | prev_declared_derived_function_block_name
  1567 | prev_declared_program_type_name
  1576 | prev_declared_program_type_name
  1568 /**/
  1577 /**/
  1569 | prev_declared_resource_name
  1578 | prev_declared_resource_name
  1570 | prev_declared_program_name
  1579 | prev_declared_program_name
  1571 | prev_declared_global_var_name
  1580 | prev_declared_global_var_name
  1572 ;
  1581 ;
  1573 
  1582 
  1574 
  1583 
  1575 prev_declared_variable_name: prev_declared_variable_name_token {$$ = new identifier_c($1, locloc(@$));};
  1584 prev_declared_variable_name       : prev_declared_variable_name_token        {$$ = new identifier_c($1, locloc(@$));};
  1576 prev_declared_fb_name: prev_declared_fb_name_token {$$ = new identifier_c($1, locloc(@$));};
  1585 prev_declared_fb_name             : prev_declared_fb_name_token              {$$ = new identifier_c($1, locloc(@$));};
  1577 
  1586 
  1578 prev_declared_simple_type_name: prev_declared_simple_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1587 prev_declared_simple_type_name    : prev_declared_simple_type_name_token     {$$ = new identifier_c($1, locloc(@$));};
  1579 prev_declared_subrange_type_name: prev_declared_subrange_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1588 prev_declared_subrange_type_name  : prev_declared_subrange_type_name_token   {$$ = new identifier_c($1, locloc(@$));};
  1580 prev_declared_enumerated_type_name: prev_declared_enumerated_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1589 prev_declared_enumerated_type_name: prev_declared_enumerated_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1581 prev_declared_array_type_name: prev_declared_array_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1590 prev_declared_array_type_name     : prev_declared_array_type_name_token      {$$ = new identifier_c($1, locloc(@$));};
  1582 prev_declared_structure_type_name: prev_declared_structure_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1591 prev_declared_structure_type_name : prev_declared_structure_type_name_token  {$$ = new identifier_c($1, locloc(@$));};
  1583 prev_declared_string_type_name: prev_declared_string_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1592 prev_declared_string_type_name    : prev_declared_string_type_name_token     {$$ = new identifier_c($1, locloc(@$));};
  1584 
  1593 prev_declared_ref_type_name       : prev_declared_ref_type_name_token        {$$ = new identifier_c($1, locloc(@$));};  /* defined in IEC 61131-3 v3 */
  1585 prev_declared_derived_function_name: prev_declared_derived_function_name_token {$$ = new identifier_c($1, locloc(@$));};
  1594 
       
  1595 prev_declared_derived_function_name      : prev_declared_derived_function_name_token       {$$ = new identifier_c($1, locloc(@$));};
  1586 prev_declared_derived_function_block_name: prev_declared_derived_function_block_name_token {$$ = new identifier_c($1, locloc(@$));};
  1596 prev_declared_derived_function_block_name: prev_declared_derived_function_block_name_token {$$ = new identifier_c($1, locloc(@$));};
  1587 prev_declared_program_type_name: prev_declared_program_type_name_token {$$ = new identifier_c($1, locloc(@$));};
  1597 prev_declared_program_type_name          : prev_declared_program_type_name_token           {$$ = new identifier_c($1, locloc(@$));};
  1588 
  1598 
  1589 
  1599 
  1590 
  1600 
  1591 /***************************/
  1601 /***************************/
  1592 /* B 0 - Programming Model */
  1602 /* B 0 - Programming Model */
  2480 derived_type_name:
  2490 derived_type_name:
  2481   single_element_type_name
  2491   single_element_type_name
  2482 | prev_declared_array_type_name
  2492 | prev_declared_array_type_name
  2483 | prev_declared_structure_type_name
  2493 | prev_declared_structure_type_name
  2484 | prev_declared_string_type_name
  2494 | prev_declared_string_type_name
       
  2495 | prev_declared_ref_type_name  /* as defined in IEC 61131-3 v3 */
  2485 ;
  2496 ;
  2486 
  2497 
  2487 single_element_type_name:
  2498 single_element_type_name:
  2488   prev_declared_simple_type_name
  2499   prev_declared_simple_type_name
  2489 /* Include the following if arrays of function blocks are to be allowed!
  2500 /* Include the following if arrays of function blocks are to be allowed!
  2551 
  2562 
  2552 single_element_type_declaration:
  2563 single_element_type_declaration:
  2553   simple_type_declaration
  2564   simple_type_declaration
  2554 | subrange_type_declaration
  2565 | subrange_type_declaration
  2555 | enumerated_type_declaration
  2566 | enumerated_type_declaration
       
  2567 | ref_type_decl  /* defined in IEC 61131-3 v3 */
  2556 ;
  2568 ;
  2557 
  2569 
  2558 simple_type_declaration:
  2570 simple_type_declaration:
  2559 /*  simple_type_name ':' simple_spec_init */
  2571 /*  simple_type_name ':' simple_spec_init */
  2560 /* To understand why simple_spec_init was brocken up into its consituent components in the following rules, please see note in the definition of 'enumerated_type_declaration'. */
  2572 /* To understand why simple_spec_init was brocken up into its consituent components in the following rules, please see note in the definition of 'enumerated_type_declaration'. */
  3154   /* empty */
  3166   /* empty */
  3155 	{$$ = NULL;}
  3167 	{$$ = NULL;}
  3156 | ASSIGN character_string
  3168 | ASSIGN character_string
  3157 	{$$ = $2;}
  3169 	{$$ = $2;}
  3158 ;
  3170 ;
       
  3171 
       
  3172 
       
  3173 /* Taken fron IEC 61131-3 v3
       
  3174  * // Table 14 - Reference operations
       
  3175  * Ref_Type_Decl  : Ref_Type_Name ':' Ref_Spec_Init ;
       
  3176  * Ref_Spec_Init  : Ref_Spec ( ':=' Ref_Value )? ;
       
  3177  * Ref_Spec       : 'REF_TO' Non_Gen_Type_Name ;
       
  3178  * Ref_Type_Name  : Identifier ;
       
  3179  * Ref_Name       : Identifier ;
       
  3180  * Ref_Value      : Ref_Addr | 'NULL' ;
       
  3181  * Ref_Addr       : 'REF' '(' (Symbolic_Variable | FB_Name | Class_Instance_Name ) ')' ;
       
  3182  * Ref_Assign     : Ref_Name ':=' (Ref_Name | Ref_Deref | Ref_Value ) ;
       
  3183  * Ref_Deref      : 'DREF' '(' Ref_Name ')' ;
       
  3184  */
       
  3185 
       
  3186 /* NOTE: in IEC 61131-3 v3, the formal syntax definition does not define non_generic_type_name to include FB type names.
       
  3187  *       However, in section "6.3.4.10 References", example 4 includes a  REF_TO a FB type!
       
  3188  *       We have therefore explicitly added the "REF_TO function_block_type_name" to this rule!
       
  3189  */
       
  3190 ref_spec: /* defined in IEC 61131-3 v3 */
       
  3191   REF_TO non_generic_type_name
       
  3192 	{$$ = new ref_spec_c($2, locloc(@$));}
       
  3193 | REF_TO function_block_type_name
       
  3194 	{$$ = new ref_spec_c($2, locloc(@$));}
       
  3195 /* The following line is actually not included in IEC 61131-3, but we add it anyway otherwise it will not be possible to
       
  3196  * define a REF_TO datatype as an alias to an already previously declared REF_TO datatype.
       
  3197  * For example:
       
  3198  *       TYPE
       
  3199  *          ref1: REF_TO INT;
       
  3200  *          ref2: ref1;    <-- without the following rule, this would not be allowed!!
       
  3201  *       END_TYPE
       
  3202  *
       
  3203  * This extra rule also makes it possible to declare variables using a previously declared REF_TO datatype
       
  3204  *  For example:
       
  3205  *     VAR  refvar: ref1; END_VAR
       
  3206  */
       
  3207 | prev_declared_ref_type_name 
       
  3208 ;
       
  3209 
       
  3210 
       
  3211 ref_spec_init: /* defined in IEC 61131-3 v3 */
       
  3212   ref_spec  /* For the moment, we do not support initialising reference data types */
       
  3213 ;
       
  3214 
       
  3215 ref_type_decl:  /* defined in IEC 61131-3 v3 */
       
  3216   identifier ':' ref_spec_init
       
  3217 	{$$ = new ref_type_decl_c($1, $3, locloc(@$));
       
  3218 	 library_element_symtable.insert($1, prev_declared_ref_type_name_token);
       
  3219 	}
       
  3220 ;
       
  3221 
  3159 
  3222 
  3160 
  3223 
  3161 
  3224 
  3162 /*********************/
  3225 /*********************/
  3163 /* B 1.4 - Variables */
  3226 /* B 1.4 - Variables */
  3498 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3561 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3499 | var1_list ':' subrange_spec_init
  3562 | var1_list ':' subrange_spec_init
  3500 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3563 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3501 | var1_list ':' enumerated_spec_init
  3564 | var1_list ':' enumerated_spec_init
  3502 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3565 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
       
  3566 | var1_list ':' ref_spec_init   /* defined in IEC 61131-3 v3   (REF_TO ...)*/
       
  3567 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3503 /* ERROR_CHECK_BEGIN */
  3568 /* ERROR_CHECK_BEGIN */
  3504 | var1_list simple_spec_init
  3569 | var1_list simple_spec_init
  3505 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and simple specification."); yynerrs++;}
  3570 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and simple specification."); yynerrs++;}
  3506 | var1_list subrange_spec_init
  3571 | var1_list subrange_spec_init
  3507 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and subrange specification."); yynerrs++;}
  3572 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and subrange specification."); yynerrs++;}
  3817 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3882 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3818 | var1_list ':' subrange_specification
  3883 | var1_list ':' subrange_specification
  3819 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3884 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3820 | var1_list ':' enumerated_specification
  3885 | var1_list ':' enumerated_specification
  3821 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3886 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
       
  3887 | var1_list ':' ref_spec   /* defined in IEC 61131-3 v3   (REF_TO ...)*/
       
  3888 	{$$ = new var1_init_decl_c($1, $3, locloc(@$));}
  3822 /* ERROR_CHECK_BEGIN */
  3889 /* ERROR_CHECK_BEGIN */
  3823 | var1_list simple_specification
  3890 | var1_list simple_specification
  3824 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and simple specification."); yynerrs++;}
  3891 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and simple specification."); yynerrs++;}
  3825 | var1_list subrange_specification
  3892 | var1_list subrange_specification
  3826 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and subrange specification."); yynerrs++;}
  3893 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between variable list and subrange specification."); yynerrs++;}
  4043 | global_var_name ':' prev_declared_structure_type_name
  4110 | global_var_name ':' prev_declared_structure_type_name
  4044 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  4111 	{$$ = new external_declaration_c($1, $3, locloc(@$));
  4045 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  4112 	 variable_name_symtable.insert($1, prev_declared_variable_name_token);
  4046 	}
  4113 	}
  4047 | global_var_name ':' function_block_type_name
  4114 | global_var_name ':' function_block_type_name
       
  4115 	{$$ = new external_declaration_c($1, new fb_spec_init_c($3, NULL, locloc(@3)), locloc(@$));
       
  4116 	 variable_name_symtable.insert($1, prev_declared_fb_name_token);
       
  4117 	}
       
  4118 | global_var_name ':' ref_spec /* defined in IEC 61131-3 v3   (REF_TO ...)*/
  4048 	{$$ = new external_declaration_c($1, new fb_spec_init_c($3, NULL, locloc(@3)), locloc(@$));
  4119 	{$$ = new external_declaration_c($1, new fb_spec_init_c($3, NULL, locloc(@3)), locloc(@$));
  4049 	 variable_name_symtable.insert($1, prev_declared_fb_name_token);
  4120 	 variable_name_symtable.insert($1, prev_declared_fb_name_token);
  4050 	}
  4121 	}
  4051 /* ERROR_CHECK_BEGIN */
  4122 /* ERROR_CHECK_BEGIN */
  4052 | global_var_name simple_specification
  4123 | global_var_name simple_specification
  4174 | enumerated_spec_init
  4245 | enumerated_spec_init
  4175 | array_spec_init
  4246 | array_spec_init
  4176 | initialized_structure
  4247 | initialized_structure
  4177 | single_byte_string_spec
  4248 | single_byte_string_spec
  4178 | double_byte_string_spec
  4249 | double_byte_string_spec
       
  4250 | ref_spec_init /* defined in IEC 61131-3 v3 (REF_TO ...) */
  4179 ;
  4251 ;
  4180 
  4252 
  4181 
  4253 
  4182 location:
  4254 location:
  4183   AT direct_variable_token
  4255   AT direct_variable_token