Send Close Add comments: (status displays here)
Got it!  This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Postfix code to tree


1. Postfix code to tree

2. Postfix to tree
Expression tree for (X & Y) | ((! X) & (! Y))The postfix code can be used, if needed, to reconstruct a tree. Thus, the postfix code can be used as a compact way to store a tree.
( X & Y ) | ( ( ! X ) & ( ! Y ) )


3. Postfix representation and code list.
Here is the postfix representation.
   x y & x ! y ! & |

Here is a list that can represent the code.
codeList1 = [    ["var", "x"],    ["var", "y"],    ["op2", "and"],    ["var", "x"],    ["op1", "not"],    ["var", "y"],    ["op1", "not"],    ["op2", "and"],    ["op2", "or"],    ]

Here is a code example, with print statements interspersed to trace what is happening.

Here is the JavaScript code.

Here is the output of the JavaScript code.

Note that the printed output of a list (above) is not pretty-printed, but printed using the default print behavior. For pretty-print purposes, a special-purpose routine is needed to output the structure in the form desired (omitted, left as an exercise).

4. End of page