BNF 学说有什么用?
看起来很乱,如何作为参考?
http://www.doctrine- project.org/documentation/manual/1_1/en/dql-doctrine-query-language%3Abnf
It looks like a big mess,how does it work as reference?
http://www.doctrine-project.org/documentation/manual/1_1/en/dql-doctrine-query-language%3Abnf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,我认为它没有被任何人用作参考;但如果有人想使用一些理解 BNF 的自动工具,它可能会很有用;例如,某种代码生成器。
BNF 的优点在于它是描述语言的一种正式方式——当你是一个程序时,它比英语更容易理解。
供参考:
在评论后编辑: 这是一个关于 DQL / 对象内容的简单示例:
让我们考虑这部分代码,它使用面向对象的 API 编写查询、执行查询并获取结果(水合为数组 - 打印出来调试时只有数据,这样):
这是您将得到的输出类型:
当然,这是考虑到模式和模型类都可以 - 对于中的示例感到抱歉法语,我使用了不久前设置的模式/模型/数据库来演示 Doctrine,它是法语的。
基本上,数据库用于博客应用程序,在这里,我们:
现在,这里有一个等价的,使用我所说的“DQL”作为“伪 SQL 语言”:
这里没有面向对象的 API (好吧,我的意思是编写查询):我只写了我正在考虑的伪 SQL——据我所知,这就是 BNF 所描述的。
当然,var_dump 的输出与我之前得到的输出完全相同。
我希望这能让事情变得更清楚:-)
I don't think it's used as a reference by any human-being, actually ; but it might be useful if someone want to use some automatic tool that understands BNF ; for instance, some kind of code generator.
The advantage of BNF being that's it's a formal way to describe a language -- much more easier to understand than english, when you are a program.
For reference :
Edit after the comments : Here's a quick example about the DQL / Object stuff :
Let's consider this portion of code, which is using the object-oriented API to write a query, execute it, and get the results (hydrated as arrays -- prints out only the data, this way, when debugging) :
And here's the kind of output you'll get :
Of course, this is considering the schema and models classes are OK -- and sorry for the example in french, I used a schema/model/database I set up some time ago for a demonstration of Doctrine, which was in french.
Basically, the DB is for a blogging application, and, here, we :
Now, here's an equivalent, using what I meant by "DQL" as in "pseudo-SQL language" :
No object-oriented API here (well, to write the query, I mean) : I only wrote that pseudo-SQL I was thinking about -- which is what the BNF describes, as far as I can tell.
And, of course, the output of the
var_dump
is exactly the same as the one I got before.I hope this makes things a bit more clear :-)
这就是巴科斯-诺尔范式,一种描述上下文无关语法的方法。请参阅这篇维基百科文章。
It's Backus–Naur Form, a method of describing context free grammars. See this wikipedia article.