I've a piece of code for a compiler for basic arithmetic (add, diff). In my mparse.y yacc file, I've read input from a file in main function. To invoke parsing, I've put the condition as follows:
if(yyparse()==0)
fprintf(stderr,"Parsing complete.");
the last statement of yyparse, after completion is supposed to be:
printf("The last statement of yyparse");
The problem is, if I use fprintf(), I get the following absurd output:
Parsing Complete
The last statement of yyparse.
Whereas, if I use printf instead of fprintf, I get the normal output.
The last statement of yyparse
Parsing complete.
Shouldn't the second option be correct, ie, all the statements of yyparse should be executed first and then the printf after if? Why this weird behaviour?