我正在做一个数学表达式解析器,它将文本解析为抽象语法树(我对此不太了解)。
我在 Wikipedia 上读到,可以使用Shunting-yard 算法将标记的线性序列解析为逆波兰表示法 或本身的 AST,但我找不到任何直接中缀到 AST解析的示例与调车场。
现在我正在使用 Shunting-yard 将中缀表示法转换为后缀表示法,然后使用此类输出来构建 AST。
将表达式转换为后缀表示法,然后从中构建 AST 是一个很好的做法,还是我有点笨拙?
我正在开发一个 Electron 应用程序,其中我需要发送一个包含给定类的对象的数组,ipcRenderer
并且我注意到这些对象在这样做时会丢失所有原型数据。例如:
//js running on the browser
const {ipcRenderer} = require('electron');
class Thingy {
constructor() {
this.thingy = 'thingy'
}
}
let array = [new Thingy(), 'another thing']
console.log(array[0] instanceof Thingy) // => true
console.log(array[0].constructor.name) // => 'Thingy'
console.log(array[0]) // => Thingy { this.thingy='thingy' }
ipcRendered.send('array of thingys', foo)
//app-side js
const {ipcMain} = require('electron');
ipcMain.on('array of thingys', (event, array) => {
console.log(array[0] instanceof Thingy) // => false
console.log(array[0].constructor.name) // => 'Object'
console.log(array[0]) // => Object { …
Run Code Online (Sandbox Code Playgroud)