Simple program for operator precedence parser in C.
It takes the expression as input and calculates the precedence of the operators.
Subscribe to the blog to get instant updates via E-Mail.
It takes the expression as input and calculates the precedence of the operators.
Subscribe to the blog to get instant updates via E-Mail.
PROGRAM CODE:
#include<stdio.h>
#include<string.h>
void main()
{
int i,j,cnt=1;
char operators[] ="*/%+-",input[100];
printf("Enter the statement : ");
gets(input);
for(i=0;i<strlen(operators);i++)
{
for(j=0;j<strlen(input);j++)
{
if(input[j]==operators[i])
{
printf("%d %c=%c%c%c\n",cnt++,input[j-1],input[j-1],input[j],input[j+1]);
input[j+1]=input[j-1];
}
}
}
}
OUTPUT:
Subscribe to the blog to get instant updates via E-Mail.
Notify the Suggestions about the program through comments ... :)
0 comments:
Post a comment