Program to find the leading edge for non terminals present in the grammar production.
Program Code:
#include<iostream.h>
#include<conio.h>
#include<string.h>
main()
{
int n,j,i,k,b;
char pr[10][10],lead[10],temp;
cout<<"Enter the number of production rules you want to enter\n";
cin>>n;
cout<<"Enter the production rules";
for(i=0;i<n;i++)
{
cin>>pr[i];
}int d=0;
for(i=0;i<n;i++)
{d=0;
for(j=3;j<7;j++)
{
if(islower(pr[i][j]))
{
lead[pr[i][0]]=pr[i][j];
d=1;
break;
}
}
if(d==0)
{
if(lead[pr[i][j]]!='\0')
{
lead[pr[i][0]]=lead[pr[i][3]];
break;
}
}
}for(i=0;i<n;i++)
{
cout<<"leading["<<pr[i][0]<<"]="<<lead[pr[i][0]]<<endl;
}
getch();
}
Output:
0 comments:
Post a Comment