Penguin
Note: You are viewing an old revision of this page. View the current version.

Style of syntax used for writing expressions:

  • In infix notation you write the operator between the arguments.

c - (5 + a + x) * b

Infix notation is the usual. It needs precedence rules and/or brackets to make the order of operations unambiguous though. Polish and Reverse Polish don't have that problem, providing the number arguments to each operator is fixed.

  • In Reverse Polish, or postfix, notation you write the operator after the arguments.

c 5 a + x + b * -

It's very easy to interpret expressions in this notation, you need just a single stack to place intermediate values on, this is why FORTH? uses it.

  • In Polish, or prefix, notation you write the operator before the arguments.
  • c * + 5 + a x b

Polish notation is called that because a famous Polish mathematician first used it for Boolean algebra, and nobody can either remember or pronounce his name without looking it up first. (You go look it up.)

  • In S-exp, or Lisp, notation you write the operator before the arguments, enclosed in brackets.

(- c (* (+ 5 a x) b))

Lisp operators take any number of arguments so Lisp expressions need brackets to associate arguments with operators.

It's very easy to parse this notation into tree structures, which is why Lisp uses it.

  • In XML notation you bracket the arguments with the operator:

<subtract>

<variable name="c"/> <multiply>

<add>

<constant value="5"/> <variable name="a"/> <variable name="x"/>

</add> <variable name="b"/>

</multiply>

</subtract>

Whoever came up with this had good intentions, I'm sure...