问题
flex yy_fatal_error
exist just like that. But I want handler back to my application. How to avoid exist call? from yy_fatal_error. whether this problem addressed in any version? your suggestion is highly appreciated. help me on this issues.
回答1:
You can override the function, by #define
ing your own. Note that in the generated code there is
/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
#endif
If you #define
the macro YY_FATAL_ERROR(msg)
to call your own function, the lexer will call that function rather than the one from the template.
However, the lexer template is written to assume that this function does not return. You can make it do that by using setjmp and longjmp
to prepare a predictable place to return in your application and jumping back (from your own yy_fatal_error
function) to that when a "fatal" error is used.
vi like emacs does this for instance, because it uses lexers for syntax highlighting. If a fatal error is generated by the lexer, you would not want the editor to stop.
Here are a few links discussing setjmp
and longjmp
:
- Practical usage of setjmp and longjmp in C
- setjmp and longjmp - understanding with examples
来源:https://stackoverflow.com/questions/30341967/flex-yy-fatal-error-exist-just-like-that-i-want-handler-back-to-application