Ambiguous grammar understanding and elimination

Given grammar G, if there is a sentence s, it has two different parse tree, then known as G is ambiguous grammar
from the compilers point of view, there is a problem ambiguous grammar:
there will be a program with different meanings
so the program runs the result is not only
a sentence has more than one parse tree, and the sentence grammar is only relevant, regardless of the methods used is derived.
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Dangling else problem

In the complex if statement, then more than likely else, so that combined with what else I do not know then. The general principle is the right combination, namely else in conjunction with the closest left then. The grammar is rewritten into the S exact match (MS) and do not match exactly (UMS) categories, and specifies the right else incorporated in the UMS.
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
However, dangling else problem can not completely solve the problem

Published 32 original articles · won praise 25 · views 4118

Guess you like

Origin blog.csdn.net/weixin_44143695/article/details/103229044