Anonymous user
Arithmetic evaluation: Difference between revisions
m
→{{header|Ruby}}: slight rewording of explanation.
(added Ruby solution.) |
m (→{{header|Ruby}}: slight rewording of explanation.) |
||
Line 1,845:
=={{header|Ruby}}==
Function to convert infix arithmetic expression to binary tree. The resulting tree knows how to print and evaluate itself. Assumes expression is well-formed (matched parens, all operators have 2 operands).
<lang ruby>$op_priority = {"+" => 0, "-" => 0, "*" => 1, "/" => 1}
$op_function = {
|