Lista3 de Comp
Lista3 de Comp
QUESTION 1
S→A(S)B∣ϵ
A→S∣SB∣x∣ϵ
B→SB∣y
QUESTION 2
What are the items in the initial state of the SLR(1) parsing automaton for the grammar in the previous question (Question 1)?
[Choose all that apply]
A B C D E F
S→.A ( S ) B S→. A→.S A→.SB A→.x A→S.B
G H I J
A→. B→.SB B→.y B→.
QUESTION 3
Which of the following are true of the initial state of the SLR(1) parsing automaton from the last question (Question 2)? [Choose all that apply]
QUESTION 4
The number of symbols in the first sets for the *non-terminals* are:
A
G1: E = 2; T = 2
G2: S = 3; A = 2
G3: R = 2; R' = 4; X = 3
B
G1: E = 2; T = 2
G2: S = 3; A = 2
G3: R = 2; R' = 3; X = 3
C
G1: E = 2; T = 2
G2: S = 3; A = 1
G3: R = 2; R' = 3; X = 3
D
G1: E = 4; T = 2
G2: S = 2; A = 2
G3: R = 2; R' = 4; X = 3
E
G1: E = 4; T = 2
G2: S = 2; A = 2
G3: R = 2; R' = 3; X = 3
QUESTION 5
Which of the following series is a valid bottom-up parsing for the string [Choose all that apply]:
if a then if b then win else loss
QUESTION 6
For the grammar in the last question (Question 5), when applying shift-reduce parsing to the same string:
A B C D
No conflict Reduce-reduce conflict Both conflicts Shift-reduce conflict
QUESTION 7
E→T*E∣T
T → int + T ∣ int ∣ (E)
Using shift-reduce parsing, how many shift and how many reduce moves does it take to accept the input string:
((int + int)*int)
A B C
shift = 10; reduce = 6 shift = 9; reduce = 9 shift = 10; reduce = 7
D E
shift = 9; reduce = 8 shift = 9; reduce = 7
QUESTION 8
S → Sb ∣ a
A B C
not SLR(1) SLR(1) but not LL(1) LL(1)
QUESTION 9
S → SbS ∣ a
A B C
not SLR(1) SLR(1) but not LL(1) LL(1)
QUESTION 10
S → bS ∣ a
A B C
not SLR(1) SLR(1) but not LL(1) LL(1)
QUESTION 11
S → aTUb ∣ ϵ
T → cUc ∣ bUb ∣ aUa
U → Sb ∣ cc
QUESTION 12
Choose whether or not each variable use binds to the name on the given line.
1 Class Foo {
2 f(x: Int): Int {
3 {
4 let x: Int <- 4 in {
6 x;
7 let x: Int <- 7 in
8 x;
9 x;
10 };
11 x;
12 };
13 };
14 x: Int <- 14;
15 }
QUESTION 13
QUESTION 14
For the program in Question 13, what would the the program print assuming it is dynamically scoped?
A B C D E
13 5 11 9 15
QUESTION 15
Choose the type rules that are sound.
[Sequence]
_____________________________
{ }
[Divide]
________________________
[Compare]
________________________
[Isvoid]
___________________
e1: bool
QUESTION 16
A