0% found this document useful (0 votes)
74 views26 pages

PCD Lab Manual - Parsing - C (Programming Language)

hhjghgj

Uploaded by

alok kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
74 views26 pages

PCD Lab Manual - Parsing - C (Programming Language)

hhjghgj

Uploaded by

alok kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 26

6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Enjoy thousands of titles when you


subscribe

Read free for 30 days

Only $8.99/month after. Cancel anytime.

PCD Lab Manual

Uploaded by thalasiva
 64% (25) · 15K views · 24 pages
More

     
Save 64% 36% Embed Share Print

Download now  Search document 

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 1/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)
 

Search Read free for 30 days

NFA FROM RE

AIM:

To write a C program to convert the regular expression to NFA.

ALGORITHM:

1. Start the program.


2. Declare all necessary header files.
3. Define the main function.
4. Declare the variables and initialize variables r & c to ‘0’.
5. Use a for loop within another for loop to initialize the matrix for NFA states.
6. Get a regular expression from the user & store it in ‘m’.
7. Obtain the length of the expression using strlen() function and store it in ‘n’.
8. Use for loop upto the string length and follow steps 8 to 12.
9. Use switch case to check each character of the expression
10.If case is ‘*’, set the links as ‘E’ or suitable inputs as per rules.
11.If case is ‘+’, set the links as ‘E’ or suitable inputs as per rules.
12.Check the default case, i.e.,for single alphabet or 2 consecutive alphabets
and set the links to respective alphabet.
13.End the switch case.
14.Use for loop to print the states along the matrix.
15.Use a for loop within another for lop and print the value of respective links.
16.Print the states start state as ‘0’ and final state.
17.End the program.

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 2/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)
 

Search Read free for 30 days

PROGRAM:

#include<stdio.h>
#include<conio.h>

void main()
{
char m[20],t[10][10];
int n,i,j,r=0,c=0;
clrscr();
 printf("\n\t\t\t\tSIMULATION OF NFA");
 printf("\n\t\t\t\t*****************");
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
t[i][j]=' ';
}
}
 printf("\n\nEnter a regular expression:");
scanf("%s",m);
n=strlen(m);
for(i=0;i<n;i++)
{
switch(m[i])
{
case '|' : {
t[r][r+1]='E';
t[r+1][r+2]=m[i-1];
t[r+2][r+5]='E';
t[r][r+3]='E';
t[r+4][r+5]='E';
t[r+3][r+4]=m[i+1];
r=r+5;
 break;
}
case '*':{
t[r-1][r]='E';
t[r][r+1]='E';

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 3/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)
 

Search Read free for 30 days

t[r][r+3]='E';
t[r+1][r+2]=m[i-1];
t[r+2][r+1]='E';
t[r+2][r+3]='E';
r=r+3;
 break;
}
case '+': {
t[r][r+1]=m[i-1];
t[r+1][r]='E';
r=r+1;
 break;
}
default:
{

if(c==0)
You're Reading a Preview
{
Upload your documents to download.
if((isalpha(m[i]))&&(isalpha(m[i+1])))
{ OR
t[r][r+1]=m[i];
t[r+1][r+2]=m[i+1];
Become a Scribd member for full access. Your
r=r+2;
first 30 days are free.
c=1;
}
c=1; Continue for Free
}
else if(c==1)
{
if(isalpha(m[i+1]))
{
t[r][r+1]=m[i+1];
r=r+1;
c=2;
}
}
else
{
if(isalpha(m[i+1]))
{

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 4/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)
 

Search Read free for 30 days

t[r][r+1]=m[i+1];
r=r+1;
c=3;
}
}
}
break;
}
}
 printf("\n");
for(j=0;j<=r;j++)
 printf(" %d",j);
 printf("\n___________________________________\n");
 printf("\n");
for(i=0;i<=r;i++)
{
for(j=0;j<=r;j++)
You're Reading a Preview
{
Upload your documents to download.
 printf(" %c",t[i][j]);
} OR
 printf(" | %d",i);
 printf("\n"); Become a Scribd member for full access. Your
}
first 30 days are free.
 printf("\nStart state: 0\nFinal state: %d",i-1);
getch();
} Continue for Free

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 5/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)
 

Search Read free for 30 days

OUTPUT:

Enter a regular Expression: a|b

SIMULATION OF NFA
*****************

Enter a regular expression:a|b

0 1 2 3 4 5
 ___________________________________ 

E E |0
a
You're Reading a Preview
|1
E |2
Upload your documents to download.
b |3
E |4 OR
|5
Become a Scribd member for full access. Your
Start state: 0
first 30 days are free.
Final state: 5

Continue for Free

RESULT:
 
Thus the C program to convert regular expression to NFA has been
executed and the output has been verified successfully.

You're reading a preview 

Unlock full access (pages 6-8) by Search document


Download now 
uploading documents or with a 30
https://www.scribd.com/doc/98845585/PCD-Lab-Manual 6/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

day free trial


Search Read free for 30 days
Continue for Free

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 7/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 8/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

You're reading a preview 

Unlock full access (pages 12-22) by Search document


Download now
uploading documents or with a 30
 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 9/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

day free trial


Search Read free for 30 days
Continue for Free

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 10/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Reward Your Curiosity


Download now  Search document 
Everything you want to read.
https://www.scribd.com/doc/98845585/PCD-Lab-Manual 11/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Anytime. Anywhere. Any device.


Search Read free for 30 days

Read free for 30 days

Cancel Anytime

Share this document


    

You might also like

Compiler Construction MCQs-1.docx


Khurram Abbas

Compiler Design Lab Manual


Bernice Samina

Compiler-Design Lab Assignment Solution


Kapil Panwar

Parsing C (Programming Language) Regular Expression

Computer
DownloadEngineering
now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 12/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days


Lp Lab Manual
computerstudent

Compiler Objective
amank114

Compiler Lab Manual Final E-content


PRISTUniversity

Compiler Design Lab Manual


Abhi Kamate

Compiler_Design Lab Manual


Priya R Chourasia

Previous Year Compiler Design Solved Gate Question by Kanodia


BhardwajVaibhav
Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 13/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Compiler Design Lab Manual


kumar_chinnas

CD LAB MANUAL.pdf
Holly India

Pcd Lab Record


prabhuvelli

QUESTION BANK FOR COMPILER DESIGN


PRIYA RAJI

Implementation of Lex Analyser Using c


gktest05

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 14/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Algorithm Output
revamrocksSearch Read free for 30 days

Untitled
revamrocks

Compiler Design Practical File


Sagar

Compiler Design: Theory questions with answer


Md Saidur Rahman Kohinoor

III Cse Ooad Bits


computerstudent

CS6660 Compiler Design Lesson Plan


profBalamurugan

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 15/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Compiler Design : Practical File


Manish Kumar Chouriya

CS1352-Principles of Compiler Design Question Bank


chetanarora

compiler design – 2 marks question set with answers _ TUTOR4CS.pdf


shekhar kumar

Predictive Parsing and LL(1) - Compiler Design - Dr. D. P. Sharma - NITK


Surathkal by wahid311
Abdul Wahid Khan

CD Lab Manual
miraclesuresh

Download now  Search document 


Assignment Programming
https://www.scribd.com/doc/98845585/PCD-Lab-Manual 16/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

ridz shofri
Search Read free for 30 days

Third year sixth semester CS6660 compiler design two mark with answer
PRIYA RAJI

Write a Program Parse Using Brute Force Technique of Top Down Parsing
it2020

Bootstrap and Cross Compiler


ricky_chawla_1

cs6612-compiler-design-lab-manualdoc.doc
parasuraman

The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a


Good Life
Mark Manson

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 17/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days


Shoe Dog: A Memoir by the Creator of Nike
Phil Knight

Never Split the Difference: Negotiating As If Your Life Depended On It


Chris Voss

Yes Please
Amy Poehler

Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of
a New America
Gilbert King

The Hard Thing About Hard Things: Building a Business When There Are No
Easy Answers
Ben Horowitz

Principles: Life and Work


Download now
Ray Dalio  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 18/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Fear: Trump in the White House


Bob Woodward

Rise of ISIS: A Threat We Can't Ignore


Jay Sekulow

The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be


and Embrace Who You Are
Brené Brown

Bad Feminist: Essays


Roxane Gay

The Alice Network: A Novel


Kate Quinn

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 19/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Bel Canto
Search Read free for 30 days
Ann Patchett

Little Women
Louisa May Alcott

The Art of Racing in the Rain: A Novel


Garth Stein

18791829 VTU 5th Sem Syllabus Copy


Subash Prakash

Claim Master
erdem

Basic Info Abt Com


Nabeel Ahmed
Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 20/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

handbookEMNLP.pdf
Hassina Aliane

Answers
Sean Tuason

Normal Forms
ParthPahwa

PhpDocumentor 1.2.2 Manual


Freddy Plata Antequera

AI-IIUC.pdf
Liar Zishan

Download now  Search document 


Ch 4- Semantic Analysis (4).pdf
https://www.scribd.com/doc/98845585/PCD-Lab-Manual 21/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

ethiopia tonetor
Search Read free for 30 days

Compiler_Construction.pdf
Abhijit Naikwadi

Resume (3)
Bhargavi Suri

Be It Syllabus Sem-III-Viii
Shikhar Thakur

Bash - Getopts Tutorial


gonza8888

Cse309 4 Rest
onmcv

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 22/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Gabriel Hjort Blindell (Auth.)-Instruction Selection_ Principles, Methods, And


Applications-Springer International Publishing (2016)
Christian Kjær Larsen

OUTPUT1
Christy Angelia

Compiler Design Pur Vi


Purvi Majoka

Writing An Interpreter In Go.epub


vibha71992

Lecture Parsing
Jitendra Kumar

Compiler design Chapter-4


Download now
Vuggam Venkatesh
 Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 23/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Search Read free for 30 days

Compiler Unit-2 Partha Sir


nimoj

Sip Message
Quách Thiên

Compilers Notes.doc
parvez

Generating FDS Fire Simulation Input Using IFC-bas


Sergio Santucho

Tutorial NLP4MIR
Arnu Felix Campos

Download now  Search document 

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 24/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

Short Notes to Memorize gate


Search Read free for 30 days
appasami

‫ معالجة اللغات الطبيعية‬10 ‫المحاضرة‬


Lua

156486 Service Consumer


సామాన్యు డు సామాన్యు డు

W00-1106
Le Thithanhha

A Python Book
Gerald Gavina

About Support Legal Social


https://www.scribd.com/doc/98845585/PCD-Lab-Manual 25/26
6/5/2021 PCD Lab Manual | Parsing | C (Programming Language)

About Scribd Help / FAQ Terms Instagram


Search Read free for 30 days
Press Accessibility Privacy Twitter

Our blog Purchase help Copyright Facebook

Join our team! AdChoices Pinterest

Contact us Publishers

Invite friends

Gifts

Scribd for enterprise

Get our free apps

Books • Audiobooks • Magazines • Podcasts • Sheet Music • Documents • Snapshots • Directory

Language: English

Copyright © 2021 Scribd Inc.

https://www.scribd.com/doc/98845585/PCD-Lab-Manual 26/26

You might also like