为解析器编写规则
嗨,
我有一个解析器,它有很多规则,它的所有工作都没有问题。我正在使用 lex 和 yacc...
问题是我想要一个规则,如果输入字符串与定义的任何规则都不匹配在解析器中,我想编写一个接受此类输入字符串的规则。
所以基本上我想做的是,如果输入与任何其他规则不匹配,我不希望解析器停止给出错误消息,我想显示该错误消息,然后使解析器继续解析而不是退出..
我知道我必须在 yyerror() 函数中进行更改,但究竟如何..或者是否还有其他我可以编写这样的规则.. 。
谢谢.. :)
Hii,
I have a parser which has many rules and no problem with it its all working.. i am using lex and yacc...
The problem is i want a rule such that if the input string does not match any of the rules defined in the parser then i want to write a rule which will accept such input string..
So basically what i want to do is that i dont want the parser to stop give an error message on itself if the input does not match any other rule, i want to display that error message and then make the parser continue its parsing instead of exiting..
I kno i have to make changes in yyerror() function but how exactly.. or is there any other i can write such a rule...
Thanks.. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以放置“.”。 (点)位于其他解析规则的末尾。它匹配任何其他规则未匹配的字符串。请参阅此 链接了解详细信息。
希望,这就是你的意思。
编辑:看来我误解了。要定义默认操作,您只需将
{ }
操作放入解析器文件中即可。请参阅此处。You can place the "." (dot) at the end of other parsing rules. It matches any string that has not matched by other rules. See this link for details.
Hope, it's what you meant.
Edit: It seams I have misunderstood. To define default action you can simply put
{ }
action in the parser file. See here.