Results 1 to 11 of 11
- 05-15-2012, 06:12 AM #1
Member
- Join Date
- May 2012
- Posts
- 27
- Rep Power
- 0
Order of operations using stacks and queues
Greetings, this is my first post. Sorry if it is in the wrong section.
So my problem is making my calculator use order of operations, including parenthesis.
right now I got it to read regular input like 3 + 4 , or 4 / 3 + 4 * 3, etc
as of now it just reads it from left to right.
the problem im having is the order of operations, which ive been staring at for hours.
This is the part of my assignment im missing.
As it is, the expression evaluator can only evaluate expressions involving additions and subtractions. You will extend the evaluator to support multiplication and division, as well as parenthesized expressions. You will also add the feature of precedence on the operators, imposing the following precedence:
+, -
*
/
You are allowed to used recursion and Queues to solve these problems.
So im just stuck, i emailed my professor but he is bad with returning emails. Wondering if someone can help me with the general idea. Right now my program runs with stacks, if my code is required ill post, but i rather not as its not due till friday.
- 05-15-2012, 09:14 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
Re: Order of operations using stacks and queues
Google for "operator precedence parsing"; there are numerous examples; or you can read my blog article on expression compilation (see the Blogs button near the top of this page).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-16-2012, 06:59 AM #3
Member
- Join Date
- May 2012
- Posts
- 27
- Rep Power
- 0
Re: Order of operations using stacks and queues
Thanks for the tip!
i found a few examples, the java ones i did find used stacks whereas i need queues or recursion, and the ones that did use recursion are in other languages im struggling to understand.
do you mind being a bit specific?
- 05-16-2012, 07:45 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
Re: Order of operations using stacks and queues
For parsing infix expressions you don't need queues; stacks or recursion will do; have you read my blog entry? It is full of recursive methods ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-16-2012, 08:19 AM #5
Member
- Join Date
- May 2012
- Posts
- 27
- Rep Power
- 0
Re: Order of operations using stacks and queues
i completely blanked on looking up your article, its the one titled compilers?
- 05-16-2012, 08:33 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
Re: Order of operations using stacks and queues
Yep, that's the one; it describes several implementations of (C-like) expression parsers and code generators.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-16-2012, 08:49 AM #7
Member
- Join Date
- May 2012
- Posts
- 27
- Rep Power
- 0
Re: Order of operations using stacks and queues
thanks, im reading it now, ill see how far i get into it tonight
- 05-16-2012, 08:54 AM #8
Member
- Join Date
- May 2012
- Posts
- 27
- Rep Power
- 0
Re: Order of operations using stacks and queues
oh link to it is down, any chance of updating it?
- 05-16-2012, 08:56 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,603
- Blog Entries
- 7
- Rep Power
- 17
- 05-16-2012, 09:04 AM #10
Member
- Join Date
- May 2012
- Posts
- 27
- Rep Power
- 0
Re: Order of operations using stacks and queues
i just get this when i click the link to the zip
Invalid Attachment specified. If you followed a valid link, please notify the administrator
- 05-16-2012, 09:12 AM #11
Member
- Join Date
- May 2012
- Posts
- 27
- Rep Power
- 0
Similar Threads
-
Node, Stacks and Queues: Why am I getting a bizarre output?
By son012189 in forum New To JavaReplies: 7Last Post: 03-21-2012, 06:18 AM -
Adding order of operations in Java
By ratyo8 in forum New To JavaReplies: 1Last Post: 01-30-2012, 01:57 AM -
Queues
By A.M.S in forum New To JavaReplies: 3Last Post: 12-23-2009, 10:00 PM -
Help with Queues in Java
By Java01 in forum New To JavaReplies: 3Last Post: 11-07-2008, 03:56 PM -
I want to be able to do this with stacks and queues as well as with vectors
By carl in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks