Part b 6

Run Settings
LanguageC
Language Version
Run Command
include<stdio.h> #include<string.h> char s[30],stack[20]; int main() { char m[5][6][3]={{"tb"," "," ","tb"," "," "}, {" ","+tb"," "," ","n","n"}, {"fc"," "," ","fc"," "," ",}, {" ","n","*fc"," ","n","n"}, {"d"," "," ","(e)"," "," "}}; int size[5][6]={2,0,0,2,0,0,0,3,0,0,1,1,2,0,0,2,0,0,0,1,3,0,1,1,1,0,0,3,0,0}; int i,j,k,n,str1,str2; printf("\n enter the input string:"); scanf("%s",s); strcat(s,"$"); n=strlen(s); stack[0]='$'; stack[1]='e'; i=1; j=0; printf("\n stack input\n"); printf("\n"); while((stack[i]!='$')&&(s[j]!='$')) { if(stack[i]=s[j]) { i--; j++; } switch(stack[i]) { case 'e':str1=0; break; case 'b':str1=1; break; case 't':str1=2; break; case 'c':str1=3; break; case 'f':str1=4; break; } switch(s[j]) { case 'd':str2=0; break; case '+':str2=1; break; case '*':str2=2; break; case '(':str2=3; break; case ')':str2=4; break; case '$':str2=5; break; } if(m[str1][str2][0]=='$') { printf("\n error\n"); return(0); } else if(m[str1][str2][0]='n') i--; else if(m[str1][str2][0]='i') stack[i]='d'; else { for(k=size[str1][str2] -1;k>=0;k-- ) { stack[i]=m[str1][str2][k]; i++; }i--; } for(k=0;k<=i;k++) printf("%c",stack[k]); printf(" "); for(k=j;k<=n;k++) printf("%c",s[k]); printf("\n"); } printf("\n SUCCESS"); } OUTPUT: $ cc ll1parsing.c $ ./a.out enter the input string:i+i*i stack input +i*i$ i*i$ *i$ i$ $ SUCCESS Ex-2: faculty@pec-server:~$ ./a.out enter the input string:i+i*i stack input +i*i$ i*i$ *i$ i$ $
Editor Settings
Theme
Key bindings
Full width
Lines