Flex reentrant with start conditions

人盡茶涼 提交于 2020-01-04 09:18:27

问题


I am trying to make a reentrant scanner that relies on start conditions.

I was following along something similar to this guys question:

Writing re-entrant lexer with Flex

And as the one poster mentioned, the scanner will work if you explicitly create the yyscan_t and pass it as an extra argument. However, I still get the yyg undeclared error message when using BEGIN <sc> , etc to manipulate the start condition.

Is this a bug? Should I explicity use the yy_push_state and yy_pop_state state functions instead?


回答1:


Looks like when you use %option reentrant you can only use BEGIN and YY_START in the actions section of your lexer, and not in the code section. Makes sense as manipulating the parser state requires access to the parser state, but BEGIN doesn't take any arguments, so there's no way to provide it. Using %option stack and yy_push/pop_state seems like a reasonable workaround.



来源:https://stackoverflow.com/questions/13957454/flex-reentrant-with-start-conditions

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