Javascript parser in javascript

I need to add light syntactic sugar to the JavaScript source code and process it using a JavaScript-based build system. Are there any open source JavaScript scripts written in JavaScript? And are they fast enough when run on top of V8 or a similar high-performance JavaScript implementation?

Thanks for any pointers you can provide!

+66
javascript parsing
Mar 31 '10 at 16:08
source share
9 answers

Crescent Fresh answered this question in the comments:

JSLint contains a JavaScript parser written in JavaScript. See JSlint from Douglas Crockford. On line 2712, the parser begins. JSLint is written in the same way as processing html, so you have to mask these parts

+24
Apr 13 '10 at 13:59 on
source share

UglifyJS (JS Compressor / Decoder in JavaScript) contains a complete JavaScript parser that provides a simple API. It was heavily tested and used in some large projects (WebKit).

+32
Sep 26 2018-11-11T00:
source share

The fastest Javascript Parser in Javascript was esprima .

He also gives you

Intelligent Abstract Syntax Tree (AST) format compatible with Mozilla Parser API

+22
Aug 05 2018-12-12T00:
source share

acorn is a very fast JavaScript parser written in JavaScript. It is even faster than esprima . The results that I got in the esprima Chrome speed comparison page :

Source Esprima UglifyJS2 Traceur Acorn Underscore 1.4.1 15.1 23.8 14.2 7.6 Backbone 1.0.0 17.1 30.2 16.7 7.9 jQuery 1.9.1 241.1 247.2 125.4 81.4 Total 273.3 ms 301.2 ms 156.3 ms 96.9 ms 

It is compatible with the Mozilla Parser API, so you can use escodegen to generate JavaScript from parsing trees.

+9
Sep 18 '13 at 15:04 on
source share

This is not the JavaScript parser itself, but there is a project called Jison (e.g. Bison) for generating parsers written in JS.

+8
Mar 31 '10 at 16:43
source share

The only metacircular interpreter I've seen in JavaScript is the Narcissus Engine.

It was also developed by Brendan Eich, they used many non-standard extensions that are typical for SpiderMonkey, I think that it will not work on V8.

+7
Mar 31 '10 at 16:51
source share

Microsoft has developed the TypeScript compiler in TypeScript. Because TypeScript is a strict superset of JavaScript, and TypeScript is compiled into JavaScript, the resulting compiler is technically a JavaScript compiler written in JavaScript.

This, of course, depends on your definition of "compiler". But if the compiler accepting a superset of A is not A, which excludes GCC, Clang, and just about any other compiler.

+5
Oct 14
source share

https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API :

Recent builds of the standalone SpiderMonkey shell include a reflection of the SpiderMonkey parser, available as a JavaScript API.

Please note that this is only an API in JavaScript, the parser is C ++.

+3
Oct 13 '12 at 12:32
source share

JS / CC - LALR (1) parser and lexical analyzer generator for JavaScript, written in JavaScript - http://jscc.phorward-software.com/

0
Jun 23 2018-12-12T00:
source share



All Articles