Diketahui:
S -> S + A | S – A | A + S | A – S | B * A
B -> aB | B(a*B) | B * a | a(a+B) | b
A -> a
Jawab:
S -> A+SS’ | A – SS’ | B * AS’
S’ -> +AS’ | -AS’ | ε
S -> AF | B * AS’
S’ -> +AS’ | -AS’ | ε
S’’ -> +SS’ | -SS’
B -> aBB’ | a(a+B)B’ | bB’
B’-> (a+B)B’ | *aB’
B -> aG | bB’
B’ -> (a+B)B’ | *aB’
B’’-> BB’ | (a+B)B’
A -> a
First S -> {a,b}
First S’ -> {+,-, ε}
First S’’ -> {+,-}
First B -> {a,b}
First B’ -> {(,*}
First B’’ -> {a,b,(}
Follow S -> {$,+,-}
Follow S’ -> {$}
Follow B -> {$,a,b,)}
Follow B’ -> {$}
Follow S’’ -> {$,+,-}
Follow B’’ -> {$,a,b,)}
Diketahui:
S -> if E then S | if E then S else S | V:= E
S’->ε | else S
E-> TE’
E’-> +TE’ | -TE’ | ε
T->FT’
T’-> FT’|/FT’|ε
F-> V|(E)|const
V-> id V’
V’-> ε|[E]
First(S) = {if, id}
First(S’) = {ε, else}
First(E) = { id, ( , const}
First(E’) = {+, -, ε}
First(T) = {id,(, const}
First(T’) = {*, /,ε }
First(F) = {id,(, const}
First(V) = {id}
First(V’) = {a b c}
Follow(S) = {$}
Follow(S’) = {$}
Follow(E) = { then, $,),]}
Follow(E’) = { then, $,),]}
Follow(T) = {+, -}
Follow(T’) = {+, -}
Follow(F) = {*,/ }
Follow(V) = {:}
Follow(V’) = {:}
Diketahui:
S -> a=A
A-> aA’|bA’
A’-> +AA’|ε
Jawab:
First S ={a}
First A={a,b}
First A’={+, ε }
Follow S={$}
Follow A={$,+}
Follow A’={$,+}
Diketahui:
be -> bt be’
be’ -> or bt be’
be’ -> ε
bt -> bf bt’
bt’ -> and bf bt’
bt’ -> ε
bf -> not bf
bf -> (be)
bf -> true
bf -> false
Jawab:
First (be) -> not,(,true,false
First (be’) -> or, ε
First (bt) -> not,(,true,false
First (bt’) -> and, ε
First (bf) -> not,(,true,flase
Follow (be) -> {$,)}
Follow (be’) -> {$,)}
Follow (bt) -> {or,$,)}
Follow (bt’) -> {or,$,)}
Follow (bf) -> {or,$,), and}
No |
Stack |
Input |
Output |
1 |
be$ |
not(true or false) and true and true and false not (false) true$ |
be > bt be |
2 |
bt be’$ |
not(true or false) and true and true and false not (false) true$ |
bt -> or bt’ |
3 |
bf bt’ be’$ |
not(true or false) and true and true and false not (false) true$ |
bf -> not bf |
4 |
bf bt’ be’$ |
not(true or false) and true and true and false not (false) true$ |
pop not |
5 |
bf bt’ be’$ |
(true or false) and true and true and false not (false) true$ |
bf -> (be) |
6 |
bt’ be’$ |
true or false) and true and true and false not (false) true$ |
pop ( |
7 |
be) bt’ be’$ |
true or false) and true and true and false not (false) true$ |
be -> bt be’ |
8 |
bt be’ ) bt’ be’$ |
true or false) and true and true and false not (false) true$ |
bt -> bf bt’ |
9 |
bf bt be’ ) bt’ be’$ |
true or false) and true and true and false not (false) true$ |
bf -> true |
10 |
bt’ be’ ) bt’ be’$ |
or false) and true and true and false not (false) true$ |
pop true |
11 |
bt’ be’ ) bt’ be’$ |
or false) and true and true and false not (false) true$ |
bt’ -> ε |
12 |
be’ ) bt’ be’$ |
or false) and true and true and false not (false) true$ |
be -> or bt be’ |
13 |
bt be’ ) bt’ be’$ |
false) and true and true and false not (false) true$ |
pop or |
14 |
bt be’ ) bt’ be’$ |
false) and true and true and false not (false) true$ |
bt -> bf bt’ |
15 |
bf bt’ be’ ) bt’ be’$ |
false) and true and true and false not (false) true$ |
bf -> false |
16 |
false bt’ be’ ) bt’ be’$ |
) and true and true and false not (false) true $ |
pop false |
17 |
bt’ be’ ) bt’ be’$ |
) and true and true and false not (false) true $ |
be’->ε |
18 |
be’ ) bt’ be’$ |
) and true and true and false not (false) true $ |
be’->ε |
19 |
) bt’ be’$ |
and true and true and false not (false) true $ |
pop ) |
20 |
bt’ be’$ |
and true and true and false not (false) true $ |
bt’->and bf br’ |
21 |
and bf bt’ be’$ |
true and true and false not (false) true $ |
pop and |
22 |
bf bt’ be’$ |
true and true and false not (false) true $ |
bf->true |
23 |
true bt’ be’$ |
and true and false not (false) true $ |
pop true |
24 |
bt’ be’$ |
and true and false not (false) true $ |
bt’ -> and bf bt’ |
25 |
and bf bt’ be’$ |
true and false not (false) true $ |
pop and |
26 |
bf bt’ be’$ |
true and false not (false) true $ |
bf -> true |
27 |
true bf bt’ be’$ |
and false not (false) true $ |
pop true |
28 |
bt’ be’$ |
and false not (false) true $ |
bt’ -> and bf bt’ |
29 |
and bf bt’ be’$ |
false not (false) true $ |
pop and |
30 |
bf bt’ be’$ |
false not (false) true $ |
bf -> false |
31 |
false bf bt’ be’$ |
not (false) true $ |
pop false |
32 |
bt’ be’$ |
not (false) true $ |
rejected |