1. ANTLR 4 自动将左递归规则重写成非左递归形式
    1. 只支持直接左递归
  2. ANTLR 4 提供优秀的错误报告功能和复杂的错误恢复机制
  3. ANTLR 4 使用了一种名为 $\text{Adaptive }LL(∗)$ 的新技术
  4. ANTLR 4 几乎能处理任何文法
    1. 支持二义性文法,不支持间接左递归

Left-recursion Elimination


根本问题:

究竟是在 expr 的当前调用中匹配下一个运算符,

还是让 expr 的调用者匹配下一个运算符?

For left-associative operators, the right operand gets one more precedence level than the operator itself.

Untitled

Untitled

For right-associative operators, the right operand has the same precedence as the current operator.

Untitled

Error Handling


报错 ⇒ 恢复 ⇒ 继续分析,最重要的是恢复策略

<aside> 💡 恐慌/应急 (Panic) 模式

假装成功、调整状态、继续进行

</aside>

如果下一个词法单元符合预期, 则采用