SlideShare a Scribd company logo
1 of 2
Download to read offline
20DCE096 CE442: DESIGN OF LANGUAGE PROCESSOR 10
PRACTICAL - 4
Aim: Write a program to left factor the given grammar.
Code:
#include <stdio.h>
#include <string.h>
int main()
{
char gram[20], part1[20], part2[20], modifiedGram[20], newGram[20], tempGram[20];
int i, j = 0, k = 0, l = 0, pos;
printf("Enter Production : A->");
gets(gram);
for (i = 0; gram[i] != '|'; i++, j++)
part1[j] = gram[i];
part1[j] = '0';
for (j = ++i, i = 0; gram[j] != '0'; j++, i++)
part2[i] = gram[j];
part2[i] = '0';
for (i = 0; i < strlen(part1) || i < strlen(part2); i++)
{
if (part1[i] == part2[i])
{
modifiedGram[k] = part1[i];
k++;
pos = i + 1;
}
}
for (i = pos, j = 0; part1[i] != '0'; i++, j++)
{
newGram[j] = part1[i];
}
newGram[j++] = '|';
for (i = pos; part2[i] != '0'; i++, j++)
{
newGram[j] = part2[i];
}
modifiedGram[k] = 'X';
modifiedGram[++k] = '0';
newGram[j] = '0';
printf("n A->%s", modifiedGram);
printf("n X->%sn", newGram);
}
20DCE096 CE442: DESIGN OF LANGUAGE PROCESSOR 11
Output:
Conclusion: In this practical we implement how to left factor the grammar.
Grade:
Signature:
Remarks:

More Related Content

Similar to 20DCE096_dlp_prac4.pdf

Hello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdfHello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdf
FashionColZone
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
Jeff Tu Pechito
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
shehabhamad_90
 

Similar to 20DCE096_dlp_prac4.pdf (20)

Graphics programs
Graphics programsGraphics programs
Graphics programs
 
Hello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdfHello, I need some assistance in writing a java program THAT MUST US.pdf
Hello, I need some assistance in writing a java program THAT MUST US.pdf
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
 
Qno 1 (d)
Qno 1 (d)Qno 1 (d)
Qno 1 (d)
 
Qno 1 (e)
Qno 1 (e)Qno 1 (e)
Qno 1 (e)
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
Vcs16
Vcs16Vcs16
Vcs16
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
C exam
C examC exam
C exam
 
Automata fix.pdf
Automata fix.pdfAutomata fix.pdf
Automata fix.pdf
 
C programs Set 2
C programs Set 2C programs Set 2
C programs Set 2
 
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdfbfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
bfd23fd7-0d89-45c0-8b82-c991b30ed375.pdf
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
 
Arrays
ArraysArrays
Arrays
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
operators.ppt
operators.pptoperators.ppt
operators.ppt
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
 
'C' language notes (a.p)
'C' language notes (a.p)'C' language notes (a.p)
'C' language notes (a.p)
 

More from ShivangPithadiya1 (9)

20DCE096_dlp_prac2.pdf.
20DCE096_dlp_prac2.pdf.20DCE096_dlp_prac2.pdf.
20DCE096_dlp_prac2.pdf.
 
20DCE096_prac7.pdf
20DCE096_prac7.pdf20DCE096_prac7.pdf
20DCE096_prac7.pdf
 
20DCE096_dlp_prac3.pdf
20DCE096_dlp_prac3.pdf20DCE096_dlp_prac3.pdf
20DCE096_dlp_prac3.pdf
 
20DCE096_prac1.pdf
20DCE096_prac1.pdf20DCE096_prac1.pdf
20DCE096_prac1.pdf
 
20DCE096_prac6.pdf
20DCE096_prac6.pdf20DCE096_prac6.pdf
20DCE096_prac6.pdf
 
20DCE096_prac10.pdf
20DCE096_prac10.pdf20DCE096_prac10.pdf
20DCE096_prac10.pdf
 
20DCE096_dlp_prac2.pdf
20DCE096_dlp_prac2.pdf20DCE096_dlp_prac2.pdf
20DCE096_dlp_prac2.pdf
 
20DCE096_prac8.pdf
20DCE096_prac8.pdf20DCE096_prac8.pdf
20DCE096_prac8.pdf
 
20DCE096_dlp_prac5.pdf
20DCE096_dlp_prac5.pdf20DCE096_dlp_prac5.pdf
20DCE096_dlp_prac5.pdf
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 

20DCE096_dlp_prac4.pdf

  • 1. 20DCE096 CE442: DESIGN OF LANGUAGE PROCESSOR 10 PRACTICAL - 4 Aim: Write a program to left factor the given grammar. Code: #include <stdio.h> #include <string.h> int main() { char gram[20], part1[20], part2[20], modifiedGram[20], newGram[20], tempGram[20]; int i, j = 0, k = 0, l = 0, pos; printf("Enter Production : A->"); gets(gram); for (i = 0; gram[i] != '|'; i++, j++) part1[j] = gram[i]; part1[j] = '0'; for (j = ++i, i = 0; gram[j] != '0'; j++, i++) part2[i] = gram[j]; part2[i] = '0'; for (i = 0; i < strlen(part1) || i < strlen(part2); i++) { if (part1[i] == part2[i]) { modifiedGram[k] = part1[i]; k++; pos = i + 1; } } for (i = pos, j = 0; part1[i] != '0'; i++, j++) { newGram[j] = part1[i]; } newGram[j++] = '|'; for (i = pos; part2[i] != '0'; i++, j++) { newGram[j] = part2[i]; } modifiedGram[k] = 'X'; modifiedGram[++k] = '0'; newGram[j] = '0'; printf("n A->%s", modifiedGram); printf("n X->%sn", newGram); }
  • 2. 20DCE096 CE442: DESIGN OF LANGUAGE PROCESSOR 11 Output: Conclusion: In this practical we implement how to left factor the grammar. Grade: Signature: Remarks: