Is there a BNF grammar openly available for JavaScript ES6? [closed]
Asked Answered
B

2

13

I am working on a merge tool for JavaScript programs, and I need to write a grammar for JavaScript (version >= ES6) in JavaCC format.

For that, I want to use an openly available BNF grammar for ES6, then I would write the grammar in JavaCC format from it.

I was able to find only those (from this Stack Overflow question):

However, these are very old BNFs (and the question on StackOverflow is also very old, from 11 years ago). These grammars work only - and in a limited manner - for versions < ES6.

Do you know about a newer publicly available grammar (BNF, JavaCC file, etc)?

There are parsers available for ES6, such as Esprima, but, since I have to use JavaCC environment, I need the grammar to work on.

Blastema answered 2/7, 2017 at 12:41 Comment(4)
I'm no language expert, but I don't think ES6 can be expressed purely in terms of a BNF grammar.Under
It may be an EBNFBlastema
You may have better luck asking on esdiscuss.Under
Thanks for the advice, @torazaburo!Blastema
O
10

The fully-approved latest version of ECMAScript (ES2017 = ES8) is at https://www.ecma-international.org/publications/standards/Ecma-262.htm

The latest draft of the next version (ES2018) is at https://github.com/tc39/ecma262 (source repo) and https://tc39.github.io/ecma262/ (rendered).

All of these are openly available and contain a grammar for the language. The grammar notation is mostly BNF with some extensions.

Oppugn answered 3/7, 2017 at 13:10 Comment(3)
Nice reference! That section (ecma-international.org/ecma-262/8.0/…), summarising the grammar, is basically an EBNF, which might suit well to my needs! I will work on it. Thanks for the answer!Blastema
This comment should be the accepted answer!Aegrotat
Is there a grammar file available that isn't HTML? Something that can be passed to tooling?Cuman
B
8

ANTLR

Take a look at the JavaScript grammar from the ANTLR grammars repository.

Bridgettbridgette answered 13/2, 2019 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.