diff -r 08097122a922 -r b0a43002dcac stage1_2/iec.y --- a/stage1_2/iec.y Tue Oct 23 10:28:50 2007 +0200 +++ b/stage1_2/iec.y Tue Oct 23 10:33:09 2007 +0200 @@ -79,6 +79,7 @@ /* file with declaration of token constants. Generated by bison! */ // #include "iec.y.hh" +/* The interface through which bison and flex interact. */ #include "stage1_2_priv.hh" @@ -103,6 +104,16 @@ } + +/* Macros used to pass the line and column locations when + * creating a new object for the abstract syntax tree. + */ +#define locloc(foo) foo.first_line, foo.first_column, foo.last_line, foo.last_column +#define locf(foo) foo.first_line, foo.first_column +#define locl(foo) foo.last_line, foo.last_column + + + /* A macro for printing out internal parser errors... */ #define ERROR error_exit(__FILE__,__LINE__) /* function defined in main.cc */ @@ -173,7 +184,21 @@ */ } - +/* + TODO: DO we need to define a destructor do free + memory when recovering from errors, or do the + class destructors already handle this? + Following is example on how to define + detructors, using the syntax: + %destructor { CODE } SYMBOLS +%union + { + char *string; + } + %token STRING + %type string + %destructor { free ($$); } STRING string +*/ @@ -200,15 +225,7 @@ %token BOGUS_TOKEN_ID - -%{ -/* The interface through which bison and flex interact. */ -/* May only be included after the definition of BOGUS_TOKEN_ID */ -#include "stage1_2_priv.hh" -%} - - -%type start +%type start %type any_identifier @@ -709,7 +726,7 @@ /***********************/ /* B 1.5.1 - Functions */ /***********************/ -//%type function_name +// %type function_name /* helper symbol for IL language */ %type function_name_no_clashes %type function_name_simpleop_clashes @@ -1273,7 +1290,7 @@ /* the pragmas... */ pragma: - pragma_token {$$ = new pragma_c($1);} + pragma_token {$$ = new pragma_c($1, locloc(@$));} @@ -1338,19 +1355,19 @@ -prev_declared_variable_name: prev_declared_variable_name_token {$$ = new identifier_c($1);}; -prev_declared_fb_name: prev_declared_fb_name_token {$$ = new identifier_c($1);}; - -prev_declared_simple_type_name: prev_declared_simple_type_name_token {$$ = new identifier_c($1);}; -prev_declared_subrange_type_name: prev_declared_subrange_type_name_token {$$ = new identifier_c($1);}; -prev_declared_enumerated_type_name: prev_declared_enumerated_type_name_token {$$ = new identifier_c($1);}; -prev_declared_array_type_name: prev_declared_array_type_name_token {$$ = new identifier_c($1);}; -prev_declared_structure_type_name: prev_declared_structure_type_name_token {$$ = new identifier_c($1);}; -prev_declared_string_type_name: prev_declared_string_type_name_token {$$ = new identifier_c($1);}; - -prev_declared_derived_function_name: prev_declared_derived_function_name_token {$$ = new identifier_c($1);}; -prev_declared_derived_function_block_name: prev_declared_derived_function_block_name_token {$$ = new identifier_c($1);}; -prev_declared_program_type_name: prev_declared_program_type_name_token {$$ = new identifier_c($1);}; +prev_declared_variable_name: prev_declared_variable_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_fb_name: prev_declared_fb_name_token {$$ = new identifier_c($1, locloc(@$));}; + +prev_declared_simple_type_name: prev_declared_simple_type_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_subrange_type_name: prev_declared_subrange_type_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_enumerated_type_name: prev_declared_enumerated_type_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_array_type_name: prev_declared_array_type_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_structure_type_name: prev_declared_structure_type_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_string_type_name: prev_declared_string_type_name_token {$$ = new identifier_c($1, locloc(@$));}; + +prev_declared_derived_function_name: prev_declared_derived_function_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_derived_function_block_name: prev_declared_derived_function_block_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_program_type_name: prev_declared_program_type_name_token {$$ = new identifier_c($1, locloc(@$));}; @@ -1369,8 +1386,7 @@ {$$ = $1; $$->add_element($2);} | library error {$$ = NULL; - print_err_msg(current_filename, @2.last_line, "unknown error."); - /* yychar */ + print_err_msg(current_filename, @2.first_line, "unknown error."); yyerrok; } ; @@ -1495,15 +1511,15 @@ */ identifier: - identifier_token {$$ = new identifier_c($1);} + identifier_token {$$ = new identifier_c($1, locloc(@$));} /* Make sure that all tokens (names) not defined as keywords are included here... * I (Mario) have already done this, but if any changes are made to this file, * this list MUST be kept consistent!! */ /**/ -| PRIORITY {$$ = new identifier_c(strdup("PRIORITY"));} -| SINGLE {$$ = new identifier_c(strdup("SINGLE"));} -| INTERVAL {$$ = new identifier_c(strdup("INTERVAL"));} +| PRIORITY {$$ = new identifier_c(strdup("PRIORITY"), locloc(@$));} +| SINGLE {$$ = new identifier_c(strdup("SINGLE"), locloc(@$));} +| INTERVAL {$$ = new identifier_c(strdup("INTERVAL"), locloc(@$));} /**/ | LD_operator {$$ = il_operator_c_2_identifier_c($1);} | LDN_operator {$$ = il_operator_c_2_identifier_c($1);} @@ -1667,14 +1683,14 @@ * real: real_token | fixed_point_token */ real: - real_token {$$ = new real_c($1);} -| fixed_point_token {$$ = new real_c($1);} -; - -integer: integer_token {$$ = new integer_c($1);}; -binary_integer: binary_integer_token {$$ = new binary_integer_c($1);}; -octal_integer: octal_integer_token {$$ = new octal_integer_c($1);}; -hex_integer: hex_integer_token {$$ = new hex_integer_c($1);}; + real_token {$$ = new real_c($1, locloc(@$));} +| fixed_point_token {$$ = new real_c($1, locloc(@$));} +; + +integer: integer_token {$$ = new integer_c($1, locloc(@$));}; +binary_integer: binary_integer_token {$$ = new binary_integer_c($1, locloc(@$));}; +octal_integer: octal_integer_token {$$ = new octal_integer_c($1, locloc(@$));}; +hex_integer: hex_integer_token {$$ = new hex_integer_c($1, locloc(@$));}; numeric_literal: integer_literal @@ -1690,13 +1706,13 @@ integer_literal: integer_type_name '#' signed_integer - {$$ = new integer_literal_c($1, $3);} + {$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));} | integer_type_name '#' binary_integer - {$$ = new integer_literal_c($1, $3);} + {$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));} | integer_type_name '#' octal_integer - {$$ = new integer_literal_c($1, $3);} + {$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));} | integer_type_name '#' hex_integer - {$$ = new integer_literal_c($1, $3);} + {$$ = new integer_literal_c($1, $3, locf(@1), locl(@3));} /* NOTE: see note in the definition of constant for reason * why signed_integer, binary_integer, octal_integer * and hex_integer are missing here! @@ -1706,7 +1722,7 @@ signed_integer: integer | '+' integer {$$ = $2;} -| '-' integer {$$ = new neg_expression_c($2);} +| '-' integer {$$ = new neg_expression_c($2, locloc(@$));} ; /* a helper symbol for non_negative_constant */ @@ -1722,20 +1738,20 @@ real_literal: signed_real | real_type_name '#' signed_real - {$$ = new real_literal_c($1, $3);} + {$$ = new real_literal_c($1, $3, locf(@1), locl(@3));} ; /* helper symbol for non_negative_numeric_literal */ non_negative_real_literal: non_negative_signed_real | real_type_name '#' signed_real - {$$ = new real_literal_c($1, $3);} + {$$ = new real_literal_c($1, $3, locf(@1), locl(@3));} ; signed_real: real | '+' real {$$ = $2;} -| '-' real {$$ = new neg_expression_c($2);} +| '-' real {$$ = new neg_expression_c($2, locloc(@2));} ; /* helper symbol for non_negative_real_literal */ @@ -1747,13 +1763,13 @@ bit_string_literal: bit_string_type_name '#' integer /* i.e. unsigned_integer */ - {$$ = new bit_string_literal_c($1, $3);} + {$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));} | bit_string_type_name '#' binary_integer - {$$ = new bit_string_literal_c($1, $3);} + {$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));} | bit_string_type_name '#' octal_integer - {$$ = new bit_string_literal_c($1, $3);} + {$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));} | bit_string_type_name '#' hex_integer - {$$ = new bit_string_literal_c($1, $3);} + {$$ = new bit_string_literal_c($1, $3, locf(@1), locl(@3));} /* NOTE: see note in the definition of constant for reason * why unsigned_integer, binary_integer, octal_integer * and hex_integer are missing here! @@ -1767,10 +1783,12 @@ boolean_literal: - TRUE {$$ = new boolean_literal_c(new bool_type_name_c(), - new boolean_true_c());} -| FALSE {$$ = new boolean_literal_c(new bool_type_name_c(), - new boolean_false_c());} + TRUE {$$ = new boolean_literal_c(new bool_type_name_c(locloc(@$)), + new boolean_true_c(locloc(@$)), + locloc(@$));} +| FALSE {$$ = new boolean_literal_c(new bool_type_name_c(locloc(@$)), + new boolean_false_c(locloc(@$)), + locloc(@$));} /* | BOOL '#' '1' {} | BOOL '#' '0' {} @@ -1810,10 +1828,10 @@ /*******************************/ /* Transform the tokens given us by flex into leafs */ single_byte_character_string: single_byte_character_string_token - {$$ = new single_byte_character_string_c($1);}; + {$$ = new single_byte_character_string_c($1, locloc(@$));}; double_byte_character_string: double_byte_character_string_token - {$$ = new double_byte_character_string_c($1);}; + {$$ = new double_byte_character_string_c($1, locloc(@$));}; character_string: @@ -1852,13 +1870,13 @@ * when it comes across 'T#' */ TIME '#' interval - {$$ = new duration_c(NULL, $3);} + {$$ = new duration_c(NULL, $3, locloc(@$));} | TIME '#' '-' interval - {$$ = new duration_c(new neg_time_c(), $4);} + {$$ = new duration_c(new neg_time_c(locloc(@$)), $4, locloc(@$));} | T_SHARP interval - {$$ = new duration_c(NULL, $2);} + {$$ = new duration_c(NULL, $2, locloc(@$));} | T_SHARP '-' interval - {$$ = new duration_c(new neg_time_c(), $3);} + {$$ = new duration_c(new neg_time_c(locloc(@$)), $3, locloc(@$));} ; @@ -1870,46 +1888,46 @@ | milliseconds ; -integer_d: integer_d_token {$$ = new integer_c($1);}; -integer_h: integer_h_token {$$ = new integer_c($1);}; -integer_m: integer_m_token {$$ = new integer_c($1);}; -integer_s: integer_s_token {$$ = new integer_c($1);}; -integer_ms: integer_ms_token {$$ = new integer_c($1);}; +integer_d: integer_d_token {$$ = new integer_c($1, locloc(@$));}; +integer_h: integer_h_token {$$ = new integer_c($1, locloc(@$));}; +integer_m: integer_m_token {$$ = new integer_c($1, locloc(@$));}; +integer_s: integer_s_token {$$ = new integer_c($1, locloc(@$));}; +integer_ms: integer_ms_token {$$ = new integer_c($1, locloc(@$));}; fixed_point_d: fixed_point_d_token - {$$ = new fixed_point_c($1);} + {$$ = new fixed_point_c($1, locloc(@$));} | integer_d ; fixed_point_h: fixed_point_h_token - {$$ = new fixed_point_c($1);} + {$$ = new fixed_point_c($1, locloc(@$));} | integer_h ; fixed_point_m: fixed_point_m_token - {$$ = new fixed_point_c($1);} + {$$ = new fixed_point_c($1, locloc(@$));} | integer_m ; fixed_point_s: fixed_point_s_token - {$$ = new fixed_point_c($1);} + {$$ = new fixed_point_c($1, locloc(@$));} | integer_s ; fixed_point_ms: fixed_point_ms_token - {$$ = new fixed_point_c($1);} + {$$ = new fixed_point_c($1, locloc(@$));} | integer_ms ; fixed_point: fixed_point_token - {$$ = new fixed_point_c($1);} + {$$ = new fixed_point_c($1, locloc(@$));} | integer ; @@ -1917,52 +1935,52 @@ days: /* fixed_point ('d') */ fixed_point_d - {$$ = new days_c($1, NULL);} + {$$ = new days_c($1, NULL, locloc(@$));} /*| integer ('d') ['_'] hours */ | integer_d hours - {$$ = new days_c($1, $2);} + {$$ = new days_c($1, $2, locloc(@$));} | integer_d '_' hours - {$$ = new days_c($1, $3);} + {$$ = new days_c($1, $3, locloc(@$));} ; hours: /* fixed_point ('h') */ fixed_point_h - {$$ = new hours_c($1, NULL);} + {$$ = new hours_c($1, NULL, locloc(@$));} /*| integer ('h') ['_'] minutes */ | integer_h minutes - {$$ = new hours_c($1, $2);} + {$$ = new hours_c($1, $2, locloc(@$));} | integer_h '_' minutes - {$$ = new hours_c($1, $3);} + {$$ = new hours_c($1, $3, locloc(@$));} ; minutes: /* fixed_point ('m') */ fixed_point_m - {$$ = new minutes_c($1, NULL);} + {$$ = new minutes_c($1, NULL, locloc(@$));} /*| integer ('m') ['_'] seconds */ | integer_m seconds - {$$ = new minutes_c($1, $2);} + {$$ = new minutes_c($1, $2, locloc(@$));} | integer_m '_' seconds - {$$ = new minutes_c($1, $3);} + {$$ = new minutes_c($1, $3, locloc(@$));} ; seconds: /* fixed_point ('s') */ fixed_point_s - {$$ = new seconds_c($1, NULL);} + {$$ = new seconds_c($1, NULL, locloc(@$));} /*| integer ('s') ['_'] milliseconds */ | integer_s milliseconds - {$$ = new seconds_c($1, $2);} + {$$ = new seconds_c($1, $2, locloc(@$));} | integer_s '_' milliseconds - {$$ = new seconds_c($1, $3);} + {$$ = new seconds_c($1, $3, locloc(@$));} ; milliseconds: /* fixed_point ('ms') */ fixed_point_ms - {$$ = new milliseconds_c($1);} + {$$ = new milliseconds_c($1, locloc(@$));} ; @@ -1972,13 +1990,13 @@ /************************************/ time_of_day: TIME_OF_DAY '#' daytime - {$$ = new time_of_day_c($3);} + {$$ = new time_of_day_c($3, locloc(@$));} ; daytime: day_hour ':' day_minute ':' day_second - {$$ = new daytime_c($1, $3, $5);} + {$$ = new daytime_c($1, $3, $5, locloc(@$));} ; @@ -1989,15 +2007,15 @@ date: DATE '#' date_literal - {$$ = new date_c($3);} + {$$ = new date_c($3, locloc(@$));} | D_SHARP date_literal - {$$ = new date_c($2);} + {$$ = new date_c($2, locloc(@$));} ; date_literal: year '-' month '-' day - {$$ = new date_literal_c($1, $3, $5);} + {$$ = new date_literal_c($1, $3, $5, locloc(@$));} ; @@ -2008,7 +2026,7 @@ date_and_time: DATE_AND_TIME '#' date_literal '-' daytime - {$$ = new date_and_time_c($3, $5);} + {$$ = new date_and_time_c($3, $5, locloc(@$));} ; @@ -2042,8 +2060,8 @@ | date_type_name | bit_string_type_name | elementary_string_type_name -| TIME {$$ = new time_type_name_c();} -| BOOL {$$ = new bool_type_name_c();} +| TIME {$$ = new time_type_name_c(locloc(@$));} +| BOOL {$$ = new bool_type_name_c(locloc(@$));} /* NOTE: see note under the B 1.2.1 section of token * and grouping type definition for reason why BOOL * was added to this definition. @@ -2061,38 +2079,38 @@ ; signed_integer_type_name: - SINT {$$ = new sint_type_name_c();} -| INT {$$ = new int_type_name_c();} -| DINT {$$ = new dint_type_name_c();} -| LINT {$$ = new lint_type_name_c();} + SINT {$$ = new sint_type_name_c(locloc(@$));} +| INT {$$ = new int_type_name_c(locloc(@$));} +| DINT {$$ = new dint_type_name_c(locloc(@$));} +| LINT {$$ = new lint_type_name_c(locloc(@$));} ; unsigned_integer_type_name: - USINT {$$ = new usint_type_name_c();} -| UINT {$$ = new uint_type_name_c();} -| UDINT {$$ = new udint_type_name_c();} -| ULINT {$$ = new ulint_type_name_c();} + USINT {$$ = new usint_type_name_c(locloc(@$));} +| UINT {$$ = new uint_type_name_c(locloc(@$));} +| UDINT {$$ = new udint_type_name_c(locloc(@$));} +| ULINT {$$ = new ulint_type_name_c(locloc(@$));} ; real_type_name: - REAL {$$ = new real_type_name_c();} -| LREAL {$$ = new lreal_type_name_c();} + REAL {$$ = new real_type_name_c(locloc(@$));} +| LREAL {$$ = new lreal_type_name_c(locloc(@$));} ; date_type_name: - DATE {$$ = new date_type_name_c();} -| TIME_OF_DAY {$$ = new tod_type_name_c();} -| TOD {$$ = new tod_type_name_c();} -| DATE_AND_TIME {$$ = new dt_type_name_c();} -| DT {$$ = new dt_type_name_c();} + DATE {$$ = new date_type_name_c(locloc(@$));} +| TIME_OF_DAY {$$ = new tod_type_name_c(locloc(@$));} +| TOD {$$ = new tod_type_name_c(locloc(@$));} +| DATE_AND_TIME {$$ = new dt_type_name_c(locloc(@$));} +| DT {$$ = new dt_type_name_c(locloc(@$));} ; bit_string_type_name: - BYTE {$$ = new byte_type_name_c();} -| WORD {$$ = new word_type_name_c();} -| DWORD {$$ = new dword_type_name_c();} -| LWORD {$$ = new lword_type_name_c();} + BYTE {$$ = new byte_type_name_c(locloc(@$));} +| WORD {$$ = new word_type_name_c(locloc(@$));} +| DWORD {$$ = new dword_type_name_c(locloc(@$));} +| LWORD {$$ = new lword_type_name_c(locloc(@$));} /* NOTE: see note under the B 1.2.1 section of token * and grouping type definition for reason why the BOOL * was omitted from this definition. @@ -2109,8 +2127,8 @@ * possible future changes easier to edit... */ elementary_string_type_name: - STRING {$$ = new string_type_name_c();} -| WSTRING {$$ = new wstring_type_name_c();} + STRING {$$ = new string_type_name_c(locloc(@$));} +| WSTRING {$$ = new wstring_type_name_c(locloc(@$));} ; @@ -2118,7 +2136,7 @@ /********************************/ /* B 1.3.2 - Generic data types */ /********************************/ -/* Strangely, the following symbol does seem to be required! */ +/* Strangely, the following symbol does not seem to be required! */ /* generic_type_name: ANY @@ -2141,20 +2159,20 @@ derived_type_name: single_element_type_name -| prev_declared_array_type_name {$$ = $1;} -| prev_declared_structure_type_name {$$ = $1;} -| prev_declared_string_type_name {$$ = $1;} +| prev_declared_array_type_name +| prev_declared_structure_type_name +| prev_declared_string_type_name ; single_element_type_name: - prev_declared_simple_type_name {$$ = $1;} + prev_declared_simple_type_name /* Include the following if arrays of function blocks are to be allowed! * Since the standard does not allow them, * we leave it commented out for the time being... */ -//| prev_declared_derived_function_block_name {$$ = $1;} -| prev_declared_subrange_type_name {$$ = $1;} -| prev_declared_enumerated_type_name {$$ = $1;} +//| prev_declared_derived_function_block_name +| prev_declared_subrange_type_name +| prev_declared_enumerated_type_name ; /* NOTE: in order to remove a reduce/reduce conflict, @@ -2171,13 +2189,13 @@ data_type_declaration: TYPE type_declaration_list END_TYPE - {$$ = new data_type_declaration_c($2);} + {$$ = new data_type_declaration_c($2, locloc(@$));} ; /* helper symbol for data_type_declaration */ type_declaration_list: type_declaration ';' - {$$ = new type_declaration_list_c(); $$->add_element($1);} + {$$ = new type_declaration_list_c(locloc(@$)); $$->add_element($1);} | type_declaration_list type_declaration ';' {$$ = $1; $$->add_element($2);} ; @@ -2198,7 +2216,7 @@ simple_type_declaration: /* simple_type_name ':' simple_spec_init */ identifier ':' simple_spec_init - {$$ = new simple_type_declaration_c($1, $3); + {$$ = new simple_type_declaration_c($1, $3, locloc(@$)); library_element_symtable.insert($1, prev_declared_simple_type_name_token); } ; @@ -2206,7 +2224,8 @@ simple_spec_init: simple_specification - /* The following line was changed so that we wouldn't + /* The following commented line was changed to the + * next two lines so that we wouldn't * have the first element of a simple_spec_init_c() * pointing to another simple_spec_init_c! */ @@ -2215,9 +2234,9 @@ {$$ = new simple_spec_init_c($1, $3);} */ | elementary_type_name ASSIGN constant - {$$ = new simple_spec_init_c($1, $3);} + {$$ = new simple_spec_init_c($1, $3, locloc(@$));} | prev_declared_simple_type_name ASSIGN constant - {$$ = new simple_spec_init_c($1, $3);} + {$$ = new simple_spec_init_c($1, $3, locloc(@$));} ; /* When converting to C/C++, we need to know whether @@ -2234,43 +2253,43 @@ simple_specification: // elementary_type_name | simple_type_name elementary_type_name - {$$ = new simple_spec_init_c($1, NULL);} + {$$ = new simple_spec_init_c($1, NULL, locloc(@$));} | prev_declared_simple_type_name - {$$ = new simple_spec_init_c($1, NULL);} + {$$ = new simple_spec_init_c($1, NULL, locloc(@$));} ; subrange_type_declaration: /* subrange_type_name ':' subrange_spec_init */ identifier ':' subrange_spec_init - {$$ = new subrange_type_declaration_c($1, $3); + {$$ = new subrange_type_declaration_c($1, $3, locloc(@$)); library_element_symtable.insert($1, prev_declared_subrange_type_name_token); } ; subrange_spec_init: subrange_specification - {$$ = new subrange_spec_init_c($1, NULL);} + {$$ = new subrange_spec_init_c($1, NULL, locloc(@$));} | subrange_specification ASSIGN signed_integer - {$$ = new subrange_spec_init_c($1, $3);} + {$$ = new subrange_spec_init_c($1, $3, locloc(@$));} ; subrange_specification: integer_type_name '(' subrange')' - {$$ = new subrange_specification_c($1, $3);} -| prev_declared_subrange_type_name {$$ = $1;} + {$$ = new subrange_specification_c($1, $3, locloc(@$));} +| prev_declared_subrange_type_name ; subrange: signed_integer DOTDOT signed_integer - {$$ = new subrange_c($1, $3);} + {$$ = new subrange_c($1, $3, locloc(@$));} ; enumerated_type_declaration: /* enumerated_type_name ':' enumerated_spec_init */ identifier ':' enumerated_spec_init - {$$ = new enumerated_type_declaration_c($1, $3); + {$$ = new enumerated_type_declaration_c($1, $3, locloc(@$)); library_element_symtable.insert($1, prev_declared_enumerated_type_name_token); } ; @@ -2278,21 +2297,21 @@ enumerated_spec_init: enumerated_specification - {$$ = new enumerated_spec_init_c($1, NULL);} + {$$ = new enumerated_spec_init_c($1, NULL, locloc(@$));} | enumerated_specification ASSIGN enumerated_value - {$$ = new enumerated_spec_init_c($1, $3);} + {$$ = new enumerated_spec_init_c($1, $3, locloc(@$));} ; enumerated_specification: '(' enumerated_value_list ')' {$$ = $2;} -| prev_declared_enumerated_type_name {$$ = $1;} +| prev_declared_enumerated_type_name ; /* helper symbol for enumerated_specification */ enumerated_value_list: enumerated_value - {$$ = new enumerated_value_list_c(); $$->add_element($1);} + {$$ = new enumerated_value_list_c(locloc(@$)); $$->add_element($1);} | enumerated_value_list ',' enumerated_value {$$ = $1; $$->add_element($3);} ; @@ -2300,45 +2319,43 @@ enumerated_value: identifier - {$$ = $1;} | prev_declared_enumerated_type_name '#' any_identifier - {$$ = new enumerated_value_c($1, $3);} + {$$ = new enumerated_value_c($1, $3, locloc(@$));} ; enumerated_value_without_identifier: prev_declared_enumerated_type_name '#' any_identifier - {$$ = new enumerated_value_c($1, $3);} + {$$ = new enumerated_value_c($1, $3, locloc(@$));} ; array_type_declaration: /* array_type_name ':' array_spec_init */ identifier ':' array_spec_init - {$$ = new array_type_declaration_c($1, $3); + {$$ = new array_type_declaration_c($1, $3, locloc(@$)); library_element_symtable.insert($1, prev_declared_array_type_name_token); } ; array_spec_init: array_specification - {$$ = new array_spec_init_c($1, NULL);} + {$$ = new array_spec_init_c($1, NULL, locloc(@$));} | array_specification ASSIGN array_initialization - {$$ = new array_spec_init_c($1, $3);} + {$$ = new array_spec_init_c($1, $3, locloc(@$));} ; array_specification: prev_declared_array_type_name - {$$ = $1;} | ARRAY '[' array_subrange_list ']' OF non_generic_type_name - {$$ = new array_specification_c($3, $6);} + {$$ = new array_specification_c($3, $6, locloc(@$));} ; /* helper symbol for array_specification */ array_subrange_list: subrange - {$$ = new array_subrange_list_c(); $$->add_element($1);} + {$$ = new array_subrange_list_c(locloc(@$)); $$->add_element($1);} | array_subrange_list ',' subrange {$$ = $1; $$->add_element($1);} ; @@ -2353,7 +2370,7 @@ /* helper symbol for array_initialization */ array_initial_elements_list: array_initial_elements - {$$ = new array_initial_elements_list_c(); $$->add_element($1);} + {$$ = new array_initial_elements_list_c(locloc(@$)); $$->add_element($1);} | array_initial_elements_list ',' array_initial_elements {$$ = $1; $$->add_element($3);} ; @@ -2363,7 +2380,7 @@ array_initial_element | integer '(' ')' | integer '(' array_initial_element ')' - {$$ = new array_initial_elements_c($1, $3);} + {$$ = new array_initial_elements_c($1, $3, locloc(@$));} ; @@ -2379,7 +2396,7 @@ structure_type_declaration: /* structure_type_name ':' structure_specification */ identifier ':' structure_specification - {$$ = new structure_type_declaration_c($1, $3); + {$$ = new structure_type_declaration_c($1, $3, locloc(@$)); library_element_symtable.insert($1, prev_declared_structure_type_name_token); } ; @@ -2393,9 +2410,9 @@ initialized_structure: prev_declared_structure_type_name - {$$ = new initialized_structure_c($1, NULL);} + {$$ = new initialized_structure_c($1, NULL, locloc(@$));} | prev_declared_structure_type_name ASSIGN structure_initialization - {$$ = new initialized_structure_c($1, $3);} + {$$ = new initialized_structure_c($1, $3, locloc(@$));} ; @@ -2407,7 +2424,7 @@ /* helper symbol for structure_declaration */ structure_element_declaration_list: structure_element_declaration ';' - {$$ = new structure_element_declaration_list_c(); $$->add_element($1);} + {$$ = new structure_element_declaration_list_c(locloc(@$)); $$->add_element($1);} | structure_element_declaration_list structure_element_declaration ';' {$$ = $1; $$->add_element($2);} ; @@ -2415,15 +2432,15 @@ structure_element_declaration: structure_element_name ':' simple_spec_init - {$$ = new structure_element_declaration_c($1, $3);} + {$$ = new structure_element_declaration_c($1, $3, locloc(@$));} | structure_element_name ':' subrange_spec_init - {$$ = new structure_element_declaration_c($1, $3);} + {$$ = new structure_element_declaration_c($1, $3, locloc(@$));} | structure_element_name ':' enumerated_spec_init - {$$ = new structure_element_declaration_c($1, $3);} + {$$ = new structure_element_declaration_c($1, $3, locloc(@$));} | structure_element_name ':' array_spec_init - {$$ = new structure_element_declaration_c($1, $3);} + {$$ = new structure_element_declaration_c($1, $3, locloc(@$));} | structure_element_name ':' initialized_structure - {$$ = new structure_element_declaration_c($1, $3);} + {$$ = new structure_element_declaration_c($1, $3, locloc(@$));} ; @@ -2438,7 +2455,7 @@ /* helper symbol for structure_initialization */ structure_element_initialization_list: structure_element_initialization - {$$ = new structure_element_initialization_list_c(); $$->add_element($1);} + {$$ = new structure_element_initialization_list_c(locloc(@$)); $$->add_element($1);} | structure_element_initialization_list ',' structure_element_initialization {$$ = $1; $$->add_element($3);} ; @@ -2446,13 +2463,13 @@ structure_element_initialization: structure_element_name ASSIGN constant - {$$ = new structure_element_initialization_c($1, $3);} + {$$ = new structure_element_initialization_c($1, $3, locloc(@$));} | structure_element_name ASSIGN enumerated_value - {$$ = new structure_element_initialization_c($1, $3);} + {$$ = new structure_element_initialization_c($1, $3, locloc(@$));} | structure_element_name ASSIGN array_initialization - {$$ = new structure_element_initialization_c($1, $3);} + {$$ = new structure_element_initialization_c($1, $3, locloc(@$));} | structure_element_name ASSIGN structure_initialization - {$$ = new structure_element_initialization_c($1, $3);} + {$$ = new structure_element_initialization_c($1, $3, locloc(@$));} ; /* NOTE: in order to remove a reduce/reduce conflict, @@ -2466,7 +2483,7 @@ string_type_declaration: /* string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */ identifier ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init - {$$ = new string_type_declaration_c($1, $3, $4, $5); + {$$ = new string_type_declaration_c($1, $3, $4, $5, locloc(@$)); library_element_symtable.insert($1, prev_declared_string_type_name_token); } ; @@ -2517,17 +2534,17 @@ symbolic_variable: -/* NOTE: To be entirely correct, variable_name should be replacemed by +/* NOTE: To be entirely correct, variable_name must be replacemed by * prev_declared_variable_name | prev_declared_fb_name | prev_declared_global_var_name */ identifier - {$$ = new symbolic_variable_c($1);} + {$$ = new symbolic_variable_c($1, locloc(@$));} | prev_declared_fb_name - {$$ = new symbolic_variable_c($1);} + {$$ = new symbolic_variable_c($1, locloc(@$));} | prev_declared_global_var_name - {$$ = new symbolic_variable_c($1);} + {$$ = new symbolic_variable_c($1, locloc(@$));} | prev_declared_variable_name - {$$ = new symbolic_variable_c($1);} + {$$ = new symbolic_variable_c($1, locloc(@$));} | multi_element_variable ; @@ -2544,7 +2561,7 @@ any_symbolic_variable: // variable_name -> replaced by any_identifier any_identifier - {$$ = new symbolic_variable_c($1);} + {$$ = new symbolic_variable_c($1, locloc(@$));} | any_multi_element_variable ; @@ -2559,7 +2576,7 @@ /********************************************/ /* B.1.4.1 Directly Represented Variables */ /********************************************/ -direct_variable: direct_variable_token {$$ = new direct_variable_c($1);}; +direct_variable: direct_variable_token {$$ = new direct_variable_c($1, locloc(@$));}; @@ -2581,13 +2598,13 @@ array_variable: subscripted_variable '[' subscript_list ']' - {$$ = new array_variable_c($1, $3);} + {$$ = new array_variable_c($1, $3, locloc(@$));} ; /* please see note above any_symbolic_variable */ any_array_variable: any_subscripted_variable '[' subscript_list ']' - {$$ = new array_variable_c($1, $3);} + {$$ = new array_variable_c($1, $3, locloc(@$));} ; @@ -2604,7 +2621,7 @@ subscript_list: subscript - {$$ = new subscript_list_c(); $$->add_element($1);} + {$$ = new subscript_list_c(locloc(@$)); $$->add_element($1);} | subscript_list ',' subscript {$$ = $1; $$->add_element($3);} ; @@ -2615,14 +2632,14 @@ structured_variable: record_variable '.' field_selector - {$$ = new structured_variable_c($1, $3);} + {$$ = new structured_variable_c($1, $3, locloc(@$));} ; /* please see note above any_symbolic_variable */ any_structured_variable: any_record_variable '.' field_selector - {$$ = new structured_variable_c($1, $3);} + {$$ = new structured_variable_c($1, $3, locloc(@$));} ; @@ -2650,17 +2667,17 @@ /******************************************/ input_declarations: VAR_INPUT input_declaration_list END_VAR - {$$ = new input_declarations_c(NULL, $2);} + {$$ = new input_declarations_c(NULL, $2, locloc(@$));} | VAR_INPUT RETAIN input_declaration_list END_VAR - {$$ = new input_declarations_c(new retain_option_c(), $3);} + {$$ = new input_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));} | VAR_INPUT NON_RETAIN input_declaration_list END_VAR - {$$ = new input_declarations_c(new non_retain_option_c(), $3);} + {$$ = new input_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));} ; /* helper symbol for input_declarations */ input_declaration_list: input_declaration ';' - {$$ = new input_declaration_list_c(); $$->add_element($1);} + {$$ = new input_declaration_list_c(locloc(@$)); $$->add_element($1);} | input_declaration_list input_declaration ';' {$$ = $1; $$->add_element($2);} ; @@ -2674,9 +2691,9 @@ edge_declaration: var1_list ':' BOOL R_EDGE - {$$ = new edge_declaration_c(new raising_edge_option_c(), $1);} + {$$ = new edge_declaration_c(new raising_edge_option_c(locloc(@3)), $1, locloc(@$));} | var1_list ':' BOOL F_EDGE - {$$ = new edge_declaration_c(new falling_edge_option_c(), $1);} + {$$ = new edge_declaration_c(new falling_edge_option_c(locloc(@3)), $1, locloc(@$));} ; @@ -2693,17 +2710,17 @@ var1_init_decl: var1_list ':' simple_spec_init - {$$ = new var1_init_decl_c($1, $3);} + {$$ = new var1_init_decl_c($1, $3, locloc(@$));} | var1_list ':' subrange_spec_init - {$$ = new var1_init_decl_c($1, $3);} + {$$ = new var1_init_decl_c($1, $3, locloc(@$));} | var1_list ':' enumerated_spec_init - {$$ = new var1_init_decl_c($1, $3);} + {$$ = new var1_init_decl_c($1, $3, locloc(@$));} ; var1_list: variable_name - {$$ = new var1_list_c(); $$->add_element($1); + {$$ = new var1_list_c(locloc(@$)); $$->add_element($1); variable_name_symtable.insert($1, prev_declared_variable_name_token); } | var1_list ',' variable_name @@ -2716,13 +2733,13 @@ array_var_init_decl: var1_list ':' array_spec_init - {$$ = new array_var_init_decl_c($1, $3);} + {$$ = new array_var_init_decl_c($1, $3, locloc(@$));} ; structured_var_init_decl: var1_list ':' initialized_structure - {$$ = new structured_var_init_decl_c($1, $3);} + {$$ = new structured_var_init_decl_c($1, $3, locloc(@$));} ; @@ -2734,10 +2751,10 @@ fb_name_decl: /* fb_name_list ':' function_block_type_name */ fb_name_list_with_colon function_block_type_name - {$$ = new fb_name_decl_c($1, $2, NULL);} + {$$ = new fb_name_decl_c($1, $2, NULL, locloc(@$));} /*| fb_name_list ':' function_block_type_name ASSIGN structure_initialization */ | fb_name_list_with_colon function_block_type_name ASSIGN structure_initialization - {$$ = new fb_name_decl_c($1, $2, $4);} + {$$ = new fb_name_decl_c($1, $2, $4, locloc(@$));} ; @@ -2769,7 +2786,7 @@ fb_name_list_with_colon: var1_list_with_colon - {$$ = new fb_name_list_c(); + {$$ = new fb_name_list_c(locloc(@$)); /* fill up the new fb_name_list_c object with the references * contained in the var1_list_c object. */ @@ -2795,18 +2812,18 @@ output_declarations: VAR_OUTPUT var_init_decl_list END_VAR - {$$ = new output_declarations_c(NULL, $2);} + {$$ = new output_declarations_c(NULL, $2, locloc(@$));} | VAR_OUTPUT RETAIN var_init_decl_list END_VAR - {$$ = new output_declarations_c(new retain_option_c(), $3);} + {$$ = new output_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));} | VAR_OUTPUT NON_RETAIN var_init_decl_list END_VAR - {$$ = new output_declarations_c(new non_retain_option_c(), $3);} + {$$ = new output_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));} ; input_output_declarations: VAR_IN_OUT var_declaration_list END_VAR - {$$ = new input_output_declarations_c($2);} + {$$ = new input_output_declarations_c($2, locloc(@$));} ; @@ -2814,7 +2831,7 @@ /* helper symbol for input_output_declarations */ var_declaration_list: var_declaration ';' - {$$ = new var_declaration_list_c(); $$->add_element($1);} + {$$ = new var_declaration_list_c(locloc(@$)); $$->add_element($1);} | var_declaration_list var_declaration ';' {$$ = $1; $$->add_element($2);} ; @@ -2835,56 +2852,56 @@ var1_declaration: var1_list ':' simple_specification - {$$ = new var1_init_decl_c($1, $3);} + {$$ = new var1_init_decl_c($1, $3, locloc(@$));} | var1_list ':' subrange_specification - {$$ = new var1_init_decl_c($1, $3);} + {$$ = new var1_init_decl_c($1, $3, locloc(@$));} | var1_list ':' enumerated_specification - {$$ = new var1_init_decl_c($1, $3);} + {$$ = new var1_init_decl_c($1, $3, locloc(@$));} ; array_var_declaration: var1_list ':' array_specification - {$$ = new array_var_declaration_c($1, $3);} + {$$ = new array_var_declaration_c($1, $3, locloc(@$));} ; structured_var_declaration: var1_list ':' prev_declared_structure_type_name - {$$ = new structured_var_declaration_c($1, $3);} + {$$ = new structured_var_declaration_c($1, $3, locloc(@$));} ; var_declarations: VAR var_init_decl_list END_VAR - {$$ = new var_declarations_c(NULL, $2);} + {$$ = new var_declarations_c(NULL, $2, locloc(@$));} | VAR CONSTANT var_init_decl_list END_VAR - {$$ = new var_declarations_c(new constant_option_c(), $3);} + {$$ = new var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));} ; retentive_var_declarations: VAR RETAIN var_init_decl_list END_VAR - {$$ = new retentive_var_declarations_c($3);} + {$$ = new retentive_var_declarations_c($3, locloc(@$));} ; located_var_declarations: VAR located_var_decl_list END_VAR - {$$ = new located_var_declarations_c(NULL, $2);} + {$$ = new located_var_declarations_c(NULL, $2, locloc(@$));} | VAR CONSTANT located_var_decl_list END_VAR - {$$ = new located_var_declarations_c(new constant_option_c(), $3);} + {$$ = new located_var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));} | VAR RETAIN located_var_decl_list END_VAR - {$$ = new located_var_declarations_c(new retain_option_c(), $3);} + {$$ = new located_var_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));} | VAR NON_RETAIN located_var_decl_list END_VAR - {$$ = new located_var_declarations_c(new non_retain_option_c(), $3);} + {$$ = new located_var_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));} ; /* helper symbol for located_var_declarations */ located_var_decl_list: located_var_decl ';' - {$$ = new located_var_decl_list_c(); $$->add_element($1);} + {$$ = new located_var_decl_list_c(locloc(@$)); $$->add_element($1);} | located_var_decl_list located_var_decl ';' {$$ = $1; $$->add_element($2);} ; @@ -2892,11 +2909,11 @@ located_var_decl: variable_name location ':' located_var_spec_init - {$$ = new located_var_decl_c($1, $2, $4); + {$$ = new located_var_decl_c($1, $2, $4, locloc(@$)); variable_name_symtable.insert($1, prev_declared_variable_name_token); } | location ':' located_var_spec_init - {$$ = new located_var_decl_c(NULL, $1, $3);} + {$$ = new located_var_decl_c(NULL, $1, $3, locloc(@$));} ; @@ -2904,15 +2921,15 @@ external_var_declarations: VAR_EXTERNAL external_declaration_list END_VAR - {$$ = new external_var_declarations_c(NULL, $2);} + {$$ = new external_var_declarations_c(NULL, $2, locloc(@$));} | VAR_EXTERNAL CONSTANT external_declaration_list END_VAR - {$$ = new external_var_declarations_c(new constant_option_c(), $3);} + {$$ = new external_var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));} ; /* helper symbol for external_var_declarations */ external_declaration_list: external_declaration ';' - {$$ = new external_declaration_list_c(); $$->add_element($1);} + {$$ = new external_declaration_list_c(locloc(@$)); $$->add_element($1);} | external_declaration_list external_declaration';' {$$ = $1; $$->add_element($2);} ; @@ -2920,27 +2937,27 @@ external_declaration: global_var_name ':' simple_specification - {$$ = new external_declaration_c($1, $3); + {$$ = new external_declaration_c($1, $3, locloc(@$)); variable_name_symtable.insert($1, prev_declared_variable_name_token); } | global_var_name ':' subrange_specification - {$$ = new external_declaration_c($1, $3); + {$$ = new external_declaration_c($1, $3, locloc(@$)); variable_name_symtable.insert($1, prev_declared_variable_name_token); } | global_var_name ':' enumerated_specification - {$$ = new external_declaration_c($1, $3); + {$$ = new external_declaration_c($1, $3, locloc(@$)); variable_name_symtable.insert($1, prev_declared_variable_name_token); } | global_var_name ':' array_specification - {$$ = new external_declaration_c($1, $3); + {$$ = new external_declaration_c($1, $3, locloc(@$)); variable_name_symtable.insert($1, prev_declared_variable_name_token); } | global_var_name ':' prev_declared_structure_type_name - {$$ = new external_declaration_c($1, $3); + {$$ = new external_declaration_c($1, $3, locloc(@$)); variable_name_symtable.insert($1, prev_declared_variable_name_token); } | global_var_name ':' function_block_type_name - {$$ = new external_declaration_c($1, $3); + {$$ = new external_declaration_c($1, $3, locloc(@$)); variable_name_symtable.insert($1, prev_declared_fb_name_token); } ; @@ -2951,18 +2968,18 @@ global_var_declarations: VAR_GLOBAL global_var_decl_list END_VAR - {$$ = new global_var_declarations_c(NULL, $2);} + {$$ = new global_var_declarations_c(NULL, $2, locloc(@$));} | VAR_GLOBAL CONSTANT global_var_decl_list END_VAR - {$$ = new global_var_declarations_c(new constant_option_c(), $3);} + {$$ = new global_var_declarations_c(new constant_option_c(locloc(@2)), $3, locloc(@$));} | VAR_GLOBAL RETAIN global_var_decl_list END_VAR - {$$ = new global_var_declarations_c(new retain_option_c(), $3);} + {$$ = new global_var_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));} ; /* helper symbol for global_var_declarations */ global_var_decl_list: global_var_decl ';' - {$$ = new global_var_decl_list_c(); $$->add_element($1);} + {$$ = new global_var_decl_list_c(locloc(@$)); $$->add_element($1);} | global_var_decl_list global_var_decl ';' {$$ = $1; $$->add_element($2);} ; @@ -2970,20 +2987,20 @@ global_var_decl: global_var_spec ':' - {$$ = new global_var_decl_c($1, NULL);} + {$$ = new global_var_decl_c($1, NULL, locloc(@$));} | global_var_spec ':' located_var_spec_init - {$$ = new global_var_decl_c($1, $3);} + {$$ = new global_var_decl_c($1, $3, locloc(@$));} | global_var_spec ':' function_block_type_name - {$$ = new global_var_decl_c($1, $3);} + {$$ = new global_var_decl_c($1, $3, locloc(@$));} ; global_var_spec: global_var_list {$$ = $1;} | location - {$$ = new global_var_spec_c(NULL, $1);} + {$$ = new global_var_spec_c(NULL, $1, locloc(@$));} | global_var_name location - {$$ = new global_var_spec_c($1, $2); + {$$ = new global_var_spec_c($1, $2, locloc(@$)); variable_name_symtable.insert($1, prev_declared_global_var_name_token); } @@ -3003,14 +3020,14 @@ location: AT direct_variable - {$$ = new location_c($2);} + {$$ = new location_c($2, locloc(@$));} ; global_var_list: global_var_name - {$$ = new global_var_list_c(); $$->add_element($1); + {$$ = new global_var_list_c(locloc(@$)); $$->add_element($1); variable_name_symtable.insert($1, prev_declared_global_var_name_token); } | global_var_list ',' global_var_name @@ -3028,7 +3045,7 @@ single_byte_string_var_declaration: var1_list ':' single_byte_string_spec - {$$ = new single_byte_string_var_declaration_c($1, $3);} + {$$ = new single_byte_string_var_declaration_c($1, $3, locloc(@$));} ; /* NOTE: The constructs @@ -3068,50 +3085,50 @@ {$$ = new single_byte_string_spec_c(NULL, NULL);} */ STRING '[' integer ']' - {$$ = new single_byte_string_spec_c($3, NULL);} + {$$ = new single_byte_string_spec_c($3, NULL, locloc(@$));} /* | STRING ASSIGN single_byte_character_string - {$$ = new single_byte_string_spec_c(NULL, $3);} + {$$ = new single_byte_string_spec_c(NULL, $3, locloc(@$));} */ | STRING '[' integer ']' ASSIGN single_byte_character_string - {$$ = new single_byte_string_spec_c($3, $6);} + {$$ = new single_byte_string_spec_c($3, $6, locloc(@$));} ; double_byte_string_var_declaration: var1_list ':' double_byte_string_spec - {$$ = new double_byte_string_var_declaration_c($1, $3);} + {$$ = new double_byte_string_var_declaration_c($1, $3, locloc(@$));} ; double_byte_string_spec: /* WSTRING - {$$ = new double_byte_string_spec_c(NULL, NULL);} + {$$ = new double_byte_string_spec_c(NULL, NULL, locloc(@$));} */ WSTRING '[' integer ']' - {$$ = new double_byte_string_spec_c($3, NULL);} + {$$ = new double_byte_string_spec_c($3, NULL, locloc(@$));} /* | WSTRING ASSIGN double_byte_character_string - {$$ = new double_byte_string_spec_c(NULL, $3);} + {$$ = new double_byte_string_spec_c(NULL, $3, locloc(@$));} */ | WSTRING '[' integer ']' ASSIGN double_byte_character_string - {$$ = new double_byte_string_spec_c($3, $6);} + {$$ = new double_byte_string_spec_c($3, $6, locloc(@$));} ; incompl_located_var_declarations: VAR incompl_located_var_decl_list END_VAR - {$$ = new incompl_located_var_declarations_c(NULL, $2);} + {$$ = new incompl_located_var_declarations_c(NULL, $2, locloc(@$));} | VAR RETAIN incompl_located_var_decl_list END_VAR - {$$ = new incompl_located_var_declarations_c(new retain_option_c(), $3);} + {$$ = new incompl_located_var_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));} | VAR NON_RETAIN incompl_located_var_decl_list END_VAR - {$$ = new incompl_located_var_declarations_c(new non_retain_option_c(), $3);} + {$$ = new incompl_located_var_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));} ; /* helper symbol for incompl_located_var_declarations */ incompl_located_var_decl_list: incompl_located_var_decl ';' - {$$ = new incompl_located_var_decl_list_c(); $$->add_element($1);} + {$$ = new incompl_located_var_decl_list_c(locloc(@$)); $$->add_element($1);} | incompl_located_var_decl_list incompl_located_var_decl ';' {$$ = $1; $$->add_element($2);} ; @@ -3119,13 +3136,13 @@ incompl_located_var_decl: variable_name incompl_location ':' var_spec - {$$ = new incompl_located_var_decl_c($1, $2, $4);} + {$$ = new incompl_located_var_decl_c($1, $2, $4, locloc(@$));} ; incompl_location: AT incompl_location_token - {$$ = new incompl_location_c($2);} + {$$ = new incompl_location_c($2, locloc(@$));} ; @@ -3151,16 +3168,16 @@ */ string_spec: /* STRING - {$$ = new single_byte_string_spec_c(NULL, NULL);} + {$$ = new single_byte_string_spec_c(NULL, NULL, locloc(@$));} */ STRING '[' integer ']' - {$$ = new single_byte_string_spec_c($3, NULL);} + {$$ = new single_byte_string_spec_c($3, NULL, locloc(@$));} /* | WSTRING - {$$ = new double_byte_string_spec_c(NULL, NULL);} + {$$ = new double_byte_string_spec_c(NULL, NULL, locloc(@$));} */ | WSTRING '[' integer ']' - {$$ = new double_byte_string_spec_c($3, NULL);} + {$$ = new double_byte_string_spec_c($3, NULL, locloc(@$));} ; @@ -3173,7 +3190,7 @@ */ var_init_decl_list: var_init_decl ';' - {$$ = new var_init_decl_list_c(); $$->add_element($1);} + {$$ = new var_init_decl_list_c(locloc(@$)); $$->add_element($1);} | var_init_decl_list var_init_decl ';' {$$ = $1; $$->add_element($2);} ; @@ -3184,6 +3201,13 @@ /***********************/ /* B 1.5.1 - Functions */ /***********************/ +/* +function_name: + prev_declared_derived_function_name +| standard_function_name +; +*/ + /* The following rules should be set such as: * function_name: function_name_no_clashes | function_name_simpleop_clashes | function_name_expression_clashes * function_name: function_name_no_NOT_clashes | function_name_NOT_clashes; @@ -3196,12 +3220,6 @@ function_name_no_NOT_clashes: prev_declared_derived_function_name | standard_function_name_no_NOT_clashes; //function_name_NOT_clashes: standard_function_name_NOT_clashes; -/* -function_name: - prev_declared_derived_function_name -| standard_function_name -; -*/ /* NOTE: The list of standard function names * includes the standard functions MOD(), NOT() @@ -3274,7 +3292,7 @@ standard_function_name_no_clashes: standard_function_name_token - {$$ = new identifier_c($1);} + {$$ = new identifier_c($1, locloc(@$));} ; @@ -3285,7 +3303,7 @@ standard_function_name_NOT_clashes: NOT - {$$ = new identifier_c(strdup("NOT"));} + {$$ = new identifier_c(strdup("NOT"), locloc(@$));} ; /* Add here any other IL simple operators that collide @@ -3334,7 +3352,7 @@ function_declaration: /* FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */ function_name_declaration ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION - {$$ = new function_declaration_c($1, $3, $4, $5); + {$$ = new function_declaration_c($1, $3, $4, $5, locloc(@$)); variable_name_symtable.pop(); if (allow_function_overloading) { switch (library_element_symtable.find_value($1)) { @@ -3355,7 +3373,7 @@ } /* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */ | function_name_declaration ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION - {$$ = new function_declaration_c($1, $3, $4, $5); + {$$ = new function_declaration_c($1, $3, $4, $5, locloc(@$)); variable_name_symtable.pop(); if (allow_function_overloading) { switch (library_element_symtable.find_value($1)) { @@ -3367,7 +3385,17 @@ library_element_symtable.insert($1, prev_declared_derived_function_name_token); } } -; +/* ERROR_CHECK_BEGIN */ +| FUNCTION error END_FUNCTION + {$$ = NULL; + print_err_msg(current_filename, @2.first_line, "error in function declaration."); + /* yychar */ + yyerrok; + } +/* ERROR_CHECK_END */ +; + + /* helper symbol for function_declaration */ /* NOTE: due to reduce/reduce conflicts between identifiers @@ -3418,7 +3446,7 @@ /* intermediate helper symbol for function_declaration */ io_OR_function_var_declarations_list: /* empty */ - {$$ = new var_declarations_list_c();} + {$$ = new var_declarations_list_c(locloc(@$));} | io_OR_function_var_declarations_list io_var_declarations {$$ = $1; $$->add_element($2);} | io_OR_function_var_declarations_list function_var_decls @@ -3435,15 +3463,15 @@ function_var_decls: VAR CONSTANT var2_init_decl_list END_VAR - {$$ = new function_var_decls_c(new constant_option_c(), $3);} + {$$ = new function_var_decls_c(new constant_option_c(locloc(@2)), $3, locloc(@$));} | VAR var2_init_decl_list END_VAR - {$$ = new function_var_decls_c(NULL, $2);} + {$$ = new function_var_decls_c(NULL, $2, locloc(@$));} ; /* intermediate helper symbol for function_var_decls */ var2_init_decl_list: var2_init_decl ';' - {$$ = new var2_init_decl_list_c(); $$->add_element($1);} + {$$ = new var2_init_decl_list_c(locloc(@$)); $$->add_element($1);} | var2_init_decl_list var2_init_decl ';' {$$ = $1; $$->add_element($2);} ; @@ -3477,14 +3505,14 @@ ; -standard_function_block_name: standard_function_block_name_token {$$ = new identifier_c($1);}; +standard_function_block_name: standard_function_block_name_token {$$ = new identifier_c($1, locloc(@$));}; derived_function_block_name: identifier; function_block_declaration: FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations_list function_block_body END_FUNCTION_BLOCK - {$$ = new function_block_declaration_c($2, $3, $4); + {$$ = new function_block_declaration_c($2, $3, $4, locloc(@$)); library_element_symtable.insert($2, prev_declared_derived_function_block_name_token); /* Clear the variable_name_symtable. Since * we have finished parsing the function block, @@ -3493,6 +3521,14 @@ */ variable_name_symtable.pop(); } +/* ERROR_CHECK_BEGIN */ +| FUNCTION_BLOCK error END_FUNCTION_BLOCK + {$$ = NULL; + print_err_msg(current_filename, @2.first_line, "error in function block declaration."); + /* yychar */ + yyerrok; + } +/* ERROR_CHECK_END */ ; @@ -3504,7 +3540,7 @@ */ io_OR_other_var_declarations_list: /* empty */ - {$$ = new var_declarations_list_c();} + {$$ = new var_declarations_list_c(locloc(@$));} | io_OR_other_var_declarations_list io_var_declarations {$$ = $1; $$->add_element($2);} | io_OR_other_var_declarations_list other_var_declarations @@ -3539,14 +3575,14 @@ temp_var_decls: VAR_TEMP temp_var_decls_list END_VAR - {$$ = new temp_var_decls_c($2);} + {$$ = new temp_var_decls_c($2, locloc(@$));} ; /* intermediate helper symbol for temp_var_decls */ temp_var_decls_list: temp_var_decl ';' - {$$ = new temp_var_decls_list_c(); $$->add_element($1);} + {$$ = new temp_var_decls_list_c(locloc(@$)); $$->add_element($1);} | temp_var_decls_list temp_var_decl ';' {$$ = $1; $$->add_element($2);} ; @@ -3554,7 +3590,7 @@ non_retentive_var_decls: VAR NON_RETAIN var_init_decl_list END_VAR - {$$ = new non_retentive_var_decls_c($3);} + {$$ = new non_retentive_var_decls_c($3, locloc(@$));} ; @@ -3581,7 +3617,7 @@ program_declaration: PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM - {$$ = new program_declaration_c($2, $3, $4); + {$$ = new program_declaration_c($2, $3, $4, locloc(@$)); library_element_symtable.insert($2, prev_declared_program_type_name_token); /* Clear the variable_name_symtable. Since * we have finished parsing the program declaration, @@ -3590,6 +3626,14 @@ */ variable_name_symtable.pop(); } +/* ERROR_CHECK_BEGIN */ +| PROGRAM error END_PROGRAM + {$$ = NULL; + print_err_msg(current_filename, @2.first_line, "error in function block declaration."); + /* yychar */ + yyerrok; + } +/* ERROR_CHECK_END */ ; @@ -3599,7 +3643,7 @@ */ program_var_declarations_list: /* empty */ - {$$ = new var_declarations_list_c();} + {$$ = new var_declarations_list_c(locloc(@$));} | program_var_declarations_list io_var_declarations {$$ = $1; $$->add_element($2);} | program_var_declarations_list other_var_declarations @@ -3643,14 +3687,14 @@ sequential_function_chart: sfc_network - {$$ = new sequential_function_chart_c(); $$->add_element($1);} + {$$ = new sequential_function_chart_c(locloc(@$)); $$->add_element($1);} | sequential_function_chart sfc_network {$$ = $1; $$->add_element($2);} ; sfc_network: initial_step - {$$ = new sfc_network_c(); $$->add_element($1);} + {$$ = new sfc_network_c(locloc(@$)); $$->add_element($1);} | sfc_network step {$$ = $1; $$->add_element($2);} | sfc_network transition @@ -3662,13 +3706,13 @@ 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);} + {$$ = new initial_step_c($2, $4, locloc(@$));} ; step: STEP step_name ':' action_association_list END_STEP // STEP identifier ':' action_association_list END_STEP - {$$ = new step_c($2, $4);} + {$$ = new step_c($2, $4, locloc(@$));} ; /* helper symbol for: @@ -3677,7 +3721,7 @@ */ action_association_list: /* empty */ - {$$ = new action_association_list_c();} + {$$ = new action_association_list_c(locloc(@$));} | action_association_list action_association ';' {$$ = $1; $$->add_element($2);} ; @@ -3687,14 +3731,14 @@ step_name: any_identifier; action_association: - action_name '(' action_qualifier indicator_name_list ')' - {$$ = new action_association_c($1, $3, $4, NULL);} + action_name '(' {cmd_goto_sfc_qualifier_state()} action_qualifier {cmd_pop_state()} indicator_name_list ')' + {$$ = new action_association_c($1, $4, $6, locloc(@$));} ; /* helper symbol for action_association */ indicator_name_list: /* empty */ - {$$ = new indicator_name_list_c();} + {$$ = new indicator_name_list_c(locloc(@$));} | indicator_name_list ',' indicator_name {$$ = $1; $$->add_element($3);} ; @@ -3706,27 +3750,27 @@ /* empty */ {$$ = NULL;} | qualifier - {$$ = new action_qualifier_c($1, NULL);} + {$$ = new action_qualifier_c($1, NULL, locloc(@$));} | timed_qualifier ',' action_time - {$$ = new action_qualifier_c($1, $3);} + {$$ = new action_qualifier_c($1, $3, locloc(@$));} ; qualifier: -N {$$ = new qualifier_c(strdup("N"));} +N {$$ = new qualifier_c(strdup("N"), locloc(@$));} /* NOTE: the following two clash with the R and S IL operators. * It will have to be handled when we include parsing of SFC... */ -| R {$$ = new qualifier_c(strdup("R"));} -| S {$$ = new qualifier_c(strdup("S"));} -| P {$$ = new qualifier_c(strdup("P"));} +| R {$$ = new qualifier_c(strdup("R"), locloc(@$));} +| S {$$ = new qualifier_c(strdup("S"), locloc(@$));} +| P {$$ = new qualifier_c(strdup("P"), locloc(@$));} ; timed_qualifier: -L {$$ = new timed_qualifier_c(strdup("L"));} -| D {$$ = new timed_qualifier_c(strdup("D"));} -| SD {$$ = new timed_qualifier_c(strdup("SD"));} -| DS {$$ = new timed_qualifier_c(strdup("DS"));} -| SL {$$ = new timed_qualifier_c(strdup("SL"));} +L {$$ = new timed_qualifier_c(strdup("L"), locloc(@$));} +| D {$$ = new timed_qualifier_c(strdup("D"), locloc(@$));} +| SD {$$ = new timed_qualifier_c(strdup("SD"), locloc(@$));} +| DS {$$ = new timed_qualifier_c(strdup("DS"), locloc(@$));} +| SL {$$ = new timed_qualifier_c(strdup("SL"), locloc(@$));} ; action_time: @@ -3742,14 +3786,14 @@ steps: step_name - {$$ = new steps_c($1, NULL);} + {$$ = new steps_c($1, NULL, locloc(@$));} | '(' step_name_list ')' - {$$ = new steps_c(NULL, $2);} + {$$ = new steps_c(NULL, $2, locloc(@$));} ; step_name_list: step_name ',' step_name - {$$ = new step_name_list_c(); $$->add_element($1); $$->add_element($3);} + {$$ = new step_name_list_c(locloc(@$)); $$->add_element($1); $$->add_element($3);} | step_name_list ',' step_name {$$ = $1; $$->add_element($3);} ; @@ -3778,11 +3822,14 @@ {$$ = $2} ; + +/* TODO: Can't we clean this up a bit ? */ transition: transition_header transition_condition_il END_TRANSITION - {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, $2, NULL);} + {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, $2, NULL, locloc(@$));} + /* TODO: free the memory used up by the no longer used object $1 */ | transition_header transition_condition_st END_TRANSITION - {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, NULL, $2);} + {$$ = new transition_c($1.first, $1.second, $1.third, $1.fourth, NULL, $2, locloc(@$));} ; action_header: @@ -3794,7 +3841,7 @@ action: action_header function_block_body END_ACTION - {$$ = new action_c($1.first, $2);} + {$$ = new action_c($1.first, $2, locloc(@$));} ; @@ -3836,10 +3883,10 @@ * If it ever becomes necessary to change this interpretation of * the syntax, then this section of the syntax parser must be updated! */ -prev_declared_global_var_name: prev_declared_global_var_name_token {$$ = new identifier_c($1);}; -prev_declared_resource_name: prev_declared_resource_name_token {$$ = new identifier_c($1);}; -prev_declared_program_name: prev_declared_program_name_token {$$ = new identifier_c($1);}; -// prev_declared_task_name: prev_declared_task_name_token {$$ = new identifier_c($1);}; +prev_declared_global_var_name: prev_declared_global_var_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_resource_name: prev_declared_resource_name_token {$$ = new identifier_c($1, locloc(@$));}; +prev_declared_program_name: prev_declared_program_name_token {$$ = new identifier_c($1, locloc(@$));}; +// prev_declared_task_name: prev_declared_task_name_token {$$ = new identifier_c($1, locloc(@$));}; @@ -3870,7 +3917,7 @@ optional_access_declarations optional_instance_specific_initializations END_CONFIGURATION - {$$ = new configuration_declaration_c($2, $3, $4, $6, $7); + {$$ = new configuration_declaration_c($2, $3, $4, $6, $7, locloc(@$)); library_element_symtable.insert($2, prev_declared_configuration_name_token); variable_name_symtable.pop(); } @@ -3880,16 +3927,18 @@ optional_access_declarations optional_instance_specific_initializations END_CONFIGURATION - {$$ = new configuration_declaration_c($2, $3, $4, $5, $6); + {$$ = new configuration_declaration_c($2, $3, $4, $5, $6, locloc(@$)); library_element_symtable.insert($2, prev_declared_configuration_name_token); variable_name_symtable.pop(); } +/* ERROR_CHECK_BEGIN */ | CONFIGURATION error END_CONFIGURATION {$$ = NULL; - print_err_msg(current_filename, @2.last_line, "error in configuration declaration."); + print_err_msg(current_filename, @2.first_line, "error in configuration declaration."); /* yychar */ yyerrok; } +/* ERROR_CHECK_END */ ; // helper symbol for @@ -3920,7 +3969,7 @@ // helper symbol for configuration_declaration // resource_declaration_list: resource_declaration - {$$ = new resource_declaration_list_c(); $$->add_element($1);} + {$$ = new resource_declaration_list_c(locloc(@$)); $$->add_element($1);} | resource_declaration_list resource_declaration {$$ = $1; $$->add_element($2);} ; @@ -3931,7 +3980,7 @@ optional_global_var_declarations single_resource_declaration END_RESOURCE - {$$ = new resource_declaration_c($3, $5, $6, $7); + {$$ = new resource_declaration_c($3, $5, $6, $7, locloc(@$)); variable_name_symtable.pop(); variable_name_symtable.insert($3, prev_declared_resource_name_token); } @@ -3940,14 +3989,14 @@ single_resource_declaration: task_configuration_list program_configuration_list - {$$ = new single_resource_declaration_c($1, $2);} + {$$ = new single_resource_declaration_c($1, $2, locloc(@$));} ; // helper symbol for single_resource_declaration // task_configuration_list: // empty - {$$ = new task_configuration_list_c();} + {$$ = new task_configuration_list_c(locloc(@$));} | task_configuration_list task_configuration ';' {$$ = $1; $$->add_element($2);} ; @@ -3956,7 +4005,7 @@ // helper symbol for single_resource_declaration // program_configuration_list: program_configuration ';' - {$$ = new program_configuration_list_c(); $$->add_element($1);} + {$$ = new program_configuration_list_c(locloc(@$)); $$->add_element($1);} | program_configuration_list program_configuration ';' {$$ = $1; $$->add_element($2);} ; @@ -4010,7 +4059,7 @@ */ any_fb_name_list: // empty - {$$ = new any_fb_name_list_c();} + {$$ = new any_fb_name_list_c(locloc(@$));} //| fb_name_list fb_name '.' | any_fb_name_list any_identifier '.' {$$ = $1; $$->add_element($2);} @@ -4021,13 +4070,13 @@ global_var_reference: // [resource_name '.'] global_var_name ['.' structure_element_name] // prev_declared_global_var_name - {$$ = new global_var_reference_c(NULL, $1, NULL);} + {$$ = new global_var_reference_c(NULL, $1, NULL, locloc(@$));} | prev_declared_global_var_name '.' structure_element_name - {$$ = new global_var_reference_c(NULL, $1, $3);} + {$$ = new global_var_reference_c(NULL, $1, $3, locloc(@$));} | prev_declared_resource_name '.' prev_declared_global_var_name - {$$ = new global_var_reference_c($1, $3, NULL);} + {$$ = new global_var_reference_c($1, $3, NULL, locloc(@$));} | prev_declared_resource_name '.' prev_declared_global_var_name '.' structure_element_name - {$$ = new global_var_reference_c($1, $3, $5);} + {$$ = new global_var_reference_c($1, $3, $5, locloc(@$));} ; @@ -4048,7 +4097,7 @@ */ // prev_declared_program_name '.' symbolic_variable program_name '.' symbolic_variable - {$$ = new program_output_reference_c($1, $3);} + {$$ = new program_output_reference_c($1, $3, locloc(@$));} ; program_name: identifier; @@ -4064,7 +4113,7 @@ task_configuration: TASK task_name task_initialization - {$$ = new task_configuration_c($2, $3);} + {$$ = new task_configuration_c($2, $3, locloc(@$));} ; /* NOTE: The specification does nopt mention the namespace to which task names @@ -4079,13 +4128,13 @@ task_initialization: // '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' // '(' PRIORITY ASSIGN integer ')' - {$$ = new task_initialization_c(NULL, NULL, $4);} + {$$ = new task_initialization_c(NULL, NULL, $4, locloc(@$));} | '(' SINGLE ASSIGN data_source ',' PRIORITY ASSIGN integer ')' - {$$ = new task_initialization_c($4, NULL, $8);} + {$$ = new task_initialization_c($4, NULL, $8, locloc(@$));} | '(' INTERVAL ASSIGN data_source ',' PRIORITY ASSIGN integer ')' - {$$ = new task_initialization_c(NULL, $4, $8);} + {$$ = new task_initialization_c(NULL, $4, $8, locloc(@$));} | '(' SINGLE ASSIGN data_source ',' INTERVAL ASSIGN data_source ',' PRIORITY ASSIGN integer ')' - {$$ = new task_initialization_c($4, $8, $12);} + {$$ = new task_initialization_c($4, $8, $12, locloc(@$));} ; data_source: @@ -4098,15 +4147,15 @@ program_configuration: // PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] // PROGRAM program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements - {$$ = new program_configuration_c(NULL, $2, $3, $5, $6); + {$$ = new program_configuration_c(NULL, $2, $3, $5, $6, locloc(@$)); variable_name_symtable.insert($2, prev_declared_program_name_token); } | PROGRAM RETAIN program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements - {$$ = new program_configuration_c(new retain_option_c(), $3, $4, $6, $7); + {$$ = new program_configuration_c(new retain_option_c(locloc(@2)), $3, $4, $6, $7, locloc(@$)); variable_name_symtable.insert($3, prev_declared_program_name_token); } | PROGRAM NON_RETAIN program_name optional_task_name ':' prev_declared_program_type_name optional_prog_conf_elements - {$$ = new program_configuration_c(new non_retain_option_c(), $3, $4, $6, $7); + {$$ = new program_configuration_c(new non_retain_option_c(locloc(@2)), $3, $4, $6, $7, locloc(@$)); variable_name_symtable.insert($3, prev_declared_program_name_token); } ; @@ -4130,7 +4179,7 @@ prog_conf_elements: prog_conf_element - {$$ = new prog_conf_elements_c(); $$->add_element($1);} + {$$ = new prog_conf_elements_c(locloc(@$)); $$->add_element($1);} | prog_conf_elements ',' prog_conf_element {$$ = $1; $$->add_element($3);} ; @@ -4149,7 +4198,7 @@ * currently parsing, so we must accept them to be any_identifier! */ any_identifier WITH task_name - {$$ = new fb_task_c($1, $3);} + {$$ = new fb_task_c($1, $3, locloc(@$));} ; @@ -4185,9 +4234,9 @@ */ prog_cnxn: any_symbolic_variable ASSIGN prog_data_source - {$$ = new prog_cnxn_assign_c($1, $3);} + {$$ = new prog_cnxn_assign_c($1, $3, locloc(@$));} | any_symbolic_variable SENDTO data_sink - {$$ = new prog_cnxn_sendto_c($1, $3);} + {$$ = new prog_cnxn_sendto_c($1, $3, locloc(@$));} ; prog_data_source: @@ -4204,13 +4253,13 @@ instance_specific_initializations: VAR_CONFIG instance_specific_init_list END_VAR - {$$ = new instance_specific_initializations_c($2);} + {$$ = new instance_specific_initializations_c($2, locloc(@$));} ; // helper symbol for instance_specific_initializations // instance_specific_init_list: instance_specific_init ';' - {$$ = new instance_specific_init_list_c(); $$->add_element($1);} + {$$ = new instance_specific_init_list_c(locloc(@$)); $$->add_element($1);} | instance_specific_init_list instance_specific_init ';' {$$ = $1; $$->add_element($2);} ; @@ -4230,18 +4279,18 @@ * The programs are only kept inside the scope of the resource in which they are defined. */ prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier ':' located_var_spec_init - {$$ = new instance_specific_init_c($1, $3, $5, $6, NULL, $8);} + {$$ = new instance_specific_init_c($1, $3, $5, $6, NULL, $8, locloc(@$));} | prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier location ':' located_var_spec_init - {$$ = new instance_specific_init_c($1, $3, $5, $6, $7, $9);} + {$$ = new instance_specific_init_c($1, $3, $5, $6, $7, $9, locloc(@$));} | prev_declared_resource_name '.' program_name '.' any_fb_name_list any_identifier ':' fb_initialization - {$5->add_element($6); $$ = new instance_specific_init_c($1, $3, $5, NULL, NULL, $8);} + {$5->add_element($6); $$ = new instance_specific_init_c($1, $3, $5, NULL, NULL, $8, locloc(@$));} ; /* helper symbol for instance_specific_init */ fb_initialization: function_block_type_name ASSIGN structure_initialization - {$$ = new fb_initialization_c($1, $3);} + {$$ = new fb_initialization_c($1, $3, locloc(@$));} ; /***********************************/ @@ -4264,28 +4313,36 @@ instruction_list: il_instruction - {$$ = new instruction_list_c(); $$->add_element($1);} + {$$ = new instruction_list_c(locloc(@$)); $$->add_element($1);} | pragma eol_list - {$$ = new instruction_list_c(); $$->add_element($1);} + {$$ = new instruction_list_c(locloc(@$)); $$->add_element($1);} | instruction_list il_instruction {$$ = $1; $$->add_element($2);} | instruction_list pragma {$$ = $1; $$->add_element($2);} -| instruction_list error - {$$ = $1; - print_err_msg(current_filename, @2.last_line, "error in IL instruction."); - /* yychar */ +; + + + +il_instruction: + il_incomplete_instruction eol_list + {$$ = new il_instruction_c(NULL, $1, locloc(@$));} +| label ':' il_incomplete_instruction eol_list + {$$ = new il_instruction_c($1, $3, locloc(@$));} +/* ERROR_CHECK_BEGIN */ +| error eol_list + {$$ = NULL; + print_err_msg(current_filename, @1.first_line, "error in IL instruction."); yyerrok; } -; - - - -il_instruction: - il_incomplete_instruction eol_list - {$$ = new il_instruction_c(NULL, $1);} -| label ':' il_incomplete_instruction eol_list - {$$ = new il_instruction_c($1, $3);} +/* ERROR_CHECK_END */ +/* ERROR_CHECK_BEGIN */ +| label ':' error eol_list + {$$ = NULL; + print_err_msg(current_filename, @1.first_line, "error in IL instruction."); + yyerrok; + } +/* ERROR_CHECK_END */ ; @@ -4306,11 +4363,15 @@ il_simple_operation: il_simple_operator - {$$ = new il_simple_operation_c($1, NULL);} + {$$ = new il_simple_operation_c($1, NULL, locloc(@$));} | il_simple_operator_noclash il_operand - {$$ = new il_simple_operation_c($1, $2);} + {$$ = new il_simple_operation_c($1, $2, locloc(@$));} | il_simple_operator_clash_il_operand - {$$ = new il_simple_operation_c($1.first, $1.second);} + {$$ = new il_simple_operation_c($1.first, $1.second, locloc(@$));} + /* TODO: free the memory used up by the no longer used $1 object! */ + /* I don't do it now because I would have to test the change, and am + * currently frying bigger fish... (Mario) + /* free($1); */ /* NOTE: the line * | il_simple_operator * already contains the 'NOT' operator, as well as all the @@ -4319,6 +4380,9 @@ * without any operands, could be reduced to either an operator or a * function call. I (Mario) have chosen to reduce it to an operator. * + * In order to do this, we must remove from the syntax that defines + * function calls all the functions whose names clash with the IL operators. + * * The line * | function_name * has been replaced with the lines @@ -4327,12 +4391,16 @@ * those whose names coincide with operators !! */ | function_name_no_clashes - {$$ = new il_function_call_c($1, NULL);} + {$$ = new il_function_call_c($1, NULL, locloc(@$));} /* NOTE: the line * | il_simple_operator il_operand - * already contains the 'NOT', 'MOD', etc. operators, followed by a single il_operand, - * which may also be reduced to a function name with an operand_list of a single - * il_operand! This would lead us to a reduce/reduce conflict! + * already contains the 'NOT', 'MOD', etc. operators, followed by a single il_operand. + * However, this same code (MOD x) may also be reduced to a function call to the MOD + * function. This means that (MOD, AND,...) could be interpret as a function name + * or as an IL operator! This would lead us to a reduce/reduce conflict! + * + * In order to do this, we must remove from the syntax that defines + * function calls all the functions whose names clash with the IL operators. * * I (Mario) have chosen to reduce it to an operand, rather than a function call. * @@ -4345,18 +4413,24 @@ * * Note that: * this alternative syntax does not cover the possibility of - * the function 'NOT', 'MOD', etc... being called with more than one il_operand! + * the function 'NOT', 'MOD', etc... being called with more than one il_operand, + * in which case it is always a function call, and not an IL instruction. * We therefore need to include an extra rule where the * function_name_expression_clashes and function_name_simpleop_clashes * are followed by a il_operand_list with __two__ or more il_operands!! */ | function_name_no_clashes il_operand_list - {$$ = new il_function_call_c($1, $2);} + {$$ = new il_function_call_c($1, $2, locloc(@$));} | il_simple_operator_clash_il_operand ',' il_operand_list - {list_c *list = new il_operand_list_c(); + {list_c *list = new il_operand_list_c(locloc(@$)); list->add_element($1.second); FOR_EACH_ELEMENT(elem, $3, {list->add_element(elem);}) - $$ = new il_function_call_c(il_operator_c_2_identifier_c($1.first), list); + $$ = new il_function_call_c(il_operator_c_2_identifier_c($1.first), list, locloc(@$)); + /* TODO: free the memory used up by the no longer used $3 object! */ + /* I don't do it now because I would have to test the change, and am + * currently frying bigger fish... (Mario) + */ + /* free($3); */ } ; @@ -4371,45 +4445,45 @@ il_expression: il_expr_operator_noclash '(' eol_list ')' - {$$ = new il_expression_c($1, NULL, NULL);} + {$$ = new il_expression_c($1, NULL, NULL, locloc(@$));} | il_expr_operator_noclash '(' il_operand eol_list ')' - {$$ = new il_expression_c($1, $3, NULL);} + {$$ = new il_expression_c($1, $3, NULL, locloc(@$));} | il_expr_operator_noclash '(' eol_list simple_instr_list ')' - {$$ = new il_expression_c($1, NULL, $4);} + {$$ = new il_expression_c($1, NULL, $4, locloc(@$));} | il_expr_operator_noclash '(' il_operand eol_list simple_instr_list ')' - {$$ = new il_expression_c($1, $3, $5);} + {$$ = new il_expression_c($1, $3, $5, locloc(@$));} /* */ | il_expr_operator_clash '(' eol_list ')' - {$$ = new il_expression_c($1, NULL, NULL);} + {$$ = new il_expression_c($1, NULL, NULL, locloc(@$));} | il_expr_operator_clash '(' il_operand eol_list ')' - {$$ = new il_expression_c($1, $3, NULL);} + {$$ = new il_expression_c($1, $3, NULL, locloc(@$));} | il_expr_operator_clash '(' il_operand eol_list simple_instr_list ')' - {$$ = new il_expression_c($1, $3, $5);} + {$$ = new il_expression_c($1, $3, $5, locloc(@$));} /* */ | il_expr_operator_clash_eol_list simple_instr_list ')' - {$$ = new il_expression_c($1, NULL, $2);} + {$$ = new il_expression_c($1, NULL, $2, locloc(@$));} ; il_jump_operation: il_jump_operator label - {$$ = new il_jump_operation_c($1, $2);} + {$$ = new il_jump_operation_c($1, $2, locloc(@$));} ; il_fb_call: il_call_operator prev_declared_fb_name - {$$ = new il_fb_call_c($1, $2, NULL, NULL);} + {$$ = new il_fb_call_c($1, $2, NULL, NULL, locloc(@$));} | il_call_operator prev_declared_fb_name '(' ')' - {$$ = new il_fb_call_c($1, $2, NULL, NULL);} + {$$ = new il_fb_call_c($1, $2, NULL, NULL, locloc(@$));} | il_call_operator prev_declared_fb_name '(' eol_list ')' - {$$ = new il_fb_call_c($1, $2, NULL, NULL);} + {$$ = new il_fb_call_c($1, $2, NULL, NULL, locloc(@$));} | il_call_operator prev_declared_fb_name '(' il_operand_list ')' - {$$ = new il_fb_call_c($1, $2, $4, NULL);} + {$$ = new il_fb_call_c($1, $2, $4, NULL, locloc(@$));} | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')' - {$$ = new il_fb_call_c($1, $2, NULL, $5);} + {$$ = new il_fb_call_c($1, $2, NULL, $5, locloc(@$));} ; @@ -4429,17 +4503,34 @@ * names clash with expressions may be interpreted by the syntax by * two different routes. I (Mario) chose to interpret them * as operators, rather than as function calls! + * (AND MOD OR XOR ADD DIV EQ GT GE LT LE MUL NE SUB) */ function_name_no_clashes '(' eol_list ')' - {$$ = new il_formal_funct_call_c($1, NULL);} + {$$ = new il_formal_funct_call_c($1, NULL, locloc(@$));} | function_name_simpleop_clashes '(' eol_list ')' - {$$ = new il_formal_funct_call_c($1, NULL);} + {$$ = new il_formal_funct_call_c($1, NULL, locloc(@$));} /* | function_name '(' eol_list il_param_list ')' */ +/* For the above syntax, we no longer have two ways of interpreting the + * same syntax. The above is always a function call! + * However, some of the functions that we may be calling + * may have the same name as an IL operator. This means that + * flex will be parsing them and handing them over to bison as + * IL operator tokens, and not as function name tokens. + * (when parsing ST, flex no longer recognizes IL operators, + * so will always return the correct function name, unless that + * name also coincides with an operator used in ST -> XOR, OR, MOD, AND, NOT) + * + * We must therefore interpret the IL operators as function names! + */ | function_name_no_clashes '(' eol_list il_param_list ')' - {$$ = new il_formal_funct_call_c($1, $4);} + {$$ = new il_formal_funct_call_c($1, $4, locloc(@$));} | function_name_simpleop_clashes '(' eol_list il_param_list ')' - {$$ = new il_formal_funct_call_c($1, $4);} -/* the function_name_expression_clashes had to be first reduced to + {$$ = new il_formal_funct_call_c($1, $4, locloc(@$));} +/* The following line should read: + * + * | function_name_expression_clashes '(' eol_list il_param_list ')' + * + * but the function_name_expression_clashes had to be first reduced to * an intermediary symbol in order to remove a reduce/reduce conflict. * In essence, the syntax requires more than one look ahead token * in order to be parsed. We resolve this by reducing a collection of @@ -4457,7 +4548,7 @@ * at the end of this file... il_operator_c_2_identifier_c() */ | il_expr_operator_clash_eol_list il_param_list ')' - {$$ = new il_formal_funct_call_c(il_operator_c_2_identifier_c($1), $2);} + {$$ = new il_formal_funct_call_c(il_operator_c_2_identifier_c($1), $2, locloc(@$));} ; @@ -4480,7 +4571,7 @@ il_operand_list: il_operand - {$$ = new il_operand_list_c(); $$->add_element($1);} + {$$ = new il_operand_list_c(locloc(@$)); $$->add_element($1);} | il_operand_list ',' il_operand {$$ = $1; $$->add_element($3);} ; @@ -4488,7 +4579,7 @@ simple_instr_list: il_simple_instruction - {$$ = new simple_instr_list_c(); $$->add_element($1);} + {$$ = new simple_instr_list_c(locloc(@$)); $$->add_element($1);} | simple_instr_list il_simple_instruction {$$ = $1; $$->add_element($2);} ; @@ -4519,14 +4610,14 @@ il_param_instruction_list il_param_last_instruction {$$ = $1; $$->add_element($2);} | il_param_last_instruction - {$$ = new il_param_list_c(); $$->add_element($1);} + {$$ = new il_param_list_c(locloc(@$)); $$->add_element($1);} ; /* Helper symbol for il_param_list */ il_param_instruction_list: il_param_instruction - {$$ = new il_param_list_c(); $$->add_element($1);} + {$$ = new il_param_list_c(locloc(@$)); $$->add_element($1);} | il_param_instruction_list il_param_instruction {$$ = $1; $$->add_element($2);} ; @@ -4546,15 +4637,15 @@ il_param_assignment: il_assign_operator il_operand - {$$ = new il_param_assignment_c($1, $2, NULL);} + {$$ = new il_param_assignment_c($1, $2, NULL, locloc(@$));} | il_assign_operator '(' eol_list simple_instr_list ')' - {$$ = new il_param_assignment_c($1, NULL, $4);} + {$$ = new il_param_assignment_c($1, NULL, $4, locloc(@$));} ; il_param_out_assignment: il_assign_out_operator variable - {$$ = new il_param_out_assignment_c($1, $2);} + {$$ = new il_param_out_assignment_c($1, $2, locloc(@$));} ; @@ -4562,7 +4653,7 @@ /*******************/ /* B 2.2 Operators */ /*******************/ -sendto_identifier: sendto_identifier_token {$$ = new identifier_c($1);}; +sendto_identifier: sendto_identifier_token {$$ = new identifier_c($1, locloc(@$));}; /* NOTE: @@ -4572,72 +4663,49 @@ * as 'EQ' * (Mario) */ -LD_operator: LD {$$ = new LD_operator_c();}; -LDN_operator: LDN {$$ = new LDN_operator_c();}; -ST_operator: ST {$$ = new ST_operator_c();}; -STN_operator: STN {$$ = new STN_operator_c();}; -NOT_operator: NOT {$$ = new NOT_operator_c();}; -S_operator: S {$$ = new S_operator_c();}; -R_operator: R {$$ = new R_operator_c();}; -S1_operator: S1 {$$ = new S1_operator_c();}; -R1_operator: R1 {$$ = new R1_operator_c();}; -CLK_operator: CLK {$$ = new CLK_operator_c();}; -CU_operator: CU {$$ = new CU_operator_c();}; -CD_operator: CD {$$ = new CD_operator_c();}; -PV_operator: PV {$$ = new PV_operator_c();}; -IN_operator: IN {$$ = new IN_operator_c();}; -PT_operator: PT {$$ = new PT_operator_c();}; -AND_operator: AND {$$ = new AND_operator_c();}; -AND2_operator: AND2 {$$ = new AND_operator_c();}; /* '&' in the source code! */ -OR_operator: OR {$$ = new OR_operator_c();}; -XOR_operator: XOR {$$ = new XOR_operator_c();}; -ANDN_operator: ANDN {$$ = new ANDN_operator_c();}; -ANDN2_operator: ANDN2 {$$ = new ANDN_operator_c();}; /* '&N' in the source code! */ -ORN_operator: ORN {$$ = new ORN_operator_c();}; -XORN_operator: XORN {$$ = new XORN_operator_c();}; -ADD_operator: ADD {$$ = new ADD_operator_c();}; -SUB_operator: SUB {$$ = new SUB_operator_c();}; -MUL_operator: MUL {$$ = new MUL_operator_c();}; -DIV_operator: DIV {$$ = new DIV_operator_c();}; -MOD_operator: MOD {$$ = new MOD_operator_c();}; -GT_operator: GT {$$ = new GT_operator_c();}; -GE_operator: GE {$$ = new GE_operator_c();}; -EQ_operator: EQ {$$ = new EQ_operator_c();}; -LT_operator: LT {$$ = new LT_operator_c();}; -LE_operator: LE {$$ = new LE_operator_c();}; -NE_operator: NE {$$ = new NE_operator_c();}; -CAL_operator: CAL {$$ = new CAL_operator_c();}; -CALC_operator: CALC {$$ = new CALC_operator_c();}; -CALCN_operator: CALCN {$$ = new CALCN_operator_c();}; -RET_operator: RET {$$ = new RET_operator_c();}; -RETC_operator: RETC {$$ = new RETC_operator_c();}; -RETCN_operator: RETCN {$$ = new RETCN_operator_c();}; -JMP_operator: JMP {$$ = new JMP_operator_c();}; -JMPC_operator: JMPC {$$ = new JMPC_operator_c();}; -JMPCN_operator: JMPCN {$$ = new JMPCN_operator_c();}; - -/* - MAY CONFLICT WITH STANDARD FUNCTION NAMES!!! - -NOT_operator: NOT {new NOT_operator_c();}; - -AND_operator: AND {new AND_operator_c();}; -OR_operator: OR {new OR_operator_c();}; -XOR_operator: XOR {new XOR_operator_c();}; - -ADD_operator: ADD {new ADD_operator_c();}; -SUB_operator: SUB {new SUB_operator_c();}; -MUL_operator: MUL {new MUL_operator_c();}; -DIV_operator: DIV {new DIV_operator_c();}; -MOD_operator: MOD {new MOD_operator_c();}; - -GT_operator: GT {new GT_operator_c();}; -GE_operator: GE {new GE_operator_c();}; -EQ_operator: EQ {new EQ_operator_c();}; -LT_operator: LT {new LT_operator_c();}; -LE_operator: LE {new LE_operator_c();}; -NE_operator: NE {new NE_operator_c();}; -*/ +LD_operator: LD {$$ = new LD_operator_c(locloc(@$));}; +LDN_operator: LDN {$$ = new LDN_operator_c(locloc(@$));}; +ST_operator: ST {$$ = new ST_operator_c(locloc(@$));}; +STN_operator: STN {$$ = new STN_operator_c(locloc(@$));}; +NOT_operator: NOT {$$ = new NOT_operator_c(locloc(@$));}; +S_operator: S {$$ = new S_operator_c(locloc(@$));}; +R_operator: R {$$ = new R_operator_c(locloc(@$));}; +S1_operator: S1 {$$ = new S1_operator_c(locloc(@$));}; +R1_operator: R1 {$$ = new R1_operator_c(locloc(@$));}; +CLK_operator: CLK {$$ = new CLK_operator_c(locloc(@$));}; +CU_operator: CU {$$ = new CU_operator_c(locloc(@$));}; +CD_operator: CD {$$ = new CD_operator_c(locloc(@$));}; +PV_operator: PV {$$ = new PV_operator_c(locloc(@$));}; +IN_operator: IN {$$ = new IN_operator_c(locloc(@$));}; +PT_operator: PT {$$ = new PT_operator_c(locloc(@$));}; +AND_operator: AND {$$ = new AND_operator_c(locloc(@$));}; +AND2_operator: AND2 {$$ = new AND_operator_c(locloc(@$));}; /* '&' in the source code! */ +OR_operator: OR {$$ = new OR_operator_c(locloc(@$));}; +XOR_operator: XOR {$$ = new XOR_operator_c(locloc(@$));}; +ANDN_operator: ANDN {$$ = new ANDN_operator_c(locloc(@$));}; +ANDN2_operator: ANDN2 {$$ = new ANDN_operator_c(locloc(@$));}; /* '&N' in the source code! */ +ORN_operator: ORN {$$ = new ORN_operator_c(locloc(@$));}; +XORN_operator: XORN {$$ = new XORN_operator_c(locloc(@$));}; +ADD_operator: ADD {$$ = new ADD_operator_c(locloc(@$));}; +SUB_operator: SUB {$$ = new SUB_operator_c(locloc(@$));}; +MUL_operator: MUL {$$ = new MUL_operator_c(locloc(@$));}; +DIV_operator: DIV {$$ = new DIV_operator_c(locloc(@$));}; +MOD_operator: MOD {$$ = new MOD_operator_c(locloc(@$));}; +GT_operator: GT {$$ = new GT_operator_c(locloc(@$));}; +GE_operator: GE {$$ = new GE_operator_c(locloc(@$));}; +EQ_operator: EQ {$$ = new EQ_operator_c(locloc(@$));}; +LT_operator: LT {$$ = new LT_operator_c(locloc(@$));}; +LE_operator: LE {$$ = new LE_operator_c(locloc(@$));}; +NE_operator: NE {$$ = new NE_operator_c(locloc(@$));}; +CAL_operator: CAL {$$ = new CAL_operator_c(locloc(@$));}; +CALC_operator: CALC {$$ = new CALC_operator_c(locloc(@$));}; +CALCN_operator: CALCN {$$ = new CALCN_operator_c(locloc(@$));}; +RET_operator: RET {$$ = new RET_operator_c(locloc(@$));}; +RETC_operator: RETC {$$ = new RETC_operator_c(locloc(@$));}; +RETCN_operator: RETCN {$$ = new RETCN_operator_c(locloc(@$));}; +JMP_operator: JMP {$$ = new JMP_operator_c(locloc(@$));}; +JMPC_operator: JMPC {$$ = new JMPC_operator_c(locloc(@$));}; +JMPCN_operator: JMPCN {$$ = new JMPCN_operator_c(locloc(@$));}; il_simple_operator: @@ -4725,10 +4793,10 @@ /* variable_name SENDTO */ /* any_identifier SENDTO */ sendto_identifier SENDTO - {$$ = new il_assign_out_operator_c(NULL, $1);} + {$$ = 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(), $2);} + {$$ = new il_assign_out_operator_c(new not_paramassign_c(locloc(@1)), $2, locloc(@$));} ; @@ -4759,21 +4827,21 @@ expression: xor_expression | expression OR xor_expression - {$$ = new or_expression_c($1, $3);} + {$$ = new or_expression_c($1, $3, locloc(@$));} ; xor_expression: and_expression | xor_expression XOR and_expression - {$$ = new xor_expression_c($1, $3);} + {$$ = new xor_expression_c($1, $3, locloc(@$));} ; and_expression: comparison | and_expression '&' comparison - {$$ = new and_expression_c($1, $3);} + {$$ = new and_expression_c($1, $3, locloc(@$));} | and_expression AND comparison - {$$ = new and_expression_c($1, $3);} + {$$ = new and_expression_c($1, $3, locloc(@$));} /* NOTE: The lexical parser never returns the token '&'. * The '&' string is interpreted by the lexcial parser as the token * AND2! @@ -4782,27 +4850,27 @@ * to remove theh AND2 token... */ | and_expression AND2 comparison - {$$ = new and_expression_c($1, $3);} + {$$ = new and_expression_c($1, $3, locloc(@$));} ; comparison: equ_expression | comparison '=' equ_expression - {$$ = new equ_expression_c($1, $3);} + {$$ = new equ_expression_c($1, $3, locloc(@$));} | comparison OPER_NE equ_expression - {$$ = new notequ_expression_c($1, $3);} + {$$ = new notequ_expression_c($1, $3, locloc(@$));} ; equ_expression: add_expression | equ_expression '<' add_expression - {$$ = new lt_expression_c($1, $3);} + {$$ = new lt_expression_c($1, $3, locloc(@$));} | equ_expression '>' add_expression - {$$ = new gt_expression_c($1, $3);} + {$$ = new gt_expression_c($1, $3, locloc(@$));} | equ_expression OPER_LE add_expression - {$$ = new le_expression_c($1, $3);} + {$$ = new le_expression_c($1, $3, locloc(@$));} | equ_expression OPER_GE add_expression - {$$ = new ge_expression_c($1, $3);} + {$$ = new ge_expression_c($1, $3, locloc(@$));} ; /* Not required... @@ -4812,9 +4880,9 @@ add_expression: term | add_expression '+' term - {$$ = new add_expression_c($1, $3);} + {$$ = new add_expression_c($1, $3, locloc(@$));} | add_expression '-' term - {$$ = new sub_expression_c($1, $3);} + {$$ = new sub_expression_c($1, $3, locloc(@$));} ; /* Not required... @@ -4824,11 +4892,11 @@ term: power_expression | term '*' power_expression - {$$ = new mul_expression_c($1, $3);} + {$$ = new mul_expression_c($1, $3, locloc(@$));} | term '/' power_expression - {$$ = new div_expression_c($1, $3);} + {$$ = new div_expression_c($1, $3, locloc(@$));} | term MOD power_expression - {$$ = new mod_expression_c($1, $3);} + {$$ = new mod_expression_c($1, $3, locloc(@$));} ; /* Not required... @@ -4838,16 +4906,16 @@ power_expression: unary_expression | power_expression OPER_EXP unary_expression - {$$ = new power_expression_c($1, $3);} + {$$ = new power_expression_c($1, $3, locloc(@$));} ; unary_expression: primary_expression | '-' primary_expression - {$$ = new neg_expression_c($2);} + {$$ = new neg_expression_c($2, locloc(@$));} | NOT primary_expression - {$$ = new not_expression_c($2);} + {$$ = new not_expression_c($2, locloc(@$));} ; /* Not required... @@ -4912,7 +4980,7 @@ function_invocation: /* function_name '(' param_assignment_list ')' */ function_name_no_NOT_clashes '(' param_assignment_list ')' - {$$ = new function_invocation_c($1, $3);} + {$$ = new function_invocation_c($1, $3, locloc(@$));} ; @@ -4921,19 +4989,21 @@ /********************/ statement_list: statement ';' - {$$ = new statement_list_c(); $$->add_element($1);} + {$$ = new statement_list_c(locloc(@$)); $$->add_element($1);} | pragma - {$$ = new statement_list_c(); $$->add_element($1);} + {$$ = new statement_list_c(locloc(@$)); $$->add_element($1);} | statement_list statement ';' {$$ = $1; $$->add_element($2);} | statement_list pragma {$$ = $1; $$->add_element($2);} +/* ERROR_CHECK_BEGIN */ | statement_list error ';' {$$ = $1; - print_err_msg(current_filename, @2.last_line, "error in statement."); + print_err_msg(current_filename, @2.first_line, "error in statement."); /* yychar */ yyerrok; } +/* ERROR_CHECK_END */ ; @@ -4950,7 +5020,7 @@ /*********************************/ assignment_statement: variable ASSIGN expression - {$$ = new assignment_statement_c($1, $3);} + {$$ = new assignment_statement_c($1, $3, locloc(@$));} ; @@ -4966,16 +5036,16 @@ return_statement: - RETURN {$$ = new return_statement_c();} + RETURN {$$ = new return_statement_c(locloc(@$));} ; fb_invocation: prev_declared_fb_name '(' ')' - {$$ = new fb_invocation_c($1, NULL); } + {$$ = new fb_invocation_c($1, NULL, locloc(@$)); } | prev_declared_fb_name '(' param_assignment_list ')' - {$$ = new fb_invocation_c($1, $3);} + {$$ = new fb_invocation_c($1, $3, locloc(@$));} ; @@ -4985,7 +5055,7 @@ */ param_assignment_list: param_assignment - {$$ = new param_assignment_list_c(); $$->add_element($1);} + {$$ = new param_assignment_list_c(locloc(@$)); $$->add_element($1);} | param_assignment_list ',' param_assignment {$$ = $1; $$->add_element($3);} ; @@ -4995,16 +5065,16 @@ param_assignment: /* variable_name ASSIGN expression */ any_identifier ASSIGN expression - {$$ = new input_variable_param_assignment_c($1, $3);} + {$$ = new input_variable_param_assignment_c($1, $3, locloc(@$));} | expression /*| variable_name SENDTO variable */ /*| any_identifier SENDTO variable */ | sendto_identifier SENDTO variable - {$$ = new output_variable_param_assignment_c(NULL,$1, $3);} + {$$ = new output_variable_param_assignment_c(NULL,$1, $3, locloc(@$));} /*| variable_name SENDTO variable */ /*| NOT any_identifier SENDTO variable*/ | NOT sendto_identifier SENDTO variable - {$$ = new output_variable_param_assignment_c(new not_paramassign_c(),$2, $4);} + {$$ = new output_variable_param_assignment_c(new not_paramassign_c(locloc(@$)),$2, $4, locloc(@$));} ; @@ -5022,15 +5092,15 @@ if_statement: IF expression THEN statement_list elseif_statement_list END_IF - {$$ = new if_statement_c($2, $4, $5, NULL);} + {$$ = new if_statement_c($2, $4, $5, NULL, locloc(@$));} | IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF - {$$ = new if_statement_c($2, $4, $5, $7);} + {$$ = new if_statement_c($2, $4, $5, $7, locloc(@$));} ; /* helper symbol for if_statement */ elseif_statement_list: /* empty */ - {$$ = new elseif_statement_list_c();} + {$$ = new elseif_statement_list_c(locloc(@$));} | elseif_statement_list elseif_statement {$$ = $1; $$->add_element($2);} ; @@ -5038,22 +5108,22 @@ /* helper symbol for elseif_statement_list */ elseif_statement: ELSIF expression THEN statement_list - {$$ = new elseif_statement_c($2, $4);} + {$$ = new elseif_statement_c($2, $4, locloc(@$));} ; case_statement: CASE expression OF case_element_list END_CASE - {$$ = new case_statement_c($2, $4, NULL);} + {$$ = new case_statement_c($2, $4, NULL, locloc(@$));} | CASE expression OF case_element_list ELSE statement_list END_CASE - {$$ = new case_statement_c($2, $4, $6);} + {$$ = new case_statement_c($2, $4, $6, locloc(@$));} ; /* helper symbol for case_statement */ case_element_list: case_element - {$$ = new case_element_list_c(); $$->add_element($1);} + {$$ = new case_element_list_c(locloc(@$)); $$->add_element($1);} | case_element_list case_element {$$ = $1; $$->add_element($2);} ; @@ -5061,15 +5131,15 @@ case_element: case_list ':' statement_list - {$$ = new case_element_c($1, $3);} + {$$ = new case_element_c($1, $3, locloc(@$));} | case_list ':' statement_list identifier BOGUS_TOKEN_ID - {$$ = new case_element_c($1, $3); ERROR;} + {$$ = new case_element_c($1, $3, locloc(@$)); ERROR;} ; case_list: case_list_element - {$$ = new case_list_c(); $$->add_element($1);} + {$$ = new case_list_c(locloc(@$)); $$->add_element($1);} | case_list ',' case_list_element {$$ = $1; $$->add_element($3);} ; @@ -5104,9 +5174,9 @@ for_statement: FOR control_variable ASSIGN expression TO expression BY expression DO statement_list END_FOR - {$$ = new for_statement_c($2, $4, $6, $8, $10);} + {$$ = new for_statement_c($2, $4, $6, $8, $10, locloc(@$));} | FOR control_variable ASSIGN expression TO expression DO statement_list END_FOR - {$$ = new for_statement_c($2, $4, $6, NULL, $8);} + {$$ = new for_statement_c($2, $4, $6, NULL, $8, locloc(@$));} ; /* The spec has the syntax @@ -5136,18 +5206,18 @@ while_statement: WHILE expression DO statement_list END_WHILE - {$$ = new while_statement_c($2, $4);} + {$$ = new while_statement_c($2, $4, locloc(@$));} ; repeat_statement: REPEAT statement_list UNTIL expression END_REPEAT - {$$ = new repeat_statement_c($2, $4);} + {$$ = new repeat_statement_c($2, $4, locloc(@$));} ; exit_statement: - EXIT {$$ = new exit_statement_c();} + EXIT {$$ = new exit_statement_c(locloc(@$));} ; @@ -5191,12 +5261,12 @@ void yyerror (const char *error_msg) { current_error_msg = error_msg; /* fprintf(stderr, "error %d: %s\n", yynerrs // global variable //, error_msg); */ - print_include_stack(); +/* print_include_stack(); */ } void print_err_msg(const char *filename, int lineno, const char *additional_error_msg) { - fprintf(stderr, "error %d: %s\n", yynerrs, additional_error_msg); + fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg); print_include_stack(); fprintf(stderr, "%s:%d: %s\n", filename, lineno, current_error_msg); } @@ -5218,6 +5288,7 @@ */ symbol_c *il_operator_c_2_identifier_c(symbol_c *il_operator) { const char *name = NULL; + identifier_c *res; op_2_str(NOT, "NOT"); @@ -5282,8 +5353,14 @@ if (name == NULL) ERROR; + res = new identifier_c(strdup(name), + il_operator->first_line, + il_operator->first_column, + il_operator->last_line, + il_operator->last_column + ); free(il_operator); - return new identifier_c(strdup(name)); + return res; } @@ -5298,8 +5375,8 @@ "R_TRIG","F_TRIG", // 2.5.2.3.3 Counters // Table 36 - Standard counter function blocks -"CTU","CTU_LINT","CTU_UDINT","CTU_ULINT", -"CTD","CTD_DINT","CTD_LINT","CTD_UDINT", +"CTU","CTU_DINT","CTU_LINT","CTU_UDINT","CTU_ULINT", +"CTD","CTD_DINT","CTD_LINT","CTD_UDINT","CTD_ULINT", "CTUD","CTUD_DINT","CTUD_LINT","CTUD_ULINT", // 2.5.2.3.4 Timers // Table 37 - Standard timer function blocks