How can I access the v8 parsing tree, how can this be done?

I like to use the v8 engine and convert its code to another programming language based on this , for example, if I understand its first step correctly, I need to get a parsing tree

my question is: can I get it already with v8 or do I need to generate it from js code. what is an easier way?

+7
parsing v8 abstract-syntax-tree
source share
1 answer

It's hard to get an AST (Annotated Syntax Tree, Parse Tree) from V8 itself, but there are many other JavaScript parsers that will do what you are looking for. I would recommend taking a look at Esprima ( http://esprima.org/ ), which is a JavaScript parser written in JavaScript. This allows you to give JavaScript source code and return an object version of AST that you can convert to another language if you want (or change, then convert back to JavaScript or use for any other reason).

They have great online demos that should give you an idea of ​​what it can do: http://esprima.org/demo/index.html

+2
source share

All Articles