Flex的折返与启动条件 [英] Flex reentrant with start conditions

查看:172
本文介绍了Flex的折返与启动条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个折返扫描仪,它依赖于启动条件。​​

我正沿着类似这样的家伙问题下面的东西

编写重入词法分析器使用Flex

和作为一张海报提到的,扫描仪会工作,如果你明确地创建 yyscan_t ,并把它作为一个额外的参数。不过,我仍然在使用时,你得到 YYG不宣错误信息 BEGIN< SC> 等操纵启动条件。

这是一个错误吗?我应该明确地使用 yy_push_state yy_pop_state 国家职能呢?


解决方案

看起来当您使用%选择折返您只能使用 BEGIN像 YY_START 在你的词法分析器的动作部分,而不是在code部分。有意义的,因为操纵解析器状态需要访问解析器状态,但 BEGIN 不带任何参数,所以没有办法提供。使用%选择堆栈 yy_push / pop_state 似乎是一个合理的解决办法。

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?

解决方案

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.

这篇关于Flex的折返与启动条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆