Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript parser in JavaScript [closed]

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

Thank you for any pointers you can provide!

like image 262
emk Avatar asked Mar 31 '10 16:03

emk


People also ask

How does JavaScript parser work?

Parsing means analyzing and converting a program into an internal format that a runtime environment can actually run, for example the JavaScript engine inside browsers. The browser parses HTML into a DOM tree. HTML parsing involves tokenization and tree construction.

What Is syntax parser in JavaScript?

Syntax parser is part of Javascript engine. It reads your code character by character, tells what your code does, and check if the grammar is correct or not. You can think syntax parser as an interpreter between your code and computer. It translates your code to machine readable code.

What is used for parsing and running JavaScript in node JS?

Parse Arguments using process.argv is the simplest way of parsing arguments in Node. js and you do not need to install any additional package or library for that.

What is jison?

Jison is an utility which takes a context-free grammar as input and outputs a JavaScript file capable of parsing the language described by that grammar. You can then use the generated script to parse inputs and accept, reject, or perform actions based on the input. (The syntax is similar to Yacc/Bison).


2 Answers

UglifyJS (JS compressor/beautifier in JavaScript) contains a complete JavaScript parser that exposes a simple API. It's heavily tested and used in some big projects (WebKit).

like image 91
mishoo Avatar answered Sep 23 '22 01:09

mishoo


The fastest Javascript parser in Javascript was esprima.

It also gives you

Sensible format for the abstract syntax tree (AST), compatible with Mozilla Parser API

like image 25
Johannes Gerer Avatar answered Sep 20 '22 01:09

Johannes Gerer