×
DON'T BE SATISFIED WITH B when you can get A+
--Your friends at LectureNotes
Close

Compiler Design

by Anna Superkings
Type: PracticalInstitute: ANNA UNIVERISTY Specialization: Computer Science EngineeringViews: 11Uploaded: 1 month agoAdd to Favourite

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Anna Superkings
Anna Superkings
Ex.No : 1 CONSTRUCTION OF NFA AIM: To write a program for constructing an NFA from given regular expression using C++. ALGORITHM: 1. Create a menu for getting four regular expressions input as choice. 2. To draw NFA for a, a/b ,ab ,a* create a routine for each regular om expression. .c 3. For converting from regular expression to NFA, certain transition us had been made based on choice of input at the rumtime. w w w .a nn au ni ve rs ity pl 4. Each of the NFA will be displayed is sequential order. 1
PROGRAM: #include<iostream.h> #include<conio.h> #include<process.h> struct node { char start; char alp; node *nstate; }*p,*p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8; char e='e'; void disp(); om void re1() .c { pl us p1=new(node); ity p2=new(node); rs p1->start='0'; ve p1->alp='e'; au .a p2->alp='a'; nn p2->start='1'; ni p1->nstate=p2; w disp(); w w p2->nstate=NULL; getch(); } void re2() { p1=new(node); p2=new(node); p3=new(node); p4=new(node); p5=new(node); p6=new(node); p7=new(node); p8=new(node); 2
p1->start='0'; p1->alp='e'; p1->nstate=p2; p2->start='1'; p2->alp='a'; p2->nstate=p3; p3->start='2'; p3->alp='e'; p3->nstate=p4; p4->start='5'; p4->alp=' '; p4->nstate=p5; om p5->start='0'; .c p5->alp='e'; us p5->nstate=p6; ity pl p6->start='3'; rs p6->alp='b'; ve p6->nstate=p7; au ni p7->start='4'; nn p7->alp='e'; .a p7->nstate=p8; w w p8->start='5'; w p8->alp=' '; p8->nstate=NULL; disp(); getch(); } void re3() { p1=new(node); p2=new(node); p3=new(node); p1->start='0'; p1->alp='a'; p1->nstate=p2; 3
p2->start='1'; p2->alp='b'; p2->nstate=p3; p3->start='2'; p3->alp=' '; p3->nstate=NULL; disp(); getch(); } void re4() { p1=new(node); om p2=new(node); .c p3=new(node); us p4=new(node); ity pl p5=new(node); rs p6=new(node); ve p7=new(node); au .a nn p1->start='0'; p1->alp='e'; ni p8=new(node); w w p1->nstate=p2; w p2->start='1'; p2->alp='a'; p2->nstate=p3; p3->start='2'; p3->alp='e'; p3->nstate=p4; p4->start='3'; p4->alp=' '; p4->nstate=p5; p5->start='0'; p5->alp='e'; p5->nstate=p6; p6->start='3'; 4

Lecture Notes