Week - 4 Top Down Parsing 4.1) Develop An Operator Precedence Parser For A Given Language. Program
Week - 4 Top Down Parsing 4.1) Develop An Operator Precedence Parser For A Given Language. Program
Week - 4 Top Down Parsing 4.1) Develop An Operator Precedence Parser For A Given Language. Program
Date:
Week – 4 Top Down Parsing
4.1) Develop an operator precedence parser for a given language.
Program:
#include<stdio.h>
#include<string.h>
char stack[20],temp;
int top=-1;
void push(char item)
{
if(top>=20)
{
printf("STACK OVERFLOW");
return;
}
stack[++top]=item;
}
char pop()
{
if(top<=-1)
{
printf("STACK UNDERFLOW");
return;
}
char c;
c=stack[top--];
printf("Popped element:%c\n",c);
return c;
}
char TOS()
{
return stack[top];
}
int convert(char item)
{
switch(item)
{
case 'i':return 0;
case '+':return 1;
case '*':return 2;
case '$':return 3;
}
}
int main()
{
Program:
#include<stdio.h>
#include<ctype.h>
#include<string.h>
void Tp();
void Ep();
void E();
void T();
void check();
int count,flag;
char expr[10];
int main()
{
count=0;
flag=0;
printf("\nEnter an Algebraic Expression:\t");
scanf("%s",expr);
E();
if((strlen(expr)==count)&&(flag==0))
printf("\nThe expression %s is valid\n",expr);
else
printf("\nThe expression %s is invalid\n",expr);
return 0;
}
void E()
{
T();
Ep();
}
void T()
{
check();
Tp();
}
void Tp()
{
if(expr[count]=='*')
{
count++;
check();
Tp();
Output: