visual-decaf / decaf-compiler

Compiler of decaf language
1 stars 3 forks source link

实现一元减法的实现方案 #55

Closed DistinctWind closed 1 year ago

DistinctWind commented 1 year ago

一元减法运算符跟二元减法运算符的token是完全相同的,但是我们没什么办法给同样的一个token赋两个不同的优先级(一元减法的优先级要高于二元减法)。

那在bison中怎么做到这一点呢?

DistinctWind commented 1 year ago

我发现bison文档中有一小节讲了这个问题,应该能使用占位优先级来解决这个问题

DistinctWind commented 1 year ago

bison文档中的另一小节甚至讲解了if/else的移入/规约冲入问题,以后可以参考。

DistinctWind commented 1 year ago

56 中的单元测试表明,Parser能正确处理一元减法。