stage1_2/iec.y
changeset 95 b119b1db0a7a
parent 94 40288323acc0
child 96 23baa8821b58
equal deleted inserted replaced
94:40288323acc0 95:b119b1db0a7a
   153 
   153 
   154 /* Convert an il_operator_c into an identifier_c */
   154 /* Convert an il_operator_c into an identifier_c */
   155 symbol_c *il_operator_c_2_identifier_c(symbol_c *il_operator);
   155 symbol_c *il_operator_c_2_identifier_c(symbol_c *il_operator);
   156 
   156 
   157 /* print an error message */
   157 /* print an error message */
   158 void print_err_msg(const char *filename, int lineno, const char *additional_error_msg);
   158 void print_err_msg(const char *filename,
   159 
   159                    int first_line,
       
   160                    int first_column,
       
   161                    int last_line,
       
   162                    int last_column,
       
   163                    const char *additional_error_msg);
   160 %}
   164 %}
   161 
   165 
   162 
   166 
   163 
   167 
   164 
   168 
  1392 | library library_element_declaration
  1396 | library library_element_declaration
  1393 	{$$ = $1; $$->add_element($2);}
  1397 	{$$ = $1; $$->add_element($2);}
  1394 /* ERROR_CHECK_BEGIN */
  1398 /* ERROR_CHECK_BEGIN */
  1395 | library error END_OF_INPUT
  1399 | library error END_OF_INPUT
  1396 	{$$ = NULL;
  1400 	{$$ = NULL;
  1397 	 print_err_msg(current_filename, @2.first_line, "unknown error.");
  1401 	 print_err_msg(current_filename, locf(@2), locl(@2), "unknown error.");
  1398 	 yyerrok;
  1402 	 yyerrok;
  1399 	}
  1403 	}
  1400 /* ERROR_CHECK_END */
  1404 /* ERROR_CHECK_END */
  1401 ;
  1405 ;
  1402 
  1406 
  2635 	{$$ = new input_declarations_c(NULL, $2, locloc(@$));}
  2639 	{$$ = new input_declarations_c(NULL, $2, locloc(@$));}
  2636 | VAR_INPUT RETAIN     input_declaration_list END_VAR
  2640 | VAR_INPUT RETAIN     input_declaration_list END_VAR
  2637 	{$$ = new input_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));}
  2641 	{$$ = new input_declarations_c(new retain_option_c(locloc(@2)), $3, locloc(@$));}
  2638 | VAR_INPUT NON_RETAIN input_declaration_list END_VAR
  2642 | VAR_INPUT NON_RETAIN input_declaration_list END_VAR
  2639 	{$$ = new input_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));}
  2643 	{$$ = new input_declarations_c(new non_retain_option_c(locloc(@2)), $3, locloc(@$));}
       
  2644 /* ERROR_CHECK_BEGIN */
       
  2645 | VAR_INPUT error END_VAR
       
  2646 	{$$ = NULL;
       
  2647 	 print_err_msg(current_filename, locf(@1), locl(@3), "error in input variable(s) declaration.");
       
  2648 	 /* yychar */
       
  2649 	 yyerrok;
       
  2650 	}
       
  2651 /* ERROR_CHECK_END */
       
  2652 
  2640 ;
  2653 ;
  2641 
  2654 
  2642 /* helper symbol for input_declarations */
  2655 /* helper symbol for input_declarations */
  2643 input_declaration_list:
  2656 input_declaration_list:
  2644   input_declaration ';'
  2657   input_declaration ';'
  3369 	 }
  3382 	 }
  3370 	}
  3383 	}
  3371 /* ERROR_CHECK_BEGIN */
  3384 /* ERROR_CHECK_BEGIN */
  3372 | FUNCTION error END_FUNCTION
  3385 | FUNCTION error END_FUNCTION
  3373 	{$$ = NULL;
  3386 	{$$ = NULL;
  3374 	 print_err_msg(current_filename, @2.first_line, "error in function declaration.");
  3387 	 print_err_msg(current_filename, locf(@1), locl(@3), "error in function declaration.");
  3375 	 /* yychar */
  3388 	 /* yychar */
  3376 	 yyerrok;
  3389 	 yyerrok;
  3377 	}
  3390 	}
  3378 /* ERROR_CHECK_END */
  3391 /* ERROR_CHECK_END */
  3379 ;
  3392 ;
  3505 	 variable_name_symtable.pop();
  3518 	 variable_name_symtable.pop();
  3506 	}
  3519 	}
  3507 /* ERROR_CHECK_BEGIN */
  3520 /* ERROR_CHECK_BEGIN */
  3508 | FUNCTION_BLOCK error END_FUNCTION_BLOCK
  3521 | FUNCTION_BLOCK error END_FUNCTION_BLOCK
  3509 	{$$ = NULL;
  3522 	{$$ = NULL;
  3510 	 print_err_msg(current_filename, @2.first_line, "error in function block declaration.");
  3523 	 print_err_msg(current_filename, locf(@1), locl(@3), "error in function block declaration.");
  3511 	 /* yychar */
  3524 	 /* yychar */
  3512 	 yyerrok;
  3525 	 yyerrok;
  3513 	}
  3526 	}
  3514 /* ERROR_CHECK_END */
  3527 /* ERROR_CHECK_END */
  3515 ;
  3528 ;
  3610 	 variable_name_symtable.pop();
  3623 	 variable_name_symtable.pop();
  3611 	}
  3624 	}
  3612 /* ERROR_CHECK_BEGIN */
  3625 /* ERROR_CHECK_BEGIN */
  3613 | PROGRAM error END_PROGRAM
  3626 | PROGRAM error END_PROGRAM
  3614 	{$$ = NULL;
  3627 	{$$ = NULL;
  3615 	 print_err_msg(current_filename, @2.first_line, "error in function block declaration.");
  3628 	 print_err_msg(current_filename, locf(@1), locl(@3), "error in function block declaration.");
  3616 	 /* yychar */
  3629 	 /* yychar */
  3617 	 yyerrok;
  3630 	 yyerrok;
  3618 	}
  3631 	}
  3619 /* ERROR_CHECK_END */
  3632 /* ERROR_CHECK_END */
  3620 ;
  3633 ;
  3913 	 variable_name_symtable.pop();
  3926 	 variable_name_symtable.pop();
  3914 }
  3927 }
  3915 /* ERROR_CHECK_BEGIN */
  3928 /* ERROR_CHECK_BEGIN */
  3916 | CONFIGURATION error END_CONFIGURATION
  3929 | CONFIGURATION error END_CONFIGURATION
  3917 	{$$ = NULL;
  3930 	{$$ = NULL;
  3918 	 print_err_msg(current_filename, @2.first_line, "error in configuration declaration.");
  3931 	 print_err_msg(current_filename, locf(@1), locl(@3), "error in configuration declaration.");
  3919 	 /* yychar */
  3932 	 /* yychar */
  3920 	 yyerrok;
  3933 	 yyerrok;
  3921 	}
  3934 	}
  3922 /* ERROR_CHECK_END */
  3935 /* ERROR_CHECK_END */
  3923 ;
  3936 ;
  4329 | label ':' il_incomplete_instruction eol_list
  4342 | label ':' il_incomplete_instruction eol_list
  4330 	{$$ = new il_instruction_c($1, $3, locloc(@$));}
  4343 	{$$ = new il_instruction_c($1, $3, locloc(@$));}
  4331 /* ERROR_CHECK_BEGIN */
  4344 /* ERROR_CHECK_BEGIN */
  4332 | error eol_list
  4345 | error eol_list
  4333 	{$$ = NULL;
  4346 	{$$ = NULL;
  4334 	 print_err_msg(current_filename, @1.first_line, "error in IL instruction.");
  4347 	 print_err_msg(current_filename, locf(@1), locl(@1), "error in IL instruction.");
  4335 	 yyerrok;
  4348 	 yyerrok;
  4336 	}
  4349 	}
  4337 /* ERROR_CHECK_END */
  4350 /* ERROR_CHECK_END */
  4338 /* ERROR_CHECK_BEGIN */
  4351 /* ERROR_CHECK_BEGIN */
  4339 | label ':' error eol_list
  4352 | label ':' error eol_list
  4340 	{$$ = NULL;
  4353 	{$$ = NULL;
  4341 	 print_err_msg(current_filename, @1.first_line, "error in IL instruction.");
  4354 	 print_err_msg(current_filename, locf(@1), locl(@3), "error in IL instruction.");
  4342 	 yyerrok;
  4355 	 yyerrok;
  4343 	}
  4356 	}
  4344 /* ERROR_CHECK_END */
  4357 /* ERROR_CHECK_END */
  4345 ;
  4358 ;
  4346 
  4359 
  5005 | statement_list pragma
  5018 | statement_list pragma
  5006 	{$$ = $1; $$->add_element($2);}
  5019 	{$$ = $1; $$->add_element($2);}
  5007 /* ERROR_CHECK_BEGIN */
  5020 /* ERROR_CHECK_BEGIN */
  5008 | statement_list error ';'
  5021 | statement_list error ';'
  5009 	{$$ = $1;
  5022 	{$$ = $1;
  5010 	 print_err_msg(current_filename, @2.first_line, "error in statement.");
  5023 	 print_err_msg(current_filename, locf(@2), locl(@2), "error in statement.");
  5011 	 /* yychar */
  5024 	 /* yychar */
  5012 	 yyerrok;
  5025 	 yyerrok;
  5013 	}
  5026 	}
  5014 /* ERROR_CHECK_END */
  5027 /* ERROR_CHECK_END */
  5015 ;
  5028 ;
  5305 /* fprintf(stderr, "error %d: %s\n", yynerrs // global variable //, error_msg); */
  5318 /* fprintf(stderr, "error %d: %s\n", yynerrs // global variable //, error_msg); */
  5306 /*  print_include_stack(); */
  5319 /*  print_include_stack(); */
  5307 }
  5320 }
  5308 
  5321 
  5309 
  5322 
  5310 void print_err_msg(const char *filename, int lineno, const char *additional_error_msg) {
  5323 void print_err_msg(const char *filename,
       
  5324                    int first_line,
       
  5325                    int first_column,
       
  5326                    int last_line,
       
  5327                    int last_column,
       
  5328                    const char *additional_error_msg) {
  5311   fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg);
  5329   fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg);
  5312   print_include_stack();
  5330   print_include_stack();
  5313   fprintf(stderr, "%s:%d: %s\n", filename, lineno, current_error_msg);
  5331   fprintf(stderr, "%s(%d-%d): %s\n", filename, first_line, last_line, current_error_msg);
  5314 }
  5332 }
  5315 
  5333 
  5316 
  5334 
  5317 
  5335 
  5318 /* convert between an il_operator to a function name */
  5336 /* convert between an il_operator to a function name */