Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write a C program that can evaluate reverse polish notation (postfix nota

ID: 3713155 • Letter: P

Question

Please write a C program that can evaluate reverse polish notation (postfix notation).

?Given is the following C File

int parseoperand(int* op) {
    char c;
    while (isspace((c = getchar())));
    ungetc(c, stdin);
    if (c == '+' || c == '-')
        return 0;
    return fscanf(stdin, "%d", op) == 1;
}

int parseoperator(char* op) {
    char c;
    while (isspace((c = getchar())));
    if (c == '+' || c == '-') {
        *op = c;
        return 1;
    }
    ungetc(c, stdin);
    return fscanf(stdin, "%[*/%^&|~]", op) == 1;
}

int endofstream() {
    return feof(stdin);
}

Please add three files stack.c , calc.c and main.c to this program

stack.c will make use of pop,push and empty functions . Make sure that the variables are static and functions are visible because other files have to interact with this file

calc.c will make use of arithmetic associated with the reverse polish notation.
It will only contain one function void math(char);
The function should take the operator, the top 2 operands on stack, and calculate the three of them together
The result of evaluation should be pushed on the stack and please declare functions as external .

main.c module
this is the main function which is responsible for overall evaluations. It should only contain main function . If the stack contains error , it should print error and exit whereas if it contains no error it should print the result.
Also declare the function/variables as external since all other files are dependent on this.

Example Input:• 120 20 + 566 431 - *
Answer: 18900

Explanation / Answer

#include<stdio.h>

#define MAX 20

typedef struct stack

{

int data[MAX];

int top;

}stack;

void init(stack *);

int empty(stack *);

int full(stack *);

int pop(stack *);

void push(stack *,int);

int evaluate(char x,int op1,int op2);

int main()

{

stack s;

char x;

int op1,op2,val;

init(&s);

printf("Enter the expression(eg: 59+3*) Single digit operand and operators only:");

  

while((x=getchar())!=' ')

{

if(isdigit(x))

push(&s,x-48); //x-48 for removing the effect of ASCII

else

{

op2=pop(&s);

op1=pop(&s);

val=evaluate(x,op1,op2);

push(&s,val);

}

}

  

val=pop(&s);

printf(" Value of expression=%d",val);

return 0;

}

int evaluate(char x,int op1,int op2)

{

if(x=='+')

return(op1+op2);

if(x=='-')

return(op1-op2);

if(x=='*')

return(op1*op2);

if(x=='/')

return(op1/op2);

if(x=='%')

return(op1%op2);

}

void init(stack *s)

{

s->top=-1;

}

int empty(stack *s)

{

if(s->top==-1)

return(1);

  

return(0);

}

int full(stack *s)

{

if(s->top==MAX-1)

return(1);

  

return(0);

}

void push(stack *s,int x)

{

s->top=s->top+1;

s->data[s->top]=x;

}

int pop(stack *s)

{

int x;

x=s->data[s->top];

s->top=s->top-1;

  

return(x);

}