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

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

问题描述

我喜欢使用v8引擎并将其代码转换为其他编程语言 例如基于

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.这样,您可以提供一些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天全站免登陆