CFG With unambiguous if-else statement
If you insist that the alternatives in a conditional statement be blocks, then the dangling-else ambiguity vanishes.

The dangling else ambiguity is something like this, where the else could be attached to either if:

if (a &gt; 3) if (b &gt; 4) do_something else do_something_else


However, if the statements in the conditional must be surrounded by braces, that is a syntax error. You would have to write either:

if (a &gt; 3) { if (b &gt; 4) { do_something } else { do_something_else } }


or

if (a &gt; 3) { if (b &gt; 4) { do_something } } else { do_something_else }


and both of those are quite explicit about which if the else belongs to.

In effect, a braced statement list (or block, as you refer to it in the context of a while statement) is a matched_statement, and you could just add it to the set of possibilities for that non-terminal. But that's only necessary if you want the braces to be optional; if you're going to require them, then you can scrap all that matched- and unmatched- statement stuff, and just use block in your if statement, just as with your while statement.

In any case, the problem is

Rule 20    matched_statement -&gt; command
Rule 21    unmatched_statement -&gt; IF LPAREN logical_expression RPAREN LBRACE command RBRACE
Rule 22    unmatched_statement -&gt; IF LPAREN logical_expression RPAREN LBRACE matched_statement RBRACE ELSE LBRACE unmatched_statement RBRACE


Since matched_statement -&gt; command (rule 20), the RBRACE in rule 21 induces a shift-reduce conflict. Assuming a command has just been reduced, the parser has to decide whether rule 20 should be applied (a reduce), which is necessary if the input is the start of rule 22, or whether the RBRACE should just be shifted, necessary if the input is the start of rule 21. And it can't know that by just looking at the RBRACE, since that is the same in both rules.

However, as I said, it doesn't matter. You don't need two different non-terminals for a block, and just using block will avoid the problem.