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
3
votes
2 answers

How do unary operators get parsed using RPN?

Given the infix expression -190 + 20, what would the correct result look like as RPN? -190 + 20 == -190 20 + ? or.. -190 + 20 == 190 - 20 + ? Are the rules for unary operators (negative) the same as other operators, but just a right associative…
GN.
  • 8,672
  • 10
  • 61
  • 126
3
votes
3 answers

Postfix and prefix increment that causes an error

Why does that code does not compile due to an error: #include using namespace std; int main() { int i = 0; cout << ++(i++) << " " << i << endl; return 0; } While that code does compile: #include using namespace…
Yaroslav
  • 1,325
  • 1
  • 11
  • 23
3
votes
5 answers

convert a prefix expression to infix expression using javaScript

I am really struck with a question . convert the below expression using javaScript [ "AND", ["<", "var1", "var2"], [ "OR", [">", "var3", "var4"], ["==", "var5", "var6"] ] to var1 < val2 AND (var3 > val4 OR val5 == val6) Sorry that, I dont have…
3
votes
1 answer

Scala Postfix operator warning contradicts with Scaladoc

My code: val exitStatus = url #> outfile ! scala.sys.process: new URL("http://www.scala-lang.org/") #> new File("scala-lang.html") ! Warning: postfix operator ! should be enabled [warn] by making the implicit value scala.language.postfixOps…
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
3
votes
1 answer

How to ensure evaluation order and formal parameter order for named argument lists?

Working on a compiler, I am facing a problem related to named argument lists and evaluation order. Basically, the language ensures that for the following function and function call: int call(int first, int second) = first - second int…
3
votes
1 answer

Haskell - create artihmetic tree from prefix expression

I want to create arithmetic binary tree from prefix notation. My tree is defined as: data Tree a = Leaf Int | Node Tree String Tree deriving (Show) I want to convert it to arithmetic binary tree, like this: arithmetic tree To evaluate prefix…
3
votes
3 answers

Which of the following postfix notations correctly represents infix sum 1+2+3+4?

I am testing an infix-to-postfix-to-infix converter and found some kind of uncertainty. For example, a simple infix sum 1 + 2 + 3 + 4 can be converted to postfix one 1 2 + 3 + 4 + assuming that operators with equal precedence are not accumulated.…
Andrei
  • 10,918
  • 12
  • 76
  • 110
3
votes
1 answer

How can I correctly combine multiple boolean postfix expressions?

I've put together some code to convert between postfix and infix and back again. Now I'm trying to take separate postfix expressions and combine them. My expressions are only using boolean operators (NOT, XOR, AND, OR). Note that the numbers in…
hobwell
  • 538
  • 1
  • 8
  • 26
3
votes
4 answers

Evaluating postfix in python?

I want to write a fucnction to evaluate a postfix expression passed as a list. So far I have got: def evalPostfix(text): s = Stack() for symbol in text: if symbol in "0123456789": s.push(int(symbol)) if not…
ASm
  • 379
  • 4
  • 10
  • 20
3
votes
1 answer

Infix to postfix conversion in Python

I have started solving Data Structure problems in Python. I am implementing infix to postfix but not able to debug an error in my program. The final return statement where I perform join operation has input of type NONE. When I started debugging, I…
mrsan22
  • 727
  • 2
  • 11
  • 28
3
votes
2 answers

Apply distributive law on AST (or RPN) => disjunctive normal form

I have expressions like the following: {1000} AND ({1001} OR {1002} OR {1003}) Allowed operators are OR and AND, expressions can be nested using parenthesis. I already managed to tokenize this string and to convert it to an abstract syntax tree…
3
votes
0 answers

Is Left associativity only for Postfix expression?

In case of evaluation of postfix expression , is the associativity always left to right?. If yes, why? If no, why?
user3202188
  • 131
  • 1
  • 7
3
votes
1 answer

NullPointerException infix to postfix java using stack

Currently I am working on a project using an ArrayStack to change an infix to postfix and evaluating the postfix evaluation. For the first operator that appears when the program reads it, it sends back java.lang.NullPointerException at…
3
votes
3 answers

infix to postfix conversion for exponentiation operation

I am learning polish notation and i tried a program for infix to postfix conversion. My program executed in a fine manner for operators like + and - . But for exponentiation operation which is right associative its not working correctly. For eg: …
poorvank
  • 7,524
  • 19
  • 60
  • 102
3
votes
3 answers

Shunting-yard algorithm in c++

I need a function that takes an infix string (like "3 + 4 * 9"), and convert it to postfix (like "4 9 * 3 +"). I got it working until you throw in parentheses within parentheses. I've been working on it all day and can't figure out what I'm doing…
user1311736
  • 83
  • 2
  • 2
  • 7
1 2
3
38 39