Here is a piece of code written by lex,
%%
* Printf ("Hello / N");
Quit exit (0);
%%
Main ()
{
Yylex ();
Printf ("BYE / N");
}
How to print the results after the program ending after the end of the program is not thoroughly understanding the file flow after the LEX compilation? We will perform compiled executables will find that if we just use Ctrl C or Quit Exit programs to exit the program directly in the current position, the following printf will not be executed at all. Solve this small problem, I will implement it with an indirect method:
% {
#include
#include
JMP_BUF Position;
%}
%%
Quit Longjmp (position, 1);
* Printf ("Hello / N");
%%
Main ()
{
EXTERN INT function ();
IF (setjmp (position) == 1)
Goto quit;
Signal (SIGINT, FUNCTION);
Yylex ();
Quit:
Printf ("BYE / N");
exit (0);
}
Function ()
{
Longjmp (position, 1);
}
The above code is debugged under AIX