有没有办法改变野牛的挠曲开始状态? [英] Is there a way to change the flex start state from bison?

查看:85
本文介绍了有没有办法改变野牛的挠曲开始状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在词法分析器中定义了不同的状态,这些状态不取决于标记,而取决于标记序列(类似于模板引擎的工作方式).我可以定义更长的令牌,但是我更喜欢这种方法.

I have defined different states in my lexer, which change not depending on the token but on a sequence of tokens (similarly to how template engines work). I can define longer tokens but I somehow like this approach better.

推荐答案

您可以将一个函数粘贴在使用BEGIN宏的.l文件的第三部分中,然后从您的bison动作(或其他任何地方)中调用该函数对于这个问题).您需要注意以下事实,即野牛可能会在减少规则(运行其动作)之前预先读取令牌,因此在正确的瞬间设置正确的状态可能会很棘手.

You can stick a function in the third section of the .l file that uses the BEGIN macro, and then call that function from your bison action (or anywhere else for that matter). You need to be careful of the fact that bison may read ahead a token before reducing a rule (running its action), so getting the right state set at the right instant can be tricky.

这篇关于有没有办法改变野牛的挠曲开始状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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