ALGORITHM:
- Get the input expression and store it in the input buffer.
- Read the data from the input buffer one at the time and convert in to corresponding Non Terminal using production rules available.
- Perform push & pop operation for LR parsing table construction.
- Display the result with conversion of corresponding input symbols to production and production reduction to start symbol. No operation performed on the operator.
#include
#include
char stack[30];
int top=-1;
void push(char c)
{
top++;
stack[top]=c;
}
char pop()
{
char c;
if(top!=-1)
{
c=stack[top];
top--;
return c;
}
return'x';
}
void printstat()
{
int i;
printf("\n\t\t\t $");
for(i=0;i<=top;i++)
printf("%c",stack[i]);
}
void main()
{
int i,j,k,l;
char s1[20],s2[20],ch1,ch2,ch3;
clrscr();
printf("\n\n\t\t LR PARSING");
printf("\n\t\t ENTER THE EXPRESSION");
scanf("%s",s1);
l=strlen(s1);
j=0;
printf("\n\t\t $");
for(i=0;i
OUTPUT: LR PARSING ENTER THE EXPRESSION id+id*id-id $ $id $E $E+ $E+id $E+E $E+E* $E+E*id $E+E*E $E+E*E- $E+E*E-id $E+E*E-E $E+E*E-E $E+E*E $E $