2547 | enumerated_type_declaration |
2547 | enumerated_type_declaration |
2548 ; |
2548 ; |
2549 |
2549 |
2550 simple_type_declaration: |
2550 simple_type_declaration: |
2551 /* simple_type_name ':' simple_spec_init */ |
2551 /* simple_type_name ':' simple_spec_init */ |
2552 identifier ':' simple_spec_init |
2552 /* 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'. */ |
2553 {$$ = new simple_type_declaration_c($1, $3, locloc(@$)); |
2553 identifier ':' simple_specification {library_element_symtable.insert($1, prev_declared_simple_type_name_token);} |
2554 library_element_symtable.insert($1, prev_declared_simple_type_name_token); |
2554 {$$ = new simple_type_declaration_c($1, $3, locloc(@$));} |
2555 } |
2555 | identifier ':' elementary_type_name {library_element_symtable.insert($1, prev_declared_simple_type_name_token);} ASSIGN constant |
|
2556 {$$ = new simple_type_declaration_c($1, new simple_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));} |
|
2557 | identifier ':' prev_declared_simple_type_name {library_element_symtable.insert($1, prev_declared_simple_type_name_token);} ASSIGN constant |
|
2558 {$$ = new simple_type_declaration_c($1, new simple_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));} |
2556 /* ERROR_CHECK_BEGIN */ |
2559 /* ERROR_CHECK_BEGIN */ |
2557 | error ':' simple_spec_init |
2560 | error ':' simple_spec_init |
2558 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for data type declaration.");yyerrok;} |
2561 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for data type declaration.");yyerrok;} |
2559 | identifier simple_spec_init |
2562 | identifier simple_spec_init |
2560 {$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between data type name and specification in simple type declaration."); yynerrs++;} |
2563 {$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between data type name and specification in simple type declaration."); yynerrs++;} |
2685 /* ERROR_CHECK_END */ |
2688 /* ERROR_CHECK_END */ |
2686 ; |
2689 ; |
2687 |
2690 |
2688 enumerated_type_declaration: |
2691 enumerated_type_declaration: |
2689 /* enumerated_type_name ':' enumerated_spec_init */ |
2692 /* enumerated_type_name ':' enumerated_spec_init */ |
2690 identifier ':' enumerated_spec_init |
2693 /* 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 |
2691 {$$ = new enumerated_type_declaration_c($1, $3, locloc(@$)); |
2694 * in defining the default initial value of this type, using the fully qualified enumerated constant syntax: type_name#enum_value |
2692 library_element_symtable.insert($1, prev_declared_enumerated_type_name_token); |
2695 * In other words, this allows us to correclty parse the following IEC 61131-3 code: |
2693 } |
2696 * TYPE enum_t : (x1, x2, x3) := enum_t#x3; END_TYPE |
|
2697 * ^^^^^^^ |
|
2698 * |
|
2699 * However, we can only introduce it after we are sure we are parsing an enumerated_spec. For this reason, instead of using the |
|
2700 * symbol enumerated_spec_init in this rule, we decompose it here instead! |
|
2701 * |
|
2702 * If it were not for the above, we could use the rule |
|
2703 * identifier ':' enumerated_spec_init |
|
2704 * and include the library_element_symtable.insert(...) code in the rule actions! |
|
2705 */ |
|
2706 identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} |
|
2707 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$));} |
|
2708 | identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} ASSIGN enumerated_value |
|
2709 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));} |
2694 /* ERROR_CHECK_BEGIN */ |
2710 /* ERROR_CHECK_BEGIN */ |
2695 | error ':' enumerated_spec_init |
2711 | error ':' enumerated_spec_init |
2696 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for enumerated type declaration."); yyerrok;} |
2712 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for enumerated type declaration."); yyerrok;} |
2697 | identifier enumerated_spec_init |
2713 | identifier enumerated_spec_init |
2698 {$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between data type name and specification in enumerated type declaration."); yynerrs++;} |
2714 {$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing between data type name and specification in enumerated type declaration."); yynerrs++;} |