to solve the dangling else problem, I used the following solution:
stmt : stmt_matched | stmt_unmatched ; stmt_unmatch
Not all for statements are matched. Consider, for example
for
if (c) for (;;) if (d) ; else ;
So it is necessary to divide for statements into for_matched and for_unmatched. (And similarly with other compound statements such as while.)
for_matched
for_unmatched
while