problem with infix 2 postfix converter & postfix calculator

This is a discussion on problem with infix 2 postfix converter & postfix calculator within the C Programming forums, part of the General Programming Boards category; This is in regards to a class lab project on building a top down parser using flex in Linux as ...

problem with infix 2 postfix converter & postfix calculator

This is in regards to a class lab project on building a top down parser using flex in Linux as scanner/lexer and parser should convert valid infix expressions to postfix & calculate the result of the expression. Took me a while to comprehend what to do but I managed to almost complete the parser. It may not be optimal but it works. Unfortunately, I ran into some snags along the way, haven't figured it out yet, and my back's starting to ache. So in case I haven't solved it yet later on, hope someone can point out my logic errors.

Here's my problems:

1) infix 2 postfix conversion works 99% -- the left parenthesis still shows up in the postfix expression when it should not.

Both 1 & 2 were based on algorithms found on net. I'm including snippets of the problem code. If you think the problem is not in those code snippets, let me know & I'll post other portions of the code.

fixed calculator but still parenthesis issue

Thanks for the pointers Salem. The calculator is now fixed. I was so tired I probably overlooked the stack logic mismatch.

Originally Posted by Salem

> else if(token == TOKRPAREN)
When you do this, you need to remove the ), not just find it.

Now for the parenthesis, can you elaborate if that is the issue? The value of ")" resides in the var called data that is passed to the function. I have not used the var data when the function goes to that conditional branch. So the ")" never goes to the stack. The function is called whenever the next token is needed.

What stumps me (at least right now) is that expressions w/ no parenthesis work ok. With parentheses is nearly ok, except for the inclusion of "(". Perhaps I need to do extra pop(s) somewhere appropriate but I'm not sure where? Either that or the string compare of the postfixStack & "(" is not working right.