Write a function to evaluate Postfix expression

Function to evaluate Postfix expression

int eval(void) 
{ 
precedence token; 
char symbol; 
int opl,op2, n=0; 
int top= -1; 
token = getToken(&symbol, &n); 
while(token! = eos) 
{ 
if (token == operand) 
push(symbol-'0'); /* stack insert */ 
else { 
op2 = pop(); /* stack delete */ 
opl = pop(); 
switch(token) { 
} 
case plus: push(opl+op2); 
break; 
case minus: push(opl-op2); 
break; 
case times: push(opl*op2); 
break; 
case divide: push(opl/op2); 
break; 
case mod: push(opl%op2); 
} 
token = getToken(&symbol, &n); 
} 
return pop(); /* return result */ 
} 

Leave a Reply

Your email address will not be published. Required fields are marked *