Search code examples
javascriptpythonparsingcompiler-construction

JavaScript parser in Python


There is a JavaScript parser at least in C and Java (Mozilla), in JavaScript (Mozilla again) and Ruby. Is there any currently out there for Python?

I don't need a JavaScript interpreter, per se, just a parser that's up to ECMA-262 standards.

A quick google search revealed no immediate answers, so I'm asking the SO community.


Solution

  • ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages.

    The ANTLR site provides many grammars, including one for JavaScript.

    As it happens, there is a Python API available - so you can call the lexer (recognizer) generated from the grammar directly from Python (good luck).