flex yy_fatal_error exist just like that. I want handler back to application

筅森魡賤 提交于 2020-01-15 12:12:47

问题


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 #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:

  • 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!