【发布时间】:2017-10-12 16:13:08
【问题描述】:
我正在尝试将 James Kyle 的 The Super Tiny Compiler 从 JavaScript 翻译成 Python。
但我无法理解 JavaScript 的进入和退出方法的作用:
1)
// 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)
// 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);
}
如何将这两种方法翻译成 Python? 谢谢。
【问题讨论】:
-
要了解它们的作用,我建议阅读有关 The Super Tiny Compiler 的更多信息,并查看如何定义
enter和exit。至于翻译成 Python,它们只是需要两个节点的方法。只要你能用 Python 编写方法,翻译它们就很简单了。 -
我不认为进入和退出是在 Super Tiny 编译器中定义的。我相信它们来自 D3 JavaScript 库。
-
@MarcoLugo 为什么 D3 会定义可以应用于 AST 的访问者? D3 是一个数据可视化库。
标签: javascript python compiler-construction translate