1 / 23

Pergerakan LL(1) Parser dengan input abba

Pergerakan LL(1) Parser dengan input abba. S  aBa B  bB | . stack input output. abba$. $. S. Pergerakan LL(1) Parser dengan input abba. a. S  aBa B  bB | . S. stack input output $S a bba$ . S  aBa. $ S. S  aBa. $ aBa. $ aB a. $. a bba$. Pop( a ).

danika
Télécharger la présentation

Pergerakan LL(1) Parser dengan input abba

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pergerakan LL(1) Parser dengan input abba S  aBa B  bB |  stackinputoutput abba$ $ S

  2. Pergerakan LL(1) Parser dengan input abba a S  aBa B  bB |  S stackinputoutput $S abba$ S  aBa $S S  aBa $aBa $aBa $ abba$ Pop(a) bba$ $aB

  3. Pergerakan LL(1) Parser dengan input abba b S  aBa B  bB |  stackinputoutput $Sabba$ B B  bB S  aBa $ $aBa Pop(a) abba$ $aB $aB B  bB bba$ bba$ ba$ ba$ $a Bb b Pop(b) $aB a$

  4. Pergerakan LL(1) Parser dengan input abba a S  aBa B  bB |  stackinputoutput $Sabba$ B B   S  aBa $ $aBa Pop(a) abba$ $aB $aB B  bB bba$ bba$ ba$ ba$ Pop(b) $a Bb b $aB $aB a$ a$ B   $a $a Pop(a) a$ $ $

  5. Pergerakan LL(1) Parser dengan input abba S  aBa B  bB |  stackinputoutput $Sabba$ S  aBa $ $aBa Pop(a) abba$ $aB $aB B  bB bba$ bba$ ba$ ba$ Pop(b) $a Bb b $aB $aB a$ a$ B   $a $a Pop(a) a$ $ $ $ $ Accepted Parsing Sukses

  6. Pergerakan parsing dengan input abba Derivasi language: Input: a b b a S  aBa B  bB Parse tree: S B   a a B b B  b

  7. Contoh Top down parsing Tabel parsing: id id id id id + + $ $ E E  TE’ Input: id + id E’ E’ E’   E’  +TE’ T T T  FT’ T  FT’ T’ T’ T’   T’   F F Pergerakan LL(1) Parsing F  id F  id stackinputoutput Parse tree: E $E E  TE’ id+id$ $E’T id+id$ T  FT’ $E’T’F F  id id+id$ E’ T $E’T’id id+id$ Pop(id) $E’T’ T’   +id$ F T E’ + $E’ E’  +TE’ +id$ $E’T+ Pop(+) +id$ $E’T id$ T  FT’  T’ F id $E’T’F id$ F  id $E’T’id id$ Pop(id) $ T’   $E’T’  id E’   $E’ $ $ $ accepted

  8. Contoh mencari FIRST E  TE = First(T) = First(TE) First(E) = First(FT) = First(F) T  FT First(T) F(E)  id = { ( , id } First(F) = First(‘(E)’) | First(id) = First(+TE) | First() = { + ,  } E +TE First(E) = First(FT) | First() = { ,  } TFT First(T)

  9. Contoh mencari FOLLOW (pada non terminal) Derivasi: E  TE’ E’  +TE’ |  T  FT’ T’  *FT’ |  F  (E) | id (Rule 1)  Follow(E) = { $ } E start simbol Rules: 1. If S is the start symbol  $ is in FOLLOW(S) 2. If A  B is a production rule everything in FIRST() is FOLLOW(B) except  3. If ( A  B is a production rule ) or ( A  B is a production rule and  is in FIRST() )  everything in FOLLOW(A) is in FOLLOW(B).

  10. Contoh mencari FOLLOW (pada non terminal)  Follow(E) = { $ } E start simbol  Follow(E) = { ), $ } F (E)  Follow(E) = { ) } (Rule 2) E  TE  Follow(T) = Follow(E) = { $, ) } (Rule 3) E • Follow(T)= { +, ), $ }  Follow(T) = First(E) -  E +TE (Rule 2) = { + } T  FT’  Follow(F) = Follow(T) = {+, ), $ } (Rule 3) T’   • Follow(F)={*,+, ), $}  Follow(F) = First(T) -  T’  *FT’ = {*} (Rule 2) Rules: 1. If S is the start symbol  $ is in FOLLOW(S) 2. If A  B is a production rule everything in FIRST() is FOLLOW(B) except  3. If ( A  B is a production rule ) or ( A  B is a production rule and  is in FIRST() )  everything in FOLLOW(A) is in FOLLOW(B).

  11. Contoh mencari FOLLOW (pada non terminal) E  TE’  Follow(E’) = Follow(E) = { ), $ } (rule 3) dengan  = T T  FT’  Follow(T’) = Follow(T) = { +, ), $ } (rule 3) dengan  = F Rules: 1. If S is the start symbol  $ is in FOLLOW(S) 2. If A  B is a production rule everything in FIRST() is FOLLOW(B) except  3. If ( A  B is a production rule ) or ( A  B is a production rule and  is in FIRST() )  everything in FOLLOW(A) is in FOLLOW(B).

  12. Pembuatan tabel parsing top-down First(E) = { (, id } First(E’) = { +,  } First(T) = { (, id } First(T’) = { ,  } First(F) = { (, id } Follow(E) = { $, ) } Follow(E’) = { $, ) } Follow(T) = { +, ), $ } Follow(T’) = { +, ), $ } Follow(F) = {+, *, ), $ } Algoritma pembuatan tabel parsing: • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries.

  13. Algoritma pembuatan tabel parsing: E  TE’ E’  +TE’ E’   T  FT’ T’  *FT’ T’   F  (E) F  id • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. dengan aturan 1 First(TE’) = { (, id }

  14. Algoritma pembuatan tabel parsing: E’  +TE’ E’   T  FT’ T’  *FT’ T’   F  (E) F  id • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. dengan aturan 1 First(+TE’) = { + } E  TE’ E  TE’

  15. Algoritma pembuatan tabel parsing: E’   T  FT’ T’  *FT’ T’   F  (E) F  id • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. dengan aturan 2 Follow(E’) = { $, ) } E  TE’ E  TE’ E’  +TE’

  16. Algoritma pembuatan tabel parsing: T  FT’ T’  *FT’ T’   F  (E) F  id • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. dengan aturan 1 First(FT’) = { (, id } E  TE’ E  TE’ E’  +TE’ E’   E’  

  17. Algoritma pembuatan tabel parsing: T’  *FT’ T’   F  (E) F  id • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. dengan aturan 1 First(*FT’) = { * } E  TE’ E  TE’ E’  +TE’ E’   E’   T  FT’ T  FT’

  18. Algoritma pembuatan tabel parsing: • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. T’   F  (E) F  id dengan aturan 2 & 3 Follow(T’) = { +, ), $ } E  TE’ E  TE’ E’  +TE’ E’   E’   T  FT’ T  FT’ T’  *FT’

  19. Algoritma pembuatan tabel parsing: • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. F  (E) F  id dengan aturan 1 First(“(E)”) = { ( } E  TE’ E  TE’ E’  +TE’ E’   E’   T  FT’ T  FT’ T’   T’  *FT’ T’   T’  

  20. Algoritma pembuatan tabel parsing: • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. F  id dengan aturan 1 First(id) = { id } E  TE’ E  TE’ E’  +TE’ E’   E’   T  FT’ T  FT’ T’   T’  *FT’ T’   T’   F  (E)

  21. Algoritma pembuatan tabel parsing: • for each production rule A   of a grammar G • 1. for each terminal a in FIRST()  add A   to M[A,a] • 2. If  in FIRST()  for each terminal a in FOLLOW(A) add A   to M[A,a] • 3. If  in FIRST() and $ in FOLLOW(A)  add A   to M[A,$] • All other undefined entries of the parsing table are error entries. Selain itu adalah error error error error error E  TE’ E  TE’ error error error E’  +TE’ E’   E’   error error error error T  FT’ T  FT’ error error T’   T’  *FT’ T’   T’   error error error error F  id F  (E)

  22. Self Assessment 1. Jika diketahui grammar dengan derivasi sbb: S  aBa B  bB |  Maka nilai First(B) adalah: a.) a b.) b c.) $ d.) S 2. Dari soal no.1 nilai dari First(S) adalah: a.) a b.) b c.) $ d.) S 3. Dari soal no. 1 nilai dari Follow(S) adalah: a.) a b.) b c.) $ d.) S 4. Simbol yang digunakan sebagai tanda akhir input dalam pergerakan parsing adalah: a.) a b.) b c.) $ d.) S

  23. Summary • Top down parsing melakukan parsing dari start simbol sehingga terbentuk parse tree • Untuk melakukan top down parsing dengan stack pertama-tama isi stack adalah $ dan start simbol • Untuk membuat tabel parsing harus dicari dulu nilai first dan follow dari setiap non terminal simbol.

More Related