Questions & Results
Q1 of 10Multiple ChoiceAccuracy45s · 1 pt
When is a context-free grammar ambiguous?
A When it has more than one nonterminal B When a nonterminal appears on both sides of a production C When it generates infinitely many strings D When some string has two or more distinct parse trees✓ Correct 148 / 181 answered · 84% correct
Q2 of 10Multiple ChoiceAccuracy60s · 1 pt
Consider the grammar:
E → E - E | n
Which string shows that this grammar is ambiguous?
D None; the grammar is unambiguous 161 / 181 answered · 83% correct
Q3 of 10Multiple ChoiceAccuracy60s · 1 pt
Which grammar generates the same strings as E → E - E | n, but is unambiguous and makes - left-associative?
166 / 181 answered · 77% correct
Q4 of 10Multiple ChoiceAccuracy75s · 1 pt
Consider the grammar:
E → E + T | T
T → T * F | F
F → n
In the parse tree for n + n * n, which operator is applied at the root?
C Either one; the grammar is ambiguous 174 / 181 answered · 84% correct
Q5 of 10Multiple ChoiceAccuracy45s · 1 pt
Which of the following is NOT a valid production in a context-free grammar?
174 / 181 answered · 95% correct
Q6 of 10Multiple ChoiceAccuracy60s · 1 pt
Consider the grammar:
S → AB
A → aA | a
B → b
Which is a rightmost derivation of aab?
A S ⇒ AB ⇒ aAB ⇒ aaB ⇒ aab B S ⇒ AB ⇒ Ab ⇒ aAb ⇒ aab✓ Correct C S ⇒ AB ⇒ aAB ⇒ aAb ⇒ aab 174 / 181 answered · 78% correct
Q7 of 10Multiple ChoiceAccuracy60s · 1 pt
Consider the grammar:
E → T - E | T
T → n
How does the parse tree for n - n - n group the expression?
C Either one; the grammar is ambiguous D Neither; - cannot appear twice 179 / 181 answered · 85% correct
Q8 of 10Multiple ChoiceAccuracy45s · 1 pt
If a context-free grammar is unambiguous, then every string it generates has:
A Exactly one derivation of any kind B Identical leftmost and rightmost derivations C No rightmost derivation D Exactly one leftmost derivation✓ Correct 179 / 181 answered · 54% correct
Q9 of 10Multiple ChoiceAccuracy45s · 1 pt
How does an abstract syntax tree (AST) typically differ from a parse tree?
A It includes every nonterminal used in the derivation B It is always identical to the parse tree C It omits details like parentheses and intermediate nonterminals, keeping only the essential structure✓ Correct D It is a flat list of the terminals in the input 177 / 181 answered · 95% correct
Q10 of 10Multiple ChoiceAccuracy60s · 1 pt
Which AST represents the expression (1 + 2) * 3?
A Mult(Add(Num 1, Num 2), Num 3)✓ Correct B Add(Num 1, Mult(Num 2, Num 3)) C Add(Mult(Num 1, Num 2), Num 3) D Mult(Num 1, Add(Num 2, Num 3)) 181 / 181 answered · 98% correct
Score Distribution
Score (points) →