Results 1 to 11 of 11
  1. #1
    ale626 is offline Member
    Join Date
    May 2012
    Posts
    27
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    ale626 is offline Member
    Join Date
    May 2012
    Posts
    27
    Rep Power
    0

    Default 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. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    ale626 is offline Member
    Join Date
    May 2012
    Posts
    27
    Rep Power
    0

    Default Re: Order of operations using stacks and queues

    i completely blanked on looking up your article, its the one titled compilers?

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    ale626 is offline Member
    Join Date
    May 2012
    Posts
    27
    Rep Power
    0

    Default Re: Order of operations using stacks and queues

    thanks, im reading it now, ill see how far i get into it tonight

  8. #8
    ale626 is offline Member
    Join Date
    May 2012
    Posts
    27
    Rep Power
    0

    Default Re: Order of operations using stacks and queues

    oh link to it is down, any chance of updating it?

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: Order of operations using stacks and queues

    Quote Originally Posted by ale626 View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    ale626 is offline Member
    Join Date
    May 2012
    Posts
    27
    Rep Power
    0

    Default 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

  11. #11
    ale626 is offline Member
    Join Date
    May 2012
    Posts
    27
    Rep Power
    0

    Default 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!

Similar Threads

  1. Replies: 7
    Last Post: 03-21-2012, 06:18 AM
  2. Adding order of operations in Java
    By ratyo8 in forum New To Java
    Replies: 1
    Last Post: 01-30-2012, 01:57 AM
  3. Queues
    By A.M.S in forum New To Java
    Replies: 3
    Last Post: 12-23-2009, 10:00 PM
  4. Help with Queues in Java
    By Java01 in forum New To Java
    Replies: 3
    Last Post: 11-07-2008, 03:56 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:05 AM

Posting Permissions

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