CMSC330-10/22

CMSC 330 — Fall 2026 · October 22, 2026 · 181 players · Max 10 pts

Questions & Results

Q1 of 10Multiple ChoiceAccuracy45s · 1 pt

When is a context-free grammar ambiguous?

A When it has more than one nonterminal
10
B When a nonterminal appears on both sides of a production
14
C When it generates infinitely many strings
D When some string has two or more distinct parse trees
124
✓ 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?

A n
1
B n - n
7
C n - n - n
133
✓ Correct
D None; the grammar is unambiguous
20
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?

A E → n - E | n
35
B E → E - n | n
128
✓ Correct
C E → E - E - n | n
1
D E → n - n | n
2
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?

A +
147
✓ Correct
B *
14
C Either one; the grammar is ambiguous
9
D Neither; the root is F
4
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?

A S → ε
2
B S → aSb
1
C aS → b
165
✓ Correct
D S → AB
6
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
13
B S ⇒ AB ⇒ Ab ⇒ aAb ⇒ aab
136
✓ Correct
C S ⇒ AB ⇒ aAB ⇒ aAb ⇒ aab
15
D S ⇒ AB ⇒ Ab ⇒ ab
10
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?

A (n - n) - n
19
B n - (n - n)
152
✓ Correct
C Either one; the grammar is ambiguous
5
D Neither; - cannot appear twice
3
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
57
B Identical leftmost and rightmost derivations
23
C No rightmost derivation
3
D Exactly one leftmost derivation
96
✓ 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
8
B It is always identical to the parse tree
C It omits details like parentheses and intermediate nonterminals, keeping only the essential structure
169
✓ 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)
178
✓ Correct
B Add(Num 1, Mult(Num 2, Num 3))
1
C Add(Mult(Num 1, Num 2), Num 3)
1
D Mult(Num 1, Add(Num 2, Num 3))
1
181 / 181 answered · 98% correct

Score Distribution

2
3
2
16
19
22
32
45
40
0
1
2
3
4
5
6
7
8
9
10

Score (points) →

Players
181
Average Score
7.9
High Score
10
Max Possible
10