我试图将由James Kyle编写的Super Tiny Compiler从JavaScript翻译成Python。翻译JavaScript输入和退出Python的方法
但我无法理解什么进入和从JavaScript退出方法做:
// If there is an `exit` method for this node type we'll call it with the
// `node` and its `parent`.
if (methods && methods.exit) {
methods.exit(node, parent);
}
我怎样才能将这两种方法翻译)
// If there is an `enter` method for this node type we'll call it with the
// `node` and its `parent`.
if (methods && methods.enter) {
methods.enter(node, parent);
}
2)进入Python? 谢谢。
Here's a link to the Tiny Compiler code
为了理解他们做了什么,我建议阅读关于超级小编译器的更多内容,并看看如何定义“进入”和“退出”。至于翻译成Python,它们只是需要两个节点的方法。只要你可以用Python编写方法,翻译它们就很简单。 –
我不认为进入和退出是在Super Tiny Compiler中定义的。我相信他们来自D3 JavaScript库。 –
@MarcoLugo为什么D3会定义可应用于AST的访问者? D3是一个数据可视化库。 – sepp2k