我如何访问 v8 解析树怎么做? [英] How do i access v8 parse tree how can it be done?

查看:26
本文介绍了我如何访问 v8 解析树怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用 v8 引擎并将其代码转换为其他编程语言基于 this 例如,如果我理解正确,第一步我需要得到解析树

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

我的问题是:我可以从 v8 中获取它还是需要从 js 代码中生成它.什么是更简单的方法?

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 ?

推荐答案

从 V8 本身获得 AST(注释语法树,解析树)看起来很难,但有很多其他 JavaScript 解析器可以做你想做的事正在寻找.我建议看看 Esprima (http://esprima.org/),它是一个用JavaScript.这允许您提供一些 JavaScript 源代码并取回 AST 的 JavaScript 对象版本,如果您愿意,您可以将其转换为另一种语言(或修改然后转换回 JavaScript 或用于其他原因).

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).

他们有一些很棒的在线演示,可以让您了解它的功能:http://esprima.org/demo/index.html

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

这篇关于我如何访问 v8 解析树怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆