Slr Parsing Table Program In C

/. SLR parser for the grammar E-E+T (1) E-T (2) T-T.F (3) T-F (4) F-(E) (5) F-ID (6)./ /. Stack structure and fuctions./ /. The only thing important here is that the value associated with each name of the macro should be unique. They have no realtion to the states in. Must Read: C Program For Recursive Descent Parsing Note: This C program to find First and Follow sets of a Grammar using Array is compiled with GNU GCC compiler and developed using gEdit Editor in Linux Ubuntu operating system. C Program To Find First of a Given Grammar using Array. Please like & subscribe for more CS based tutorials!:).

SlrSlr Parsing Table Program In C

Slr Parsing Table Program In C Pdf

Program

C Parsing String

/*OPERATOR PRECEDENCE PARSER*/
#include<stdio.h>
#include<conio.h>
void main()
{
char stack[20],ip[20],opt[10][10][1],ter[10];
int i,j,k,n,top=0,col,row;
clrscr();
for(i=0;i<10;i++){stack[i]=NULL; ip[i]=NULL;
for(j=0;j<10;j++){opt[i][j][1]=NULL;}}
printf('Enter the no.of terminals:');
scanf('%d',&n);
printf('nEnter the terminals:');
scanf('%s',ter);
printf('nEnter the table values:n');
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf('Enter the value for %c %c:',ter[i],ter[j]);
scanf('%s',opt[i][j]);
}
}
printf('nOPERATOR PRECEDENCE TABLE:n');
for(i=0;i<n;i++){printf('t%c',ter[i]);}
printf('n');
for(i=0;i<n;i++){printf('n%c',ter[i]);
for(j=0;j<n;j++){printf('t%c',opt[i][j][0]);}}
stack[top]='$';
printf('nEnter the input string:');
scanf('%s',ip);
i=0;
printf('nSTACKtttINPUT STRINGtttACTIONn');
printf('n%sttt%sttt',stack,ip);
while(i<=strlen(ip))
{
for(k=0;k<n;k++)
{
if(stack[top]ter[k])
col=k;
if(ip[i]ter[k])
row=k;
}
if((stack[top]'$')&&(ip[i]'$')){
printf('String is accepted');
break;}
else if((opt[col][row][0]'<') ||(opt[col][row][0]'='))
{ stack[++top]=opt[col][row][0];
stack[++top]=ip[i];
printf('Shift %c',ip[i]);
i++;
}
else{
if(opt[col][row][0]'>')
{
while(stack[top]!='<'){--top;}
top=top-1;
printf('Reduce');
}
else
{
printf('nString is not accepted');
break;
}
}
printf('n');
for(k=0;k<=top;k++)
{
printf('%c',stack[k]);
}
printf('ttt');
for(k=i;k<strlen(ip);k++){
printf('%c',ip[k]);
}
printf('ttt');
}
getch();
}