解析需要大量前瞻的案例
大多数解析可以通过仅查看下一个符号(用于词法分析的字符,用于正确解析的标记)来完成,并且大多数剩余情况可以通过仅查看此后的一个符号来处理。
对于实际使用的编程语言或数据格式,是否有任何实际情况需要多个或无限多个前向符号(或等效的回溯)?
Most parsing can be done by looking only at the next symbol (character for lexical analysis, token for parsing proper), and most of the remaining cases can be handled by looking at only one symbol after that.
Are there any practical cases - for programming languages or data formats in actual use - that need several or indefinitely many symbols of lookahead (or equivalently backtracking)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我记得,Fortran 是一种需要大的前瞻缓冲区的语言。解析 Fortran 需要(理论上)无界的先行,尽管大多数实现都限制语句行的长度,这对先行缓冲区的大小施加了限制。
另请参阅 为什么无法解析 C++ 的所选答案使用 LR(1) 解析器?。特别是引用:
As I recall, Fortran is one language in which you need a big lookahead buffer. Parsing Fortran requires (in theory) unbounded lookahead, although most implementations limit the length of a statement line, which puts a limit on the size of the lookahead buffer.
Also, see the selected answer for Why can't C++ be parsed with a LR(1) parser?. In particular, the quote:
Knuth 证明了任何 LR(k) 文法都可以机械地转换为 LR(1) 文法。另外,据我所知,任何 LR(k) 语法都可以在与解析字符串的长度成正比的时间内进行解析。由于它包含 LR(1),所以我不知道实现 k > 的 LR(k) 解析有什么用处。 1.
我从未研究过 LR(k)->LR(1) 变换,因此在某些情况下它可能不太实用。
Knuth proved that any LR(k) grammar can be mechanically transformed to a LR(1) one. Also, AFAIK, any LR(k) grammar can be parsed in time proportional to the length of the parsed string. As it includes LR(1), I don't see what use there would be for implementing LR(k) parsing with k > 1.
I never studied the LR(k)->LR(1) transformation, so it may be possible that it is not that practical for some cases, though.