8

I like to take the v8 engine and to transform its code to other programming language based on this for example if i understand it right first step i need to get the parse tree

my question is : can i get it already from v8 or do i need to generate it from the js code . what is the easer way ?

user63898
  • 29,839
  • 85
  • 272
  • 514
  • See my SO answer on what it takes to do this: http://stackoverflow.com/a/3460977/120163 – Ira Baxter Dec 18 '11 at 09:13
  • 1
    thanks for the reply , but i need it to specific platform and specific language not "convert to all" kind of thing – user63898 Dec 18 '11 at 09:32
  • 1
    I don't think you read my answer carefully. Convert to *one* is hard, even if you have an AST. – Ira Baxter Dec 18 '11 at 10:02
  • 2
    An alternative: use Esprima (esprima.org) to parse the code and get the syntax tree. Since Esprima is pure JavaScript, you can run it via v8, Rhino, or any other JavaScript engine. – Ariya Hidayat Dec 26 '12 at 23:46

1 Answers1

4

It looks hard to get the AST (Annotated Syntax Tree, the Parse tree) from V8 itself but there are plenty of other parsers for JavaScript that will do what you're looking for. I'd recommend having a look at Esprima (http://esprima.org/) which is a JavaScript parser written in JavaScript. This allows you to give some JavaScript source code and get back a JavaScript object version of the AST which you can transform into another language if you want (or modify then transform back into JavaScript or use for some other reason).

They've got some great online demos that should give you a feel for what it can do: http://esprima.org/demo/index.html

Thomas Parslow
  • 5,712
  • 4
  • 26
  • 33