开发者

LALR(2) dangling else

Is LALR(2) able to handle the dangling else case naturally (without any special rules, as开发者_开发百科 with LALR(1))?

Thanks


No, the dangling else problem is an ambiguity, so no amount of lookahead helps.


It's ambiguous, however, it's not a problem, because a well behaved LALR parser generator will resolve the ambiguity by choosing the shift instead of the reduce choice. This is what you want -- the "else" to be matched with the previous "if" statement. So the conclusion is: there is no problem. You just have to understand the default choice which the parser generator makes for all shift-reduce ambiguities. This default can be overridden with disambiguating rules or something like the "%prec" operator in "yacc".
But that is a more advanced topic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜