Skip to content

C99文法关于 if 语句的描述是有二义性的。ToyCompile LR1 分析器未对该情况做特殊处理。 #5

@FlowerBlackG

Description

@FlowerBlackG

C99文法关于 if 语句的描述是有二义性的。ToyCompile LR1 分析器未对该情况做特殊处理。

例如:

if (a)
    if (b)
        c
    else
        d

上方代码的 else,如果按照“移进”规则,会被判定为附属于第二个 if。这种理解是正确的。

但是,如果按照“归约”规则,else 会被分配给第一个 if,这是错误的。

文法分析过程,有两个项目会产生移进归约冲突。恰好产生“移进”命令的语句在后面,覆盖掉前面的指令,使得问题没有暴露。

应该采用一定手段处理这个问题,而不是依赖幸运的语句产生顺序。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions