获取函数的AST [英] Getting the AST of a function

查看:102
本文介绍了获取函数的AST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个功能:

function hi()
    print('hi')
end

我希望能够将此函数作为参数并对其进行分析,例如列出其中的所有函数调用,查看其引用的所有变量等.

I'd like to be able to take this function as an argument and perform analysis on it, such as listing all the function calls in it, seeing all the variables it references, etc.

请注意,我并不是在谈论分析源代码;我没有函数的源文本,只有函数对象,即在运行时完成.

Note that I'm not talking about analysing source code; I don't have the source text of the function, I just have the function object, i.e. this is being done at runtime.

我认为您要执行此操作的方法是获取该功能的AST.但是我不知道该怎么做.那么我将如何获取函数的AST(或者,如果有更好的方法,还要对其进行分析)?

The way I think you'd go about doing this is to get the AST of the function. But I don't know how to do that. So how would I go about getting the AST of a function (or otherwise analysing it if there's a better way)?

推荐答案

您可能想尝试一下我的

You may want to try my lbci, a bytecode inspector library.

这篇关于获取函数的AST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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