Questions & Results
Q1 of 13Multiple ChoiceAccuracy45s · 1 pt
In the compiler front end (Source → Scanner → ? → Parser → AST), what does the scanner produce?
A An abstract syntax tree C A stream of tokens✓ Correct 160 / 194 answered · 94% correct
Q2 of 13Multiple ChoiceAccuracy60s · 1 pt
Using the lecture's tokenize function (with re_num = "[0-9]+"), what does this return?
tokenize "12+3*4"
A [Tok_Num "1"; Tok_Num "2"; Tok_Add; Tok_Num "3"; Tok_Mult; Tok_Num "4"; Tok_END] B [Tok_Num "12"; Tok_Add; Tok_Num "3"; Tok_Mult; Tok_Num "4"; Tok_END]✓ Correct C [Tok_Num "12"; Tok_Add; Tok_Num "3"; Tok_Mult; Tok_Num "4"] D Add (Num 12, Mult (Num 3, Num 4)) 175 / 194 answered · 85% correct
Q3 of 13Multiple ChoiceAccuracy60s · 1 pt
The lecture's token type is:
type token = Tok_Num of string | Tok_Add | Tok_Mult | Tok_END
What happens when we evaluate tokenize "2 - 3"?
A It returns [Tok_Num "2"; Tok_Num "3"; Tok_END], skipping the - B It returns [Tok_Num "2"; Tok_Num "-3"; Tok_END] D It raises IllegalExpression, because no regex matches -✓ Correct 186 / 194 answered · 61% correct
Q4 of 13Multiple ChoiceAccuracy60s · 1 pt
let tokens = [Tok_Num "2"; Tok_Add; Tok_Num "3"; Tok_END]
let x = lookahead tokens
What is the value of x?
D [Tok_Add; Tok_Num "3"; Tok_END] 192 / 194 answered · 92% correct
Q5 of 13Multiple ChoiceAccuracy60s · 1 pt
let tokens = [Tok_Num "2"; Tok_Add; Tok_Num "3"; Tok_END]
let x = match_token tokens Tok_Add
What is the value of x?
B It raises an exception✓ Correct D [Tok_Add; Tok_Num "3"; Tok_END] 194 / 194 answered · 80% correct
Q6 of 13Multiple ChoiceAccuracy60s · 1 pt
let tokens = [Tok_Num "2"; Tok_Add; Tok_Num "3"; Tok_END]
let x = match_token tokens (Tok_Num "2")
What is the value of x?
D [Tok_Add; Tok_Num "3"; Tok_END]✓ Correct 194 / 194 answered · 89% correct
Q7 of 13Multiple ChoiceAccuracy75s · 1 pt
The lecture's recursive descent parser implements:
S → A + S | A
A → B * A | B
B → 0 | 1 | … | 9
What does parse "2*3+4" return?
A Mult (Num 2, Add (Num 3, Num 4)) B Add (Num 2, Mult (Num 3, Num 4)) C Mult (Add (Num 2, Num 3), Num 4) D Add (Mult (Num 2, Num 3), Num 4)✓ Correct 194 / 194 answered · 81% correct
Q8 of 13Multiple ChoiceAccuracy75s · 1 pt
The lecture's recursive descent parser implements:
S → A + S | A
A → B * A | B
B → 0 | 1 | … | 9
What does parse "1 + 2 + 3" return?
A Add (Num 1, Add (Num 2, Num 3))✓ Correct B Add (Add (Num 1, Num 2), Num 3) 193 / 194 answered · 85% correct
Q9 of 13Multiple ChoiceAccuracy60s · 1 pt
Using the lecture's parser for
S → A + S | A
A → B * A | B
B → 0 | 1 | … | 9
what happens when we evaluate parse "2+"?
B It returns Add (Num 2, Num 0) C It raises ParseError: parse_B sees Tok_END where a number is expected✓ Correct D It raises IllegalExpression from tokenize 194 / 194 answered · 98% correct
Q10 of 13Multiple ChoiceAccuracy75s · 1 pt
let rec parse_S tokens =
let e1, t1 = parse_A tokens in
match lookahead t1 with
| Tok_Add ->
let t2 = match_token t1 Tok_Add in
let e2, t3 = parse_S t2 in
(Add (e1, e2), t3)
| _ -> (e1, t1)
What does parse_S (tokenize "2 3") return?
B (Num 2, [Tok_Num "3"; Tok_END])✓ Correct 191 / 194 answered · 62% correct
Q11 of 13Multiple ChoiceAccuracy45s · 1 pt
For which grammar does a straightforward recursive descent parser loop forever?
192 / 194 answered · 90% correct
Q12 of 13Multiple ChoiceAccuracy60s · 1 pt
Which grammar is the result of eliminating left recursion from
S → Sa | Sb | c
B S → Lc, L → aL | bL | ε D S → cL, L → aL | bL | ε✓ Correct 2 / 194 answered · 0% correct
Q13 of 13Multiple ChoiceAccuracy60s · 1 pt
Why can't a predictive parser with one token of lookahead (LL(1)) parse this grammar as written?
S → ab | ac
A Both productions start with a, so the lookahead cannot choose between them✓ Correct B The grammar is left recursive C The grammar is ambiguous D The grammar has no ε production 190 / 194 answered · 93% correct
Score Distribution
0–1
2–3
4–5
6–7
8–9
10–11
12–13
Score (points) →