gpt4 book ai didi

error-handling - 什么是ANTLR3错误恢复方法?

转载 作者:行者123 更新时间:2023-12-03 07:48:06 25 4
gpt4 key购买 nike

这似乎是一个理论问题。

据我所知,ANTLR3 使用其 recover(###) 方法自行处理错误。我想知道 ANTLR3 使用什么方法进行错误恢复。 (即 panic 模式/短语级别等)有人可以帮我解决这个问题吗?

如果我的第一个猜测是正确的,如果有人可以向我展示其恢复方法的声明,那就太好了。谢谢你。

最佳答案

引用:

ANTLR’s error recovery mechanism is based upon Niklaus Wirth’s early ideas in Algorithms + Data Structures = Programs 1 (as well as Rodney Topor’s A Note on Error Recovery in Recursive Descent Parsers 2) but also includes Josef Grosch’s good ideas from his CoCo parser generator (Efficient and Comfortable Error Recovery in Recur- sive Descent Parsers 3). Essentially, recognizers perform single- symbol insertion and deletion upon mismatched symbol errors (as described in a moment) if possible. If not, recognizers gobble up sym- bols until the lookahead is a member of the resynchronization set and then exit the rule. The resynchronization set is the set of input symbols that can legally follow references to the current rule and references to any invoking rules up the call chain. Similarly, if the recognizer cannot choose any of the alternatives from the start of a rule, the recognizer again uses the gobble-and-exit strategy.

[...]

-- Terence Parr. The Definitive ANTLR Reference, 10.7 Automatic Error Recovery Strategy.



引用

1 尼克劳斯·沃斯。算法 + 数据结构 = 程序。 Prentice Hall PTR,美国新泽西州上萨德尔河,1978 年。

2 罗德尼·W·托波尔。关于递归下降解析器中的错误恢复的说明。 SIGPLAN Not., 17(2):37–40, 1982。

3 约瑟夫·格罗施。递归下降解析器中高效且舒适的错误恢复。结构化编程,11(3):129–140,1990。

关于error-handling - 什么是ANTLR3错误恢复方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9708348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com