Use the following context-free grammar, with start symbol :
The symbol generates the balanced members of the suffix-nonnegative binary language, while permits extra zeros. To prove the claim and prepare the ambiguity argument, reverse every generated string. The reversed productions are
Here represents the reversals of the strings, and represents the reversals of the strings. A string belongs to the desired formal language precisely when its reversal has no string prefix with more ones than zeros. Associate a path with each reversed string, counting a zero as a step and a one as a step .
The nonterminal generates exactly the paths that stay nonnegative and finish at zero. The production consists of an initial up-step, a balanced path one level higher, a down-step to zero, and another balanced path. Conversely, any nonempty balanced nonnegative path has a first return to zero, and splitting there gives exactly this form. Mathematical induction on length proves the characterization.
The productions for generate nonnegative paths: stays strictly above zero after its first step, while first executes a balanced excursion and then another nonnegative path. Conversely, a nonempty nonnegative path starts with zero. If it never returns to height zero, removing that initial zero leaves a nonnegative path, giving . If it does return, split at its first return to obtain . These shorter components can be generated by mathematical induction. This proves that the original context-free grammar generates exactly the required formal language.
For instance, in the original context-free grammar,
while . The string is excluded since its entire length is a string suffix having two ones and only one zero.
A context-free grammar is an ambiguous grammar if some terminal string has two distinct parse trees, equivalently two distinct leftmost derivations. Different orders of expanding independent nonterminals do not by themselves constitute ambiguity.
The context-free grammar just given is unambiguous. It suffices to prove this for the reversed productions, because reversing a parse tree preserves whether two parse trees are distinct.
For , the empty string forces the empty production. A nonempty string must use . In any resulting nonnegative balanced path, the displayed one is the unique first return to zero. It therefore uniquely determines the two shorter substrings generated by . Mathematical induction on length makes both smaller parse trees unique.
For , the empty string again forces the empty production. A nonempty path with no return to zero must use , since always returns to zero. A path with a return must use , since stays positive after its first step. In the latter case, the first return uniquely determines the substring and the remaining substring. Applying mathematical induction to these shorter substrings proves uniqueness throughout. Hence

Articles by others on the same topic (0)

There are currently no matching articles.