flex yy_fatal_error exist just like that. I want h

2019-08-08 16:53发布

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.

标签: flex-lexer
1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-08 17:16

You can override the function, by #defineing 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:

查看更多
登录 后发表回答