忽略yacc/lex中的错误 [英] Ignoring errors in yacc/lex
本文介绍了忽略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?
推荐答案
只需添加一个类似于
. {
// do nothing
}
位于所有规则的底部,它只会忽略碰到的所有不符合先前任何规则的东西.
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.
如果您有多个状态,则可以在任何状态下工作的包罗万象:
if you have multiple states, then a catch-all that works in any state would then look like:
<*>. {
}
这篇关于忽略yacc/lex中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文