# Thread: Order of operations using stacks and queues

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.

2. ## 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,

Jos

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?

4. ## 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,

Jos

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?

6. ## 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,

Jos

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

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?

9. ## Re: Order of operations using stacks and queues

Originally Posted by ale626
oh link to it is down, any chance of updating it?
Strange, I just re-read my own blog article and everything worked fine ...

kind regards,

Jos

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

11. Member
Join Date
May 2012
Posts
27
Rep Power
0

## Re: Order of operations using stacks and queues

oh nevermind, i opened the page in IE and it worked, but chrome didnt weird, thanks anyways!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•