Irving's Blog

– The best way to learn –

Tugas 3 – Teknik Kompilasi

without comments

1.
S → S+A | S-A| A+S | A-S |B*A
B → aB | B(a+B) | B*a |a(a+B)|b
A →  aTentukan First, Follow, dan tabel dari production diatas!Jawaban:

 

S →  A+SS’ | A – SS’ | B * AS’

S’ → +AS’ | -AS’ | ε

S →  AF | B * AS’

F →  +SS’ | -SS’

S’ → +AS’ | -AS’ | ε

B → aBB’ | a(a+B)B’ | bB’

B’→ (a+B)B’ | *aB’

B → aG | bB’

G → BB’ | (a+B)B’

B’ → (a+B)B’ | *aB’

A → a

 

First S → {a,b}

First F → {+,-}

First S’ → {+,-, ε}

First B → {a,b}

First G → {a,b,(}

First B’ → {(,*}

 

Follow S → {$,+,-}

Follow S’ → {$}

Follow B → {$,a,b,)}

Follow B’ → {$}

Follow F → {$,+,-}

Follow G → {$,a,b,)}

 

Table :

1

 

2.

S →  if E then S | if E then sS else S | V:= E

V → id |id[E]

E → E+T |E-T|T

T → T*F|T/F|F

F → V|(E) |const

Tentukan First, Follow, dan tabel dari production diatas!

Jawaban:

 

S → If E then SS’ | V:=E

S’ → ԑ | else S

V → idV’

V’→ ԑ|(E)

E → TE’

E’ → +TE’|-TE’| ԑ

T → FT’

T’→ *FT’ | /FT | ԑ

F → V|(E)| const

 

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’) = {:}

 

Table:

2

 

3.S → a=A

A → aA’ |bA’

A’ → +AA’ | ԑ

Tentukan First, Follow, dan tabel dari production diatas!

Jawaban:

 

First (S) ={a}

First (A) = {a,b}

First (A’) = {+, ԑ}

 

Follow(S) ={$}

Follow(A) ={$, +}

Follow(A’) = {$, +}

 

Table:

3

 

4.

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

Input : not(true or false) and true and true and false not (false) true

Jawaban:

 

First (be)          = {not , ( , true , false}

First (be’)         = {or , ε}

First (bt)           = {not , ( , true , false}

First (bt’)         = {and , ε}

First (bf)           = {not , ( , true , false}

 

Follow (be)       = {$ , )}

Follow (be’)      = {$ , )}

Follow (bt)       = {or , $ , )}

Follow (bt’)      = {or , $ , )}

Follow (bf)       = {or, $, ) , and}

 

 

 

 

4

 

 

Screen Shot 2014-04-01 at 1.21.29 PM

Screen Shot 2014-04-01 at 1.21.34 PM

 

 

http://binus.ac.id

Written by vinkz28

April 1st, 2014 at 7:18 am

Posted in Teknik Kompilasi

Leave a Reply