将 EBNF 语法转换为上下文无关语法
我必须编写一个 JavaCUP 规范,并且我得到了 EBNF 语法。但是,我不知道如何在两者之间进行转换。我听说过基本的想法,但我真的不明白我需要改变什么,“终端”是什么,等等。
任何人都可以解释如何从一种转换为另一种,或者是否有地方我可以阅读关于它?
I have to write a JavaCUP specification, and I've been given an EBNF grammar. However, I don't know how to convert between the two. I've heard the basic ideas, but I don't really understand what I need to change, what would be the "terminals", etc.
Can anyone explain how to convert from one to another, or if there's somewhere where I can read about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EBNF 语法与普通 BNF 类似,但具有一些额外的功能(类似于正则表达式运算符)作为语法糖。由于您没有显示语法,我只能猜测您需要脱糖以转换为正常 BNF 的哪些部分,但以下是最常见的部分(对于像 JavaCUP 这样的 LALR 生成器):
epsilon
标识符然而,您的解析器生成器表示空字符串。EBNF grammars are similar to normal BNF, but with some extra features (similar to regular expression operators) as syntax sugar. Since you did not show your grammar, I can only guess at what parts you need to desugar to convert to normal BNF, but here are the most common (for a LALR generator like JavaCUP):
The
epsilon
identifier here is however your parser generator denotes the empty string.