ANTLR4 会在某个时候构建自动机吗?

does ANTLR4 build automata at some point?

据我了解,最新的 ANTLR4 不再为词法分析器和解析器构建静态 DFA 表,而是在运行时进行。这个对吗?有人可以大致解释一下 ANTLR4 是如何工作的吗?

我们最近的论文描述了 excruciating, academic detail 中的机制。第 3 节提供了高级概述:

Instead of relying on static grammar analysis, an ALL(*) parser adapts to the input sentences presented to it at parse- time. The parser analyzes the current decision point (nonterminal with multiple productions) using a GLR-like mechanism to explore all possible decision paths with respect to the current “call” stack of in-process nonterminals and the remaining input on-demand. The parser incrementally and dynamically builds a lookahead DFA per decision that records a mapping from lookahead sequence to predicted production number. If the DFA constructed to date matches the current lookahead, the parser can skip analysis and immediately expand the predicted alternative.

我们使用增强转换网络 (ATN) 来表示语法,但使用与 NFA 到 DFA 转换框架的子集构造算法非常相似的算法构建 DFA。

希望对您有所帮助。