Consider the following grammars:

Grammar 1: S → a S | b S | λ
Grammar 2: S → a | b | S S | λ
Grammar 3: S → a S b | λ
Grammar 4: S → S a | S b | a
Grammar 5: S → a R | R
R → b S | S | λ

How many of these grammars are ambiguous?

2
  • 0
  • 1
  • 3
  • 4
  • 5

Review the definition of an ambiguous grammar.

For each grammar, when looking for strings with multiple parse trees, start with the shortest strings that the grammar generates.

Common sources of grammatical ambiguity include recursive patterns such as double recursion and single, indirect recursion (i.e., from one non-terminal back to itself via one or more other non-terminals).