main.c
#include "stack.h"
#include "stack_interface.h"
#include "lex.h"
#include <stdio.h>
#include <stdlib.h>
#define PUSH(s,c)
if(push_char(s,c) == ERROR){
printf("Fatal error in pushing symbol on stack.\n") ;
exit(1) ;
}
#define POP(s,c)
if(pop_char(s,c) == ERROR){
printf("Fatal error in poping symbol off stack.\n") ;
exit(1) ;
}
#define TOP(s,c)
if(top_char(s,c) == ERROR){
printf("Fatal error in top operation.\n") ;
exit(1) ;
}
int stackprec(stack *p_S) ;
int inputprec(char c ) ;
void skiptoeol() ;
void clearstack(stack *p_S) ;
main( int argc , char *argv[]){
stack S ;
tokendata *p_token ;
char stacksymbol ;
bool eofreached = FALSE ;
init_stack(&S) ;
PUSH(&S , BOTTOMMARKER) ;
do{
p_token = gettoken() ;
switch(p_token->tokentype){
case EOF_T:
eofreached = TRUE ;
break ;
case VARIABLE_T:
printf("%c ",p_token->tokenvalue) ;
break ;
case OPERATOR_T:
while(stackprec(&S)>=inputprec(p_token->tokenvalue)){
POP(&S,&stacksymbol) ;
printf("%c ",stacksymbol) ;
}
PUSH(&S,p_token->tokenvalue);
break ;
case RIGHTPAREN_T:
do{
POP(&S,&stacksymbol) ;
if(stacksymbol == BOTTOMMARKER){
printf("Error in expression.\n") ;
skiptoeol() ;
clearstack(&S) ;
break ;
}
if(stacksymbol != '(')
printf("%c ", stacksymbol) ;
}while(stacksymbol != '(') ;
break ;
case EOL_T:
TOP(&S,&stacksymbol) ;
while( stacksymbol != BOTTOMMARKER){
POP(&S,&stacksymbol) ;
if(stacksymbol == '(') {
printf("Error in expression.\n") ;
clearstack(&S) ;
}else
printf("%c ",stacksymbol) ;
TOP(&S,&stacksymbol) ;
}
putchar('\n') ;
break ;
}
}while(eofreached == FALSE) ;
}
int stackprec(stack *p_S){
char topsymbol ;
TOP(p_S,&topsymmbol) ;
switch(topsymbol){
case '(':
return 0 ;
case '*':
case '/':
return 2;
case '+':
case '-':
return 1 ;
case '$':
return -1 ;
default:
printf(" Unknown symbol on stack: %c\n" , topsymbol) ;
return -1 ;
}
printf("Reached an unreacheable section of code!\n") ;
return -1 ;
}
int inputprec(char c ){
switch(c){
case '(':
return 3 ;
case '*':
case '/':
return 2 ;
case '+':
case '-':
return 1 ;
default:
printf(" Unknown operator in input: %c\n" , c) ;
return -1 ;
}
printf("Reached an unreacheable section of code!\n") ;
return -1 ;
}
void skiptoeol(){
tokendata *p_token ;
do{
p_token = gettoken() ;
}while(p_token->tokentype!=EOL_T && p_token->tokentype!=EOF_T) ;
putchar('\n') ;
}
void clearstack(stack *p_S){
char c ;
while(empty_stack(p_S) == FALSE)
POP(p_S,&c) ;
PUSH(p_S,BOTTOMMARKER) ;
}
Errors
main.c:9: error: syntax error before "if"
main.c:11: error: syntax error before numeric constant
main.c:11: error: conflicting types for 'exit'
main.c:11: error: conflicting types for 'exit'
main.c:11: warning: data definition has no type or storage class
main.c:18: error: syntax error before numeric constant
main.c:18: warning: data definition has no type or storage class
main.c:24: error: syntax error before numeric constant
main.c:24: warning: data definition has no type or storage class
data definition has no type or storage class
wy does it say conflicting types for exit