Expression Parsing

The way to write arithmetic expression is known as a notation. An arithmetic expression can be written in three different but equivalent notations, i.e., without changing the essence or output of an expression. These notations are −

  • Infix Notation
  • Prefix (Polish) Notation
  • Postfix (Reverse-Polish) Notation

Infix Notation

Infix notation is used to write expressions, such as a – b + c, where operators are used in-between operands. It is simple for humans to read, write, and talk in infix notation, but this is not the case for computing machines. A method for processing infix notation could be complicated and time and space-consuming.

Prefix Notation

In this notation, the operator is written before the operands, i.e. the operator comes first. For instance, +ab. This corresponds to the infix notation a + b. Polish Notation is another name for prefix notation.

Postfix Notation

Reversed Polish Notation is the name given to this notation style. The operator is postfixed to the operands in this notation style, which means it is written after the operands. For instance, ab+. This corresponds to the infix notation a + b.

Sr.No.Infix NotationPrefix NotationPostfix Notation
1a + b+ a ba b +
2(a + b) ∗ c∗ + a b ca b + c ∗
3a ∗ (b + c)∗ a + b ca b c + ∗
4a / b + c / d+ / a b / c da b / c d / +
5(a + b) ∗ (c + d)∗ + a b + c da b + c d + ∗
6((a + b) ∗ c) – d– ∗ + a b c da b + c ∗ d –

1 thought on “Expression Parsing”

Leave a Comment

Your email address will not be published. Required fields are marked *