忽略 yacc/lex 中的错误
我是 yacc/lex 的新手,我正在开发一个由其他人编写的解析器。我注意到,当找到未定义的标记时,解析器返回错误并停止。有没有一种简单的方法可以让它完全忽略它无法解析的行并继续进行下一个?
I'm new to yacc/lex and I'm working on a parser that was written by someone else. I notice that when an undefined token is found, the parser returns an error and stops. Is there a simple way to just make it ignore completely lines that it cannot parse and just move on to the next one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需添加一个看起来像
在所有规则底部的规则,它就会忽略遇到的所有不符合任何先前规则的规则。
编辑:如果您有多个状态,那么在任何状态下都有效的包罗万象将如下所示:
just add a rule that looks like
at the bottom of all of your rules, and it will just ignore everything it comes across that doesn't fit any of the previous rules.
Edit: if you have multiple states, then a catch-all that works in any state would then look like: