SlideShare a Scribd company logo
1 of 24
Tata Bahasa Bebas Konteks
(Context-Free Grammar)
Pertemuan ke-8 dan ke-9
Yenni Astuti, S.T., M.Eng.
yenni.stta@gmail.com
Tujuan Penggunaan Context-Free Grammar (CFG)
Menjelaskan bahasa alami manusia
Contoh 1: Aturan Kalimat pada Bahasa Manusia
<sentence>
 <noun phrase> <verb phrase>
<noun phrase>  <adjective> <noun phrase>
<noun phrase>  <noun>
**Tanda “” dibaca: “diturunkan menjadi”
Contoh 1 (lanjutan): Aturan Kalimat pada Bahasa Manusia
<sentence>
<noun phrase>
<noun phrase>
<verb phrase>
<verb phrase>
<verb>
<noun>
<adjective>

 <noun phrase> <verb phrase>
 <adjective> <noun phrase>
 <noun>
 <verb> <noun phrase>
 <verb>
 love
 boy, girl
 little, pretty
**Tanda “” dibaca: “diturunkan menjadi”
Nonterminal danTerminal pada Bahasa Alami Manusia
<verb>
<noun>
<adjective>

 love
 boy, girl
 little, pretty

• Simbol di dalam tanda < > adalah simbol nonterminal.

• “love”, “boy”, “pretty” adalah simbol terminal.
Contoh 2: Penurunan kalimat “Little boy love pretty girl” dari
Aturan slide 3
<sentence>

<noun phrase> <verb phrase>
<adjective> <noun phrase> <verb phrase>
little <noun> <verb phrase>
little boy <verb phrase>
little boy <verb> <noun phrase>
little boy love <noun phrase>
little boy love <adjective> <noun phrase>
little boy love pretty <noun phrase>
little boy love pretty <noun>
little boy love pretty girl
Manfaat CFG pada bidang Komputer
Mendeskripsikan aturan tata bahasa
suatu bahasa pemrograman (seperti: C, Pascal, Basic)
Definisi Formal CFG
CFG dituliskan dalam bentuk 4 komponen (4-tupel)
G = (N, , P, S)
N = himpunan nonterminal.
= himpunan terminal/ alfabet
P = aturan produksi, yakni A 
dengan A N,
(N
)*
S = simbol awal

Ingat materi Teori Bahasa mengenai ciri CFG
Penurunan String (Derivation)
• Dalam suatu grammar G, suatu string yang mengandung simbol

nonterminal (

1)

dapat menurunkan bentuk terminal (

• Dituliskan dengan

1

*

m).

m.

• Seluruh sentence (ingat materi Teori Bahasa) dapat membentuk suatu

bahasa, yang dinotasikan dengan L(G)
• L(G) = { w | w dalam

*, dan S

*w}
CFL (Context-Free Language)
• Seluruh sentence (ingat materi Teori Bahasa) dapat membentuk

suatu bahasa, yang dinotasikan dengan L(G)
• L(G) = { w | w dalam

*, dan S

*w}

Bahasa dari suatu grammar (G) adalah seluruh sentence
yang terdiri dari alfabet dalam G, dan diturunkan dari simbol awal S
Contoh 3: Penurunan
G = ({S}, {a,b}, P, S)
Dengan P adalah:
• S  aSb
• S  ab
Maka,
Turunan yang dihasilkan:
S
aSb
aabb
S
aSb
aaSbb
aaabbb
S
aSb
aaSbb
aaaSbbb

jumlah „a‟ dan „b‟ sama

aaaabbbb
Contoh 3 (lanjutan): Penurunan
Turunan yang dihasilkan:
S
aSb
aabb
S
aSb
aaSbb
aaabbb
S
aSb
aaSbb
aaaSbbb

Dituliskan dalam bentuk L(G)
L(G) = {anbn | n ≥ 1}

jumlah „a‟ dan „b‟ sama

aaaabbbb
Pohon Penurunan (Derivation Tree)
root

• Penurunan dapat juga dinyatakan dalam bentuk

tree/pohon.
• Sebagai root adalah simbol awal (S).

no
de

no
de
Pohon Penurunan (Derivation Tree)
S

• Penurunan dapat juga dinyatakan dalam bentuk

tree/pohon.
• Sebagai root adalah simbol awal (S).

• Node dapat berupa terminal atau nonterminal.

no
de

no
de
Pohon Penurunan (Derivation Tree)
S

• Penurunan dapat juga dinyatakan dalam bentuk

tree/pohon.
A
• Sebagai root adalah simbol awal (S)

• Node dapat berupa terminal atau nonterminal.
• Setiap nonterminal harus diturunkan

hingga membentuk terminal.

a
Pohon Penurunan (Derivation Tree)
S

• Penurunan dapat juga dinyatakan dalam

bentuk tree/pohon.
A
• Sebagai root adalah simbol awal (S)

• Node dapat berupa terminal atau nonterminal.
• Setiap nonterminal harus diturunkan

hingga membentuk terminal.

a

a
Contoh 4: Latihan
G = ({S, A}, {a,b}, P, S)
P adalah:
S  aAS
Sa
A  SbA
A  SS
A  ba
Salah satu turunannya adalah aabbaa, buktikan dengan pohon penurunan!
Contoh 4 (lanjutan): Latihan

Aturan
Produksi:
S  aAS
Sa
A  SbA
A  SS
A  ba

String aabbaa diperoleh melalui:

S
a

S

a

A

S

b

A
b

a
a
Contoh 4 (lanjutan): Latihan

Aturan
Produksi:
S  aAS
Sa
A  SbA
A  SS
A  ba

String aabbaa diperoleh melalui:

S
a

S

a

A

S

b

A
b

a
a
Keambiguan
Proses Penurunan ada 2 cara:
1. Dari sisi kiri (l e f t - m o s t ) : diturunkan satu-per-satu dari kiri.
2. Dari sisi kanan (r i g h t - m o s t ) : diturunkan satu-per-satu dari
kanan.
Jika suatu string diturunkan dari dua/lebih

proses penurunan yang sama

(keduanya left-most atau keduanya right-most)

Maka keambiguan akan terjadi !
Contoh 5: Keambiguan
CFG dengan aturan produksi:
•EE+E
•EE*E
• E  (E)
•Ea
String a + a * a merupakan string ambigu karena string tersebut
memiliki dua proses penurunan left-most.
Mari kita lihat buktinya!
Aturan Produksi:
EE+E
EE*E
E  (E)
Ea

Contoh 5 (lanjutan): Keambiguan
Penurunan LeftMost

E
E
a

+

E
a

 beda 

E

*

E
E

E

E

a

a

+

*
E
a

E

a
Aturan Produksi:
EE+E
EE*E
E  (E)
Ea

Contoh 5 (lanjutan): Keambiguan
Penurunan LeftMost

E
E
a

+

E
a

 beda 

E

*

E
E

E

E

a

a

+

*
E

E

a

a

*Kedua pohon tersebut berbeda, namun menghasilkan string yang sama  terbukti ambigu!
Palindrome
String yang jika dibaca dari kiri ke kanan
akan sama dengan jika dibaca dari kanan ke kiri
Contoh Palindrome:
• OTTO
• DOOM MOOD
• STAR RATS
• STEP ON NO PETS
• WASITARATISAW (dibaca: Was it a rat I saw)
Info Tugas:
• Tugas kuliah ke-8 (khusus kelas B) : Tugas-1
• Tugas kuliah ke-9 (kelas A dan kelas B) : Tugas-2

• Jika ada permasalahan seputar tugas, silakan hubungi saya di ruangan

(khususnya pada jam matakuliah Teori Bahasa & Otomata). Thanks!

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

08 cfg

  • 1. Tata Bahasa Bebas Konteks (Context-Free Grammar) Pertemuan ke-8 dan ke-9 Yenni Astuti, S.T., M.Eng. yenni.stta@gmail.com
  • 2. Tujuan Penggunaan Context-Free Grammar (CFG) Menjelaskan bahasa alami manusia Contoh 1: Aturan Kalimat pada Bahasa Manusia <sentence>  <noun phrase> <verb phrase> <noun phrase>  <adjective> <noun phrase> <noun phrase>  <noun> **Tanda “” dibaca: “diturunkan menjadi”
  • 3. Contoh 1 (lanjutan): Aturan Kalimat pada Bahasa Manusia <sentence> <noun phrase> <noun phrase> <verb phrase> <verb phrase> <verb> <noun> <adjective>  <noun phrase> <verb phrase>  <adjective> <noun phrase>  <noun>  <verb> <noun phrase>  <verb>  love  boy, girl  little, pretty **Tanda “” dibaca: “diturunkan menjadi”
  • 4. Nonterminal danTerminal pada Bahasa Alami Manusia <verb> <noun> <adjective>  love  boy, girl  little, pretty • Simbol di dalam tanda < > adalah simbol nonterminal. • “love”, “boy”, “pretty” adalah simbol terminal.
  • 5. Contoh 2: Penurunan kalimat “Little boy love pretty girl” dari Aturan slide 3 <sentence> <noun phrase> <verb phrase> <adjective> <noun phrase> <verb phrase> little <noun> <verb phrase> little boy <verb phrase> little boy <verb> <noun phrase> little boy love <noun phrase> little boy love <adjective> <noun phrase> little boy love pretty <noun phrase> little boy love pretty <noun> little boy love pretty girl
  • 6. Manfaat CFG pada bidang Komputer Mendeskripsikan aturan tata bahasa suatu bahasa pemrograman (seperti: C, Pascal, Basic)
  • 7. Definisi Formal CFG CFG dituliskan dalam bentuk 4 komponen (4-tupel) G = (N, , P, S) N = himpunan nonterminal. = himpunan terminal/ alfabet P = aturan produksi, yakni A  dengan A N, (N )* S = simbol awal Ingat materi Teori Bahasa mengenai ciri CFG
  • 8. Penurunan String (Derivation) • Dalam suatu grammar G, suatu string yang mengandung simbol nonterminal ( 1) dapat menurunkan bentuk terminal ( • Dituliskan dengan 1 * m). m. • Seluruh sentence (ingat materi Teori Bahasa) dapat membentuk suatu bahasa, yang dinotasikan dengan L(G) • L(G) = { w | w dalam *, dan S *w}
  • 9. CFL (Context-Free Language) • Seluruh sentence (ingat materi Teori Bahasa) dapat membentuk suatu bahasa, yang dinotasikan dengan L(G) • L(G) = { w | w dalam *, dan S *w} Bahasa dari suatu grammar (G) adalah seluruh sentence yang terdiri dari alfabet dalam G, dan diturunkan dari simbol awal S
  • 10. Contoh 3: Penurunan G = ({S}, {a,b}, P, S) Dengan P adalah: • S  aSb • S  ab Maka, Turunan yang dihasilkan: S aSb aabb S aSb aaSbb aaabbb S aSb aaSbb aaaSbbb jumlah „a‟ dan „b‟ sama aaaabbbb
  • 11. Contoh 3 (lanjutan): Penurunan Turunan yang dihasilkan: S aSb aabb S aSb aaSbb aaabbb S aSb aaSbb aaaSbbb Dituliskan dalam bentuk L(G) L(G) = {anbn | n ≥ 1} jumlah „a‟ dan „b‟ sama aaaabbbb
  • 12. Pohon Penurunan (Derivation Tree) root • Penurunan dapat juga dinyatakan dalam bentuk tree/pohon. • Sebagai root adalah simbol awal (S). no de no de
  • 13. Pohon Penurunan (Derivation Tree) S • Penurunan dapat juga dinyatakan dalam bentuk tree/pohon. • Sebagai root adalah simbol awal (S). • Node dapat berupa terminal atau nonterminal. no de no de
  • 14. Pohon Penurunan (Derivation Tree) S • Penurunan dapat juga dinyatakan dalam bentuk tree/pohon. A • Sebagai root adalah simbol awal (S) • Node dapat berupa terminal atau nonterminal. • Setiap nonterminal harus diturunkan hingga membentuk terminal. a
  • 15. Pohon Penurunan (Derivation Tree) S • Penurunan dapat juga dinyatakan dalam bentuk tree/pohon. A • Sebagai root adalah simbol awal (S) • Node dapat berupa terminal atau nonterminal. • Setiap nonterminal harus diturunkan hingga membentuk terminal. a a
  • 16. Contoh 4: Latihan G = ({S, A}, {a,b}, P, S) P adalah: S  aAS Sa A  SbA A  SS A  ba Salah satu turunannya adalah aabbaa, buktikan dengan pohon penurunan!
  • 17. Contoh 4 (lanjutan): Latihan Aturan Produksi: S  aAS Sa A  SbA A  SS A  ba String aabbaa diperoleh melalui: S a S a A S b A b a a
  • 18. Contoh 4 (lanjutan): Latihan Aturan Produksi: S  aAS Sa A  SbA A  SS A  ba String aabbaa diperoleh melalui: S a S a A S b A b a a
  • 19. Keambiguan Proses Penurunan ada 2 cara: 1. Dari sisi kiri (l e f t - m o s t ) : diturunkan satu-per-satu dari kiri. 2. Dari sisi kanan (r i g h t - m o s t ) : diturunkan satu-per-satu dari kanan. Jika suatu string diturunkan dari dua/lebih proses penurunan yang sama (keduanya left-most atau keduanya right-most) Maka keambiguan akan terjadi !
  • 20. Contoh 5: Keambiguan CFG dengan aturan produksi: •EE+E •EE*E • E  (E) •Ea String a + a * a merupakan string ambigu karena string tersebut memiliki dua proses penurunan left-most. Mari kita lihat buktinya!
  • 21. Aturan Produksi: EE+E EE*E E  (E) Ea Contoh 5 (lanjutan): Keambiguan Penurunan LeftMost E E a + E a  beda  E * E E E E a a + * E a E a
  • 22. Aturan Produksi: EE+E EE*E E  (E) Ea Contoh 5 (lanjutan): Keambiguan Penurunan LeftMost E E a + E a  beda  E * E E E E a a + * E E a a *Kedua pohon tersebut berbeda, namun menghasilkan string yang sama  terbukti ambigu!
  • 23. Palindrome String yang jika dibaca dari kiri ke kanan akan sama dengan jika dibaca dari kanan ke kiri Contoh Palindrome: • OTTO • DOOM MOOD • STAR RATS • STEP ON NO PETS • WASITARATISAW (dibaca: Was it a rat I saw)
  • 24. Info Tugas: • Tugas kuliah ke-8 (khusus kelas B) : Tugas-1 • Tugas kuliah ke-9 (kelas A dan kelas B) : Tugas-2 • Jika ada permasalahan seputar tugas, silakan hubungi saya di ruangan (khususnya pada jam matakuliah Teori Bahasa & Otomata). Thanks!