9

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.

Alberto Trindade Tavares
  • 9,248
  • 5
  • 33
  • 45

2 Answers2

7

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.

Michael Dyck
  • 1,855
  • 12
  • 14
  • 3
    Nice reference! That section (https://www.ecma-international.org/ecma-262/8.0/index.html#sec-grammar-summary), summarising the grammar, is basically an EBNF, which might suit well to my needs! I will work on it. Thanks for the answer! – Alberto Trindade Tavares Jul 03 '17 at 18:29
  • This comment should be the accepted answer! – Lukas Sep 08 '21 at 10:56
7

ANTLR

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

Ivan Kochurkin
  • 4,337
  • 8
  • 44
  • 73