问题描述
在编译器构造中,主要模糊问题之一是Aho的编译器原理和技术手册中提到的Dangling-Else
,不能使用Dangling-Else的语法(1)解析器。
in compiler constructions one of the main ambiguity problems is Dangling-Elseas mentioned in compiler principles and techniques book by Aho that the grammar for the Dangling-Else can't be used with ll(1) parser.
我的问题是它不能处理为ll(1)
and my question is it true that it cant handled to be ll(1)
推荐答案
它是真的,它不能由它们的纯形式的LL(k)或LALR(k)解析。问题是,有两种可能的解释的悬而未决的;它的歧义问题(else属于最近的if或不属于)。
Its true, it can't be parsed by LL(k) or by LALR(k) in their pure forms. The problem is that there are two possible interpretations of the dangling else; its an ambiguity problem ("else" belongs to nearest "if", or does not belong).
通常是通过坚持只是两种解释之一,例如,else属于最近的if。
It is usually cured by insisting on just one of the two interpretations, e.g., "else belongs to nearest if".
许多解析器生成器可能会偶然得到这个结果。有LL的解决方案是接受第一个解析工作,并尝试其他附加到最接近第一。 LR的解决方案是shift on else,这是很容易的原因,只需在reduce动作之前检查shift动作。
Many parser generators can get this "right by accident"; the solution with LL is to accept the first parse that works and try "else attaches to closest" first. The solution with LR is "shift on else" which is easy cause, by simply checking for "shift" actions before "reduce" actions.
问题与解析器,将真正挑起不明确的解析,如GLR。这里可以提供语法上的提示,例如shift on else。
It only gets to be a problem with a parser that will really pick up ambiguous parses, such as GLR. Here one can provide extra-grammatical hints, e.g, "shift on else".
这篇关于模糊的语法Dangling-Else的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!