Questions tagged [postfix-notation]

Postfix notation (also known as Reverse Polish Notation, RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.

Postfix notation (also known as Reverse Polish Notation, RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.

Both and postfix notation have the advantage over infix notation that operator precedence is completely defined by the expression, without parentheses being required, which further implies that both can be evaluated linearly by machine instructions without parsing.

572 questions
2
votes
1 answer

Shunting-Yard VS Recursive Descent Parser

I am building an advanced mathematical parser and would like to know the difference between Shunting-Yard and the other available parser algorithms like "Descent Parser" knowing that I prefer to store the formula in RPN notation. Thanks in advance,
2
votes
1 answer

Postfix to infix with unary/binary operators

I am trying to make a converter from postfix to infix notation and need some help. There is already a question about infix-to-postfix conversion, which gives an example I am failing to convert back. (Note: a minus sign is missing there!) The…
Andrei
  • 10,918
  • 12
  • 76
  • 110
2
votes
2 answers

Program does not accept argument Python

I am creating a postfix calculator that accepts arithmetic expressions and first pushes the operators to the stacl. ./pythonfilename 3 4 1 + - was used as my input. However, since no output is displayed, I tried to debug my program to see why my…
syavatkar
  • 85
  • 1
  • 1
  • 7
2
votes
1 answer

Postfix Expressions advantages?

What are advantages of post-fix expressions over prefix expressions? What can be the disadvantages of prefix expressions that can be removed using postfix expressions?
2
votes
2 answers

Cannot understand what I need to check for in the condition of a while loop in Java

I am having trouble understanding what I need to check for in the condition evaluation of the following while loop, which is an excerpt of an algorithm's pseudocode: if the token is an operator { while(the stack is not empty …
idelara
  • 1,786
  • 4
  • 24
  • 48
2
votes
2 answers

How to solve a simple linear equation using postfix

I have a program that takes in a simple linear equation and transforms it into its equivalent in postfix. For example: 3x+7=4(2x-1) would be transformed into 3 x * 7 + = 4 2 x * 1 - * How can i get the value of x in this example using its…
2
votes
2 answers

Evaluate Postfix Using Stack

I am trying to create a program which evaluates postfix expression.For example "3500 43 12 * 47 2 / + -" .Here is my code public static int EvaluatePostfixExpression(String postfixExpr){ Stack s = new Stack(); int result = 0; String…
Yunus Emre Güler
  • 387
  • 1
  • 6
  • 16
2
votes
2 answers

Traverse Context Free Grammar

I am facing a problem of traversing a CFG used in prolog environment , to make it traverse in a postorder way. Following is the grammar used - list_ast(Ls, AST) :- phrase(expression(AST), Ls). expression(E) --> term(T), expression_r(T,…
Being Coder
  • 127
  • 2
  • 10
2
votes
1 answer

Number of characters in Postfix notation when number in Infix notation is known

I am converting expressions with only function calls and integers from Infix notation to Postfix notation (only letters,digits,commas,brackets and no spaces). For example, add(add(1,2),add(3,4)) to 1 2 add 3 4 add add. Input expression is 22…
Somnium
  • 1,059
  • 1
  • 9
  • 34
2
votes
1 answer

Scala postfixOps feature not operating inside an object block

Suppose I have the following file test.scala import scala.language.postfixOps trait Trait { var v = 'a def update(x :Symbol):Unit = { v = x } } object x extends Trait x update 'b // value of x.v is now 'b, as expected object y extends…
eje
  • 945
  • 11
  • 22
2
votes
2 answers

Having trouble casting a stack object number to int (Java)

I'm writing a program that converts an expression from infix to postfix. I have the conversion part down but when it comes to evaluating the postfix expression, I run into problems with converting from char to int using the stack. I keep getting the…
Jonny
  • 67
  • 1
  • 2
  • 9
2
votes
0 answers

How can we convert Prefix to Postfix expression ( without using expression tree)?

By using Stack data structure, we can easily convert "Infix to Postfix" and "infix to Prefix" but I can't convert Prefix to postfix. yes, we can convert prefix to infix then infix to postfix. but I want direct conversion from prefix to postfix. Is…
SIVA
  • 439
  • 2
  • 7
  • 13
2
votes
5 answers

Postfix evaluation for multidigit numbers

I as programming a postfix evaluator, and I was able to do it correctly for single digit number. Now I need an idea of how to do it for multiple digit number, as my current program evaluates a two digit number as different numbers. Here's the code…
chettyharish
  • 1,704
  • 7
  • 27
  • 41
2
votes
2 answers

String conversion to a mathematical expression

I've written an application that converts a string into a mathematical expression for evaluation. This is done by converting the string into postfix and then by constructing an expression tree and solving it. Now I want to know though, what is the…
user2831683
  • 967
  • 1
  • 10
  • 21
2
votes
1 answer

postfix calculator does not work, why? - C

i have postfix calculator, but he is not working, can you please help me? I want calculate postfix expression 2 sin 2 cos / 5 * Output is 5.000000, but correct output is 0.17... Calculations work! I think the problem is somewhere in adding…