Sep 10, 2009
system programming-teminal and non terminal
void main()
{
/* variable declaration */
int no,i,p,m=0,n=0,j,flag;
char prod[10][20],ts[50],nts[50],c;
ts[0]=NULL,nts[0]=NULL;
clrscr();
/* entering production */
printf("\nhow many production you want to enter\n");
scanf("%d",&no);
for(i=0;i<no;i++)
{
printf("\nenter production%d\n",i+1);
scanf("%s",prod[i]);
}
for(i=0;i<no;i++)/*loop for no. of productions*/
{
for(j=0;j<strlen(prod[i]);j++)/*loop for production length*/
{
c=prod[i][j];
if(c>=97 && c<=122)/*check for terminal symbols*/
{
for(p=m;p>=0;p--)
{
if(ts[p]==c)
{
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
{
ts[m]=c;
m++;
}
}
else if(c>=65 && c<=90)/*check for non terminal symbols*/
{
for(p=n;p>=0;p--)
{
if(nts[p]==c)
{
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
{
nts[n]=c;
n++;
}
}
else
{
}
}
ts[m]=NULL;
nts[n]=NULL;
}
/*display final result*/
printf("\nterminl symbols are %s\n",ts);
printf("\nnon terminal symbols are %s",nts);
getch();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment