Consider the grammar with rules:
S → aSb | ab
Is this grammar ambiguous?
Try to draw parse trees for strings like 'ab' and 'aabb'.
This grammar generates strings with equal numbers of 'a's followed by equal numbers of 'b's. The string 'aabb' can be derived in more than one way, so the grammar is ambiguous.
Which of the following best defines an ambiguous grammar?
Think about what ambiguity means in terms of parse trees.
An ambiguous grammar is one where at least one string can be generated in more than one way, resulting in multiple parse trees.
Given the grammar:
E → E + E | E * E | (E) | id
What is the main cause of ambiguity in this grammar?
Consider how expressions like 'id + id * id' can be parsed differently.
The grammar is ambiguous because it does not specify operator precedence or associativity, so expressions can be parsed in multiple ways.
Which statement correctly compares ambiguous and unambiguous grammars?
Focus on the number of parse trees per string.
Ambiguous grammars allow multiple parse trees for some strings, while unambiguous grammars have exactly one parse tree per string.
Consider the grammar:
S → aSbS | bSaS | ε
Which of the following is true about this grammar?
Try to find two different parse trees for the string 'abab'.
The grammar is ambiguous because the string 'abab' can be derived using different parse trees due to the recursive rules.