7969 |
7969 |
7970 #include <stdio.h> /* required for printf() */ |
7970 #include <stdio.h> /* required for printf() */ |
7971 #include <errno.h> |
7971 #include <errno.h> |
7972 #include "../util/symtable.hh" |
7972 #include "../util/symtable.hh" |
7973 |
7973 |
7974 /* variables defined in code generated by flex... */ |
|
7975 extern FILE *yyin; |
|
7976 extern int yylineno; |
|
7977 extern tracking_t* current_tracking; |
|
7978 |
|
7979 |
7974 |
7980 |
7975 |
7981 |
7976 |
7982 /*************************************************************************************************/ |
7977 /*************************************************************************************************/ |
7983 /* NOTE: These variables are really parameters we would like the stage2__ function to pass */ |
7978 /* NOTE: These variables are really parameters we would like the stage2__ function to pass */ |
8100 } else { |
8095 } else { |
8101 fprintf(stderr, "%s:%d: error: %s\n", first_filename, first_line, additional_error_msg); |
8096 fprintf(stderr, "%s:%d: error: %s\n", first_filename, first_line, additional_error_msg); |
8102 } |
8097 } |
8103 //fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg); |
8098 //fprintf(stderr, "error %d: %s\n", yynerrs /* a global variable */, additional_error_msg); |
8104 print_include_stack(); |
8099 print_include_stack(); |
8105 //fprintf(stderr, "%s(%d-%d): %s\n", current_filename, first_line, last_line, current_error_msg); |
|
8106 } |
8100 } |
8107 |
8101 |
8108 |
8102 |
8109 |
8103 |
8110 /* If function overloading is on, we allow several functions with the same name. |
8104 /* If function overloading is on, we allow several functions with the same name. |
8251 const char *includedir, /* Include directory, where included files will be searched for... */ |
8245 const char *includedir, /* Include directory, where included files will be searched for... */ |
8252 symbol_c **tree_root_ref, |
8246 symbol_c **tree_root_ref, |
8253 bool full_token_loc_ /* error messages specify full token location */ |
8247 bool full_token_loc_ /* error messages specify full token location */ |
8254 ) { |
8248 ) { |
8255 |
8249 |
8256 FILE *in_file = NULL, *lib_file = NULL; |
|
8257 char *libfilename = NULL; |
8250 char *libfilename = NULL; |
8258 |
|
8259 if((in_file = fopen(filename, "r")) == NULL) { |
|
8260 char *errmsg = strdup2("Error opening main file ", filename); |
|
8261 perror(errmsg); |
|
8262 free(errmsg); |
|
8263 return -1; |
|
8264 } |
|
8265 |
8251 |
8266 if (includedir != NULL) { |
8252 if (includedir != NULL) { |
8267 INCLUDE_DIRECTORIES[0] = includedir; |
8253 INCLUDE_DIRECTORIES[0] = includedir; |
8268 } |
|
8269 if ((libfilename = strdup3(INCLUDE_DIRECTORIES[0], "/", LIBFILE)) == NULL) { |
|
8270 fprintf (stderr, "Out of memory. Bailing out!\n"); |
|
8271 return -1; |
|
8272 } |
|
8273 |
|
8274 if((lib_file = fopen(libfilename, "r")) == NULL) { |
|
8275 char *errmsg = strdup2("Error opening library file ", libfilename); |
|
8276 perror(errmsg); |
|
8277 free(errmsg); |
|
8278 } |
|
8279 |
|
8280 if (lib_file == NULL) { |
|
8281 /* we give up... */ |
|
8282 free(libfilename); |
|
8283 fclose(in_file); |
|
8284 return -1; |
|
8285 } |
8254 } |
8286 |
8255 |
8287 /* first parse the standard library file... */ |
8256 /* first parse the standard library file... */ |
8288 /* Do not debug the standard library, even if debug flag is set! */ |
8257 /* Do not debug the standard library, even if debug flag is set! */ |
8289 /* |
8258 /* |
8290 #if YYDEBUG |
8259 #if YYDEBUG |
8291 yydebug = 1; |
8260 yydebug = 1; |
8292 #endif |
8261 #endif |
8293 */ |
8262 */ |
8294 yyin = lib_file; |
8263 |
|
8264 if ((libfilename = strdup3(INCLUDE_DIRECTORIES[0], "/", LIBFILE)) == NULL) { |
|
8265 fprintf (stderr, "Out of memory. Bailing out!\n"); |
|
8266 return -1; |
|
8267 } |
|
8268 |
|
8269 if(parse_file(libfilename) < 0) { |
|
8270 char *errmsg = strdup2("Error opening library file ", libfilename); |
|
8271 perror(errmsg); |
|
8272 free(errmsg); |
|
8273 /* we give up... */ |
|
8274 return -1; |
|
8275 } |
|
8276 |
8295 allow_function_overloading = true; |
8277 allow_function_overloading = true; |
8296 allow_extensible_function_parameters = true; |
8278 allow_extensible_function_parameters = true; |
8297 full_token_loc = full_token_loc_; |
8279 full_token_loc = full_token_loc_; |
8298 current_filename = libfilename; |
|
8299 current_tracking = GetNewTracking(yyin); |
|
8300 if (yyparse() != 0) |
8280 if (yyparse() != 0) |
8301 ERROR; |
8281 ERROR; |
8302 |
8282 |
8303 if (yynerrs > 0) { |
8283 if (yynerrs > 0) { |
8304 fprintf (stderr, "\n%d error(s) found in %s. Bailing out!\n", yynerrs /* global variable */, libfilename); |
8284 fprintf (stderr, "\n%d error(s) found in %s. Bailing out!\n", yynerrs /* global variable */, libfilename); |
8305 ERROR; |
8285 ERROR; |
8306 } |
8286 } |
8307 free(libfilename); |
8287 free(libfilename); |
8308 fclose(lib_file); |
|
8309 |
8288 |
8310 /* if by any chance the library is not complete, we |
8289 /* if by any chance the library is not complete, we |
8311 * now add the missing reserved keywords to the list!!! |
8290 * now add the missing reserved keywords to the list!!! |
8312 */ |
8291 */ |
8313 for(int i = 0; standard_function_block_names[i] != NULL; i++) |
8292 for(int i = 0; standard_function_block_names[i] != NULL; i++) |
8318 |
8297 |
8319 /* now parse the input file... */ |
8298 /* now parse the input file... */ |
8320 #if YYDEBUG |
8299 #if YYDEBUG |
8321 yydebug = 1; |
8300 yydebug = 1; |
8322 #endif |
8301 #endif |
8323 yyin = in_file; |
8302 |
|
8303 if(parse_file(filename) < 0) { |
|
8304 char *errmsg = strdup2("Error opening main file ", filename); |
|
8305 perror(errmsg); |
|
8306 free(errmsg); |
|
8307 return -1; |
|
8308 } |
|
8309 |
8324 allow_function_overloading = false; |
8310 allow_function_overloading = false; |
8325 allow_extensible_function_parameters = false; |
8311 allow_extensible_function_parameters = false; |
8326 full_token_loc = full_token_loc_; |
8312 full_token_loc = full_token_loc_; |
8327 current_filename = filename; |
8313 |
8328 current_tracking = GetNewTracking(yyin); |
8314 if (yyparse() != 0) { |
8329 {int res; |
8315 fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n"); |
8330 if ((res = yyparse()) != 0) { |
8316 exit(EXIT_FAILURE); |
8331 fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n"); |
|
8332 exit(EXIT_FAILURE); |
|
8333 } |
|
8334 } |
8317 } |
8335 |
8318 |
8336 if (yynerrs > 0) { |
8319 if (yynerrs > 0) { |
8337 fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */); |
8320 fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */); |
8338 exit(EXIT_FAILURE); |
8321 exit(EXIT_FAILURE); |
8339 } |
8322 } |
8340 |
8323 |
8341 if (tree_root_ref != NULL) |
8324 if (tree_root_ref != NULL) |
8342 *tree_root_ref = tree_root; |
8325 *tree_root_ref = tree_root; |
8343 |
8326 |
8344 fclose(in_file); |
|
8345 return 0; |
8327 return 0; |
8346 } |
8328 } |
8347 |
8329 |
8348 |
8330 |
8349 |
8331 |