小编Gar*_*cia的帖子

从中缀转换为后缀,然后在数学求值器上构建 AST 是否符合惯例?

我正在做一个数学表达式解析器,它将文本解析为抽象语法树(我对此不太了解)。

我在 Wikipedia 上读到,可以使用Shunting-yard 算法将标记的线性序列解析为逆波兰表示法 本身的 AST,但我找不到任何直接中缀到 AST解析的示例与调车场。

现在我正在使用 Shunting-yard 将中缀表示法转换为后缀表示法,然后使用此类输出来构建 AST。

将表达式转换为后缀表示法,然后从中构建 AST 是一个很好的做法,还是我有点笨拙?

math evaluation parsing

6
推荐指数
1
解决办法
1820
查看次数

Electron - ipcRenderer.send() 上的原型数据丢失

我正在开发一个 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)

javascript oop prototype class electron

1
推荐指数
1
解决办法
812
查看次数

标签 统计

class ×1

electron ×1

evaluation ×1

javascript ×1

math ×1

oop ×1

parsing ×1

prototype ×1