我試圖將由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