954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help cant get my main file to compile

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

rockerjhr
Junior Poster in Training
58 posts since Dec 2010
Reputation Points: 7
Solved Threads: 1
 

Preprocessor macros must be all on one line. You'll typically see multi-line macros extend the line by using the \ character:

#define PUSH(s,c)  \
	if(push_char(s,c) == ERROR){ \
		printf("Fatal error in pushing symbol on stack.\n") ; \
		exit(1) ; \
}
Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

now i get

main.c:13: error: syntax error before '}' token
main.c: In function `main':
main.c:106: error: syntax error before "int"
main.c:111: error: `p_S' undeclared (first use in this function)
main.c:111: error: (Each undeclared identifier is reported only once
main.c:111: error: for each function it appears in.)
main.c:111: error: `topsymbol' undeclared (first use in this function)
main.c: In function `clearstack':
main.c:187: error: syntax error at end of input
rockerjhr
Junior Poster in Training
58 posts since Dec 2010
Reputation Points: 7
Solved Threads: 1
 

If you don't understand the preprocessor, maybe you should start with smaller examples to learn instead of just jumping right in and hoping someone else will fix all of your errors.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

I do understand them the problem is not with the preprocessor macros i already fixed it its because i had blank spaces after the '/' read the errors thats not the problem

rockerjhr
Junior Poster in Training
58 posts since Dec 2010
Reputation Points: 7
Solved Threads: 1
 

Well, then if you want me to read your code more deeply, post something complete that I can play with without having to mock the universe.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

forget about it already found the real error the little careless mistakes i made in the main file had nothing to do with it even though you made it seem like it was a big deal telling me a had to go back to the basics and learn macros how pathetic

rockerjhr
Junior Poster in Training
58 posts since Dec 2010
Reputation Points: 7
Solved Threads: 1
 

I'm glad you figured out your problem. Next time post complete code and I'll do more than eyeball it.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: