Bottom-Up Parsing
(Penguraian Bawah-Atas)
3
Penguraian Bawah-Atas
(Bottom-up Parsing) (3)
Contoh lagi :
(1) E E + E
(2) E E * E
(3) E ( E )
(4) E id
Salah satu derivasi right-most untuk id1 + id2 * id3 adalah :
EE+E
E+E*E
E + E * id3
E + id2 * id3
id1 + id2 * id3
4
Penguraian Bawah-Atas
(Bottom-up Parsing) (4)
Proses reduksinya :
5
Penguraian Bawah-Atas (Bottom-
up Parsing) (5)
Lalu nol atau lebih simbol input dipindahkan (shift) ke stack,
sampai suatu handel berada di puncak stack. Handel lalu
direduksi. Proses diulang sampai ditemukan error atau
berhasil.
stack input
$S $
Aksi-aksi dalam pengurian shift-reduksi :
1. Shift, simbol input berikutnya dipindahkan ke puncak stack.
2. Reduksi, parser tahu handel ada di puncak, lalu handel
direduksi
3. Accept, proses selesai, tak ada error.
4. Error, error ditemukan.
Contoh : id1 + id2 * id3,
6
Penguraian Bawah-Atas
(Bottom-up Parsing) (5)
7
LATIHAN
• S aB | bA
A a | aS | bAA
B b | bS | aBB
• Reduksi ‘aabbaabb’ sehingga menjadi S
• Lengkapi dengan tabel proses reduksinya
• Lengkapi dengan penguraian shift-reduksi
LATIHAN
• Diketahui :
• S aAS | a
• A a | aS | bAA
• B SbA | SS | ba,
• Reduksi ‘aabbaa’ sehingga menjadi S
• Lengkapi dengan tabel proses reduksinya
• Lengkapi dengan penguraian shift-reduksi