Top Down Parsing

April 1st, 2014 by Felix Hendrian Leave a reply »

Tentukan first, follow, dan production table nya!

1.

SOAL:

S  ->            S + A | S – A | A + S | A – S | B*A

B       ->      aB | B(a+B) | a(a+B) | B*a|b

A      ->       a

S  ->            A+SS’ | A – S S’ | B*AS’

S’     ->       +AS’ | -AS’ | Ɛ

S       ->       AS’‘| B*AS’

S’’      ->     +SS’ | -SS’

B      ->       aBB’ | a(a+B)B’ | bB’

B’      ->      (a+B)B’ | *aB’ |Ɛ

B      ->       aB’’ | bB’

B’’     ->      BB’ | (a+B)B’

A       ->      a

JAWABAN :

S       ->       AS’‘| B*AS’

S’       ->     +AS’ | -AS’ | Ɛ

S’’      ->     +SS’ | -SS’

B        ->     aB’’ | 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,(}

First  A  ={a}

Follow S= {$}

Follow S’= {$}

Follow S’’= {$}

Follow B= {*,)}

Follow B’= {*,)}

Follow B’’= {*.)}

Follow A= {+,-,$}

Capture

2.

SOAL : 

S-> if E then S |if E then S else S | V:=E

V-> id | id [E]

E-> E+T | E-T | T

T-> T*F | T/F | F

F-> V | (E) | const

JAWABAN : 

S-> if E then S S’ | V:=E

S’-> ε | else S

V -> id V’

V’-> ε |[E]

E-> TE’

E’-> +TE’ | -TE’ | ε

T-> FT’

T’-> *FT’ | /FT’ | ε

F-> V | (E) | const

First (S) = {if, id}

First (S’) = {ε,else}

First (V) = {id}

First (V’) = {ε,[}

First (E) = {id,(,const}

First (E’) = {+,-,ε}

First (T) = {id,(,const}

First (T’) = {*,/,ε}

First (F) = {id,(,const}

Follow (S) = {$,else}

Follow (S’) = {$,else}

Follow (V) = {:}

Follow (V’) = {:}

Follow (E) = {],)}

Follow (E’) = {],)}

Follow (T) = {+,-,]}

Follow (T’) = {+,-,]}

Follow (F) = {*,/,+,-,],}

Capture

3.

SOAL:

S -> a = A

A -> aA’ | bA

A’ -> +AA’ | Ɛ

JAWABAN :

First S = { a }

First A = { a, b }

First A’ = { +, Ɛ }

Follow S = { $ }

Follow A = { $, + }

Follow A’ = { $, + }

Capture

4.

SOAL:

be -> bt be’

be’ -> or bt be’

be’ -> e

bt -> bf bt’

bt’ -> and bf bt’

bt’ -> e

bf -> not bf

bf -> ( be)

bf -> true

bf -> false

Periksalah input sebagai berikut : 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}

Capture

 

 

Capture

Website Binus University

Advertisement

Leave a Reply