Is LALR(2) able to handle the dangling else case naturally (without any special rules, as with LALR(1))?
Thanks
Is LALR(2) able to handle the dangling else case naturally (without any special rules, as with LALR(1))?
Thanks
Copyright © 2021 Jogjafile Inc.
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.