• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Infix to Postfix using Recursion with grammars

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Ranch Hand
Posts: 88
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic