Vous êtes sur la page 1sur 2

Ques- Write a program to remove left factoring?

CODE :

#include<stdio.h>
void main()
{
char a[100],b[100],c[100],f[100],g[100],h[100];
int i,n=0,j;
printf("Enter the grammar\n");
gets(a);

i=2;
j=0;
while(a[i]!='/')
{
b[j]=a[i];
i++;
j++;
}
b[j]='\0';
i++;
while(a[i]!='\0')
{
c[n]=a[i];
n++;
i++;
}
c[n]='\0';
i=0;
while(b[i]==c[i])
{f[i]=b[i];
i++;
}
f[i]='\0';
n=0;
j=i;
while(b[i]!='\0')
{ g[n]=b[i];
n++;
i++;
}

g[n]='\0';
n=0;
while(c[j]!='\0')
{ h[n]=c[j];
n++;
j++;
}

h[n]='\0';
printf("S-%sD\n",f);
printf("D-%s/%s/e\n",g,h);
}

VIVA Questions

Ques 1: What is left factoring?


Ans : A process of transformation, turning the grammar from a left-recursive form to an equivalent
non-left-recursive form.

Ques 2: Difference between left factoring and left recursion?


Ans : Left Factoring is a grammar transformation technique. It consists in "factoring out" prefixes
which are common to two or more productions.
Left Recursion is a property a grammar has whenever you can derive from a given variable (non
terminal) a RHS that begins with the same variable, in one or more steps.

OUTPUT:

Vous aimerez peut-être aussi