ECMAScript 的 EBNF?
我正在尝试找到 ECMAScript 的良好 EBNF 描述,但到目前为止我还没有找到任何完整的内容。
有什么想法吗?
I'm trying to find a good EBNF description of ECMAScript, but so far I've not found anything complete.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ECMAScript 标准怎么样?
根据定义完成:-}
编辑:如果您想要现有语法,请尝试语法生成器工具站点之一。
对于 ANTLR,这是
ECMAScript 语法。
我对其质量一无所知,但如果语法构建器精心构建,ANTLR 可以产生良好的解析器。您可能会发现语法也与一堆 ANTLR 内容交织在一起,因此从您的角度来看,它可能会遇到与标准相同的问题。至少你可以删除所有这些东西。
How about the ECMAScript standard?
Complete by definition :-}
EDIT: If you want an existing grammar, try one of the grammar generator tools sites.
For ANTLR, here's the
ECMAScript grammar.
I know nothing of its quality but the ANTLR can produce good parsers if the grammer is constructed with care. You'll probably find the grammar also interwoven with bunch of ANTLR stuff, so it may suffer from some of the same problem as the standard from your point of view. At least you can delete all that stuff out.
Crockford 的 JavaScript: The Good Parts 的第 2 章用图表(你猜对了)介绍了好的部分。
以下是 BNF for JavaScript 的一些尝试:
来自这个早期的SO问题:
BNF语法的存储库?
Chapter 2 of Crockford's JavaScript: The Good Parts diagrams (you guessed it) the good parts.
Here are a couple stabs at BNF for JavaScript:
from this earlier SO question:
Repository of BNF Grammars?
我正在为 ECMAScript 开发基于 javacc 的解析器。到目前为止,这是我的语法:
另请参阅 Tom Copeland 的 EcmaScript BNF:
以及“另一个 JavaScript 解释器”:
以及Dojo Toolkit的语法(可能基于YAJI) :
从我的角度来看,YAJI 或 Dojo Toolkit 是最好的、最完整的(最好的)据我所知)。我的工作基于这些,但希望使其更加完整(5.1/6)、符合标准但实用。
ECMAScript 语法非常棘手。它有一些巨大的警告:
所以请注意这一点。实施这些非常棘手。
如果您的目标平台是 Java 并且您不介意 JavaCC,我会很高兴您加入我的项目。我的语法实际上已经准备好了(构建/编译时没有警告)。我现在正在开发测试套件,以涵盖每个功能和生产。不过,我预计正则表达式文字和 ASI 会出现一些问题。
附:我刚刚注意到这个问题是 09 年提出的,所以我的邀请可能已经太晚了。 :)
I am working on javacc-based parser for ECMAScript. Here's my grammar so far:
See also Tom Copeland's BNF for EcmaScript:
As well as "Yet Another JavaScript Interpreter":
As well as Dojo Toolkit's Grammar (probably based on YAJI):
From my point of view, YAJI or Dojo Toolkit's are the best and the most complete (to the best of my knowledge). I'm basing my work on those but want to make it even more complete (5.1/6) and standard-conform yet practical.
ECMAScript grammar is very tricky. It has a few huge caveats:
So please be aware of that. Implementing those is very tricky.
If your target platform Java and you don't mind JavaCC, I'd be glad if you join my project. My grammar is actually ready (builds/compiles without warnings). I'm now working on test suites to cover each and every feature and production. I anticipate some problems with regex literals and ASIs though.
ps. I've just noticed that the question is from 09 so my invitation is probably too late. :)