• Post Reply Bookmark Topic Watch Topic
  • New Topic

Infix to Postfix using Recursion with grammars  RSS feed

 
John Poob
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy yalls! Fellow ranchers, I call for your help.. I cant seem to understand how to output my Infix expressions (ex. (a+b)*c | a+(b*c) ) into a post fix Expression using a b c (ex. ab+c* | abc*+ )
I wish to do this using the recursive descent method and not the stack parsing method. The output either doesn't come out correctly or I get an error.

I know this can help in compiler design and has many other uses but my expect method exceptions keep coming up. I have the Grammars listed below and I appear to have a problem getting the correct Tokens to be parsed and outputting in the correct

Reverse Polish Notation (Postfix) from my Infix input. I aimed to use the consume method to take in the current token and advance to the next.
Can anyone point out the problems in my code? Ive used this format before for basic grammars but this is slightly more difficult.




 
Mack Wilmot
Ranch Hand
Posts: 88
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does that code work with no input?

Edit: Oh I see now, you are taking command line args.
 
Mack Wilmot
Ranch Hand
Posts: 88
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You just go into infinite recursion when you parse a "(". Just look at the stack overflow exception: F T e F T e ... F t e BONK!
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
Some of your lines are too long to be read properly inside code tags. I shall try to change that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!