answersLogoWhite

0

Conversion of a Regular Expression to NFA Algorithm Source code C programmingCS342 Compiler Lab Source code Algorithm C Programming

#include

#include

void main()

{

char reg[20];

int q[20][3],i,j,len,a,b;

clrscr();

for(a=0;a<20;a++)

{

for(b=0;b<3;b++)

{

q[a][b]=0;

}

}

printf("Regular expression: \n");

scanf("%s",reg);

len=strlen(reg);

i=0;

j=1;

while(i

{

if(reg[i]=='a'&®[i+1]!='/'&®[i+1]!='*')

{

q[j][0]=j+1;

j++;

}

if(reg[i]=='b'&®[i+1]!='/'&®[i+1]!='*')

{

q[j][1]=j+1;

j++;

}

if(reg[i]=='e'&®[i+1]!='/'&®[i+1]!='*')

{

q[j][2]=j+1;

j++;

}

if(reg[i]=='a'&®[i+1]=='/'&®[i+2]=='b')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][0]=j+1;

j++;

q[j][2]=j+3;

j++;

q[j][1]=j+1;

j++;

q[j][2]=j+1;

j++;

i=i+2;

}

if(reg[i]=='b'&®[i+1]=='/'&®[i+2]=='a')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][1]=j+1;

j++;

q[j][2]=j+3;

j++;

q[j][0]=j+1;

j++;

q[j][2]=j+1;

j++;

i=i+2;

}

if(reg[i]=='a'&®[i+1]=='*')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][0]=j+1;

j++;

q[j][2]=((j+1)*10)+(j-1);

j++;

}

if(reg[i]=='b'&®[i+1]=='*')

{

q[j][2]=((j+1)*10)+(j+3);

j++;

q[j][1]=j+1;

j++;

q[j][2]=((j+1)*10)+(j-1);

j++;

}

if(reg[i]==')'&®[i+1]=='*')

{

q[0][2]=((j+1)*10)+1;

q[j][2]=((j+1)*10)+1;

j++;

}

i++;

}

printf("Transition function \n");

for(i=0;i<=j;i++)

{

if(q[i][0]!=0)

printf("\n q[%d,a]-->%d",i,q[i][0]);

if(q[i][1]!=0)

printf("\n q[%d,b]-->%d",i,q[i][1]);

if(q[i][2]!=0)

{

if(q[i][2]<10)

printf("\n q[%d,e]-->%d",i,q[i][2]);

else

printf("\n q[%d,e]-->%d & %d",i,q[i][2]/10,q[i][2]%10);

}

}

getch();

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is the coding of program which can simplify mathematical expression in c?

34.768


What do you mean by statements in C program?

A statement in C is an expression terminated with a semi-colon. That is, a semi-colon turns an expression into a statement.


How do you generate a parse tree from an expression using C program?

c code for top down parser


What is regular grammar of a for loops C programming language?

Something like this:statement -> for (opt_expression; opt_expression; opt_expression) statementstatement -> while (expression) statementstatement -> do statement while (expression);opt_expression -> | expression


Who heads the National Food Authority in the Philippines?

Mr. Jessup P. Navarro is the current Administrator of the Philippine National Food Authority (NFA). However, since the NFA is under the Department of Agriculture (DA), the Secretary of DA, Sec. Arthur C. Yap, chairs the NFA Council.


How do you write as an expression the sum of a and c?

It is simply: a+c


Define an expression that evaluates to true when i equals j?

In Java, or C, the expression is simply:i == jIf the two are equal, this expression will evaluate to true; if not, it will evaluate to false.In Java, or C, the expression is simply:i == jIf the two are equal, this expression will evaluate to true; if not, it will evaluate to false.In Java, or C, the expression is simply:i == jIf the two are equal, this expression will evaluate to true; if not, it will evaluate to false.In Java, or C, the expression is simply:i == jIf the two are equal, this expression will evaluate to true; if not, it will evaluate to false.


Features of c program?

the features of a C program


C program was introduced in the year?

c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.


What are components of expression in c?

no


What is executive a c program?

I think it is 'execution of a C program'.


Why the semicoloumn is used in c program?

Why semicolon? Tradition.What does it do? Terminates a single statement, eg:i+= 3; /* expression is a single statement */{ i= 3; --j; } /* no semicolon after the compound statement */