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

Please help!!!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
how to uses java to write a program like this:
The input string, such as "7 * ( 23 - 105 / 15 ) - 19", is converted by the tokenizer into a sequence of tokens that are enqueued into the first buffer (i.e. queue) q1.

The validate method then dequeues the tokens, one at a time, and checks that the expression be valid. Each token is copied (i.e. enqueued) into the second buffer q2. If the expression is not valid an InvalidExpressionException is thrown and the whole process is terminated.

More detail on this method is given below.

The infix2postfix method converts the sequence of tokens (from q2) by re-ordering into postfix sequence and enqueues them into q3. Postfix notation is known commonly as reverse Polish notation.

The expression

7 * ( 23 - 105 / 15 ) - 19
with infix operators would appear as
7 23 105 15 / - * 19 -
in reverse Polish. The operator appears after the two values to which it applies. Brackets are not needed.

A means of converting infix expressions into reverse Polish is given below.

The evaluate method uses a stack to support evaluation of the reverse Polish expression and returns the result.
if someone knows how to do it, please help me! Thank you very much!!
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Parsing is a bigger topic than will fit in one post on a bulletin board, and it's not a beginner's task unless you were given an exact algorithm. I therefore assume that your homework assignment gave you an algorithm to follow which you did not post here. If not, you can start with the link below, choose a parsing algorithm, study it, and code it. For further help, you can try the dragon book (see this link).

http://en.wikipedia.org/wiki/Parser#Top-down_parsers
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
please don't post the same question to multiple forums -- it just wastes people's time and makes them less likely to want to help you. I'm closing this thread and leaving this copy open.
 
Your mother was a hamster and your father was a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic