Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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):

  • http://tomcopeland.blogs.com/EcmaScript.html
  • http://www.ccs.neu.edu/home/dherman/javascript/

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.

like image 270
Alberto Trindade Tavares Avatar asked Jul 02 '17 12:07

Alberto Trindade Tavares


2 Answers

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.

like image 175
Michael Dyck Avatar answered Oct 12 '22 09:10

Michael Dyck


ANTLR

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

like image 41
Ivan Kochurkin Avatar answered Oct 12 '22 09:10

Ivan Kochurkin