Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 11
    If you are working on a stack, the [operation: *] should come after the two inputs. It doesn't affect the important bits of what you're saying here, so it's just a minor quibble. Commented Mar 20, 2015 at 12:12
  • 6
    I find this answer quite confusing. If you're considering a stack machine, the operations are: compute the side effect and value of ++y and push the result on the stack, then compute the side effect and value of y++ and put the result on the stack, then push 5 on the stack, then pop two things off the stack, add them, and push the sum on the stack, then pop two things off the stack, multiply them, and put the product on the stack. Commented Mar 20, 2015 at 17:54
  • Okay, using post-fix notation it is expressed as [++y][y++][5]+* or 11 11 5 + *. During he first phase parsing it will push the 3 values into the stack [5][11][11] in that order. Next it will find the + operator and it will pop 2 values from the stack 11 and 5, the result of the operation, which is 16, will be pushed back into the stack, hence the stack state will be [16][11]. The next token is another operator *, so it will pop 2 values from the stack again and perform the operation: 11 * 16 (note: the 2nd value popped will be the first operand). Commented Mar 20, 2015 at 18:57
  • @OwenBringino Realistically a high level programming language will not use a "stack", it will implement the rules of the grammar. So your analogy falls apart easily. Commented Mar 20, 2015 at 22:59