使用EBNF或BNF编写递归下降解析器是否更容易? [英] Is it easier to write a recursive-descent parser using an EBNF or a BNF?

查看:113
本文介绍了使用EBNF或BNF编写递归下降解析器是否更容易?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个语法的BNF和EBNF. BNF显然更冗长.就使用BNF构造递归下降解析器而言,我有一个相当不错的主意.有很多资源.我很难找到将EBNF转换为递归下降解析器的资源.这是因为更困难吗?我从CS理论课上回想起我们曾经讨论过EBNF,但是并没有将它们转换成递归下降解析器.我们 did 将BNF转换为递归下降解析器.

I've got a BNF and EBNF for a grammar. The BNF is obviously more verbose. I have a fairly good idea as far as using the BNF to build a recursive-descent parser; there are many resources for this. I am having trouble finding resources to convert an EBNF to a recursive-descent parser. Is this because it's more difficult? I recall from my CS theory classes that we went over EBNFs, but we didn't go over converting them into a recursive-descent parser. We did go over converting BNF's into a recursive-descent parser.

我问的原因是因为EBNF更紧凑.

The reason I'm asking is because the EBNF is more compact.

从一般的EBNF来看,我注意到{}之间包含的术语可以转换为while循环.还有其他准则或规则吗?

From looking at the EBNF's in general, I notice that terms enclosed between { and } can be converted into a while loop. Are there any other guidelines or rules?

推荐答案

任何一个都不比另一个更难.确实是迭代实现某些东西和递归实现一些东西之间的区别.在BNF中,一切都是递归的.在EBNF中,某些递归是迭代表达的. EBNF语法有不同的变体,因此我将只使用英语...零或更多"是您发现的一个简单的while循环. 一个或多个"与后跟零个或多个"的相同. 零或一次"是一个简单的if语句.那应该涵盖大多数情况.

Neither is harder than the other. It is really the difference between implementing something iteratively and implementing something recursively. In BNF, everything is recursive. In EBNF, some of the recursion is expressed iteratively. There are different variations in EBNF syntax, so I'll just use the English... "zero or more" is a simple while loop as you have discovered. "One or more" is the same as one followed by "zero or more". "Zero or one times" is a simple if statement. That should cover most of the cases.

这篇关于使用EBNF或BNF编写递归下降解析器是否更容易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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