9

Is there a parser available in the open ? Else, i'm planning to write one using the grammar rules in http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

Thanks.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
trinity
  • 10,394
  • 15
  • 49
  • 67
  • Interesting ! Why isnt there one already ? Perhaps there is a better javascript parser out there ? any gnu tool ?? – trinity Aug 01 '12 at 08:41
  • 2
    @trinity Did you ever find the grammar files for flex/bison or similar? – yms Jun 07 '13 at 20:21
  • Did you think about parser generator, like flex and bison for javascript OR Grammar for javascript itself? – langpavel Nov 06 '17 at 16:22

3 Answers3

12

I think you can try Jison.

Jison 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. If you’re familiar with Bison or Yacc, or other clones, you’re almost ready to roll.

https://gerhobbelt.github.io/jison/docs/

Toshinou Kyouko
  • 334
  • 9
  • 21
Zhe Chen
  • 2,918
  • 4
  • 23
  • 39
0

Or you could try Jacob, a lexer and parser generator for JavaScript:

http://canna71.github.io/Jacob/

gcannata
  • 29
  • 4
-3

There's plenty of programs that parse JS out there, mainly the many linter programs. JSLINT/JSHINT, etc. Crockford has written a bit about the parser he makes use of in JSLINT http://javascript.crockford.com/tdop/tdop.html

I know it's not bison/grammar generated, but is that a strict requirement?

Svend
  • 7,916
  • 3
  • 30
  • 45
  • 1
    yes, i need it to be grammar dependent - to be specified in terms of grammar -> action, so i can define my own actions.. – trinity Aug 01 '12 at 11:03
  • For what purpose do you wish to define actions, are you writing an interpreter, some kinda of analysis tool? – Svend Aug 01 '12 at 11:16