A
Andre Caldas
Hello!
No... I think they must be pretty usefull for engineers, though.
This was enlightening, thank you.
By the way, is there anything good about preorder? I tryied to think of
a machine to execute it is much more complicated then postorder: that
is, I need one stack for the operands, and one "buffer" to store the
result. (well, the words on the operand stack could have only 2 bits
each - +,-,/,* -, and thats good! - you cannot use this reason ;-))
That's what I ment, sorry. Actually I guess it would be harder to
construct a tree from "postfix" or "prefix", since you would have to
start from the leaves.
I guess this was what it was all about. If the "functional" thing was
"infix" or "postfix".
Thank you.
You obviously never had a HP pocket calculator
No... I think they must be pretty usefull for engineers, though.
preorder: the node first, then left subtree, right subtree
inorder: left subtree first, node, right subtree
postoder: left subtree first, right subtree, node
This was enlightening, thank you.
By the way, is there anything good about preorder? I tryied to think of
a machine to execute it is much more complicated then postorder: that
is, I need one stack for the operands, and one "buffer" to store the
result. (well, the words on the operand stack could have only 2 bits
each - +,-,/,* -, and thats good! - you cannot use this reason ;-))
Parsing is not the problem. Evaluating is!
With inorder notation, you need to incorporate the arithmetic rules
of precedence. It is not uncommon for compilers to first build
an expression tree from an infix notation, traverse that expression
tree in postorder and emit the code from that postorder traversel.
Why? Because arithmetic precedence has already been dealt with during
parsing and the tree has organized the opertions already correctly.
That's what I ment, sorry. Actually I guess it would be harder to
construct a tree from "postfix" or "prefix", since you would have to
start from the leaves.
in a more functional approach (as eg. in Lisp) the whole expression
can be written as:
add( 1, times( add( 2, 3 ), 4 ) )
I guess this was what it was all about. If the "functional" thing was
"infix" or "postfix".
Thank you.