在执行任何规则之前,如何在FLEX中初始化?
我的Lexer规则依赖于被人群的数组。因此,在执行任何规则之前,我需要初始化数组。我可以使用yy_user_action
进行初始化(检查全局标志以查看是否未设置,如果是这样,请调用INIT函数),但这会非常效率,因为它检查了该数组是否被初始化对于每个规则。有没有办法表达出来:“在执行任何规则之前运行此代码。”?
My lexer rules rely on an array being populated. So, before any rules are executed, I need to initialize the array. I could use YY_USER_ACTION
to do the initializing (check a global flag to see if it's not set, if so call the init function) but that would be very inefficient as it checks to see if the array is initialized for every rule. Is there a way in Flex to express: "Run this code before executing any rules."?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
宏 就是这样做的。
(您说您使用的是专门使用的。其他LEX实现可能不支持它。)
您与提到的
yy_user_action
相似。The macro
YY_USER_INIT
does exactly that.(You said you're using specifically Flex. Other Lex implementations may not support it.)
You use it similarly to the mentioned
YY_USER_ACTION
.