Arithmetic evaluation: Difference between revisions

Content added Content deleted
(added Ruby solution.)
m (→‎{{header|Ruby}}: slight rewording of explanation.)
Line 1,845: Line 1,845:


=={{header|Ruby}}==
=={{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). Source: http://www.seas.gwu.edu/~csci131/fall96/exp_to_tree.html
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). Algorithm: http://www.seas.gwu.edu/~csci131/fall96/exp_to_tree.html
<lang ruby>$op_priority = {"+" => 0, "-" => 0, "*" => 1, "/" => 1}
<lang ruby>$op_priority = {"+" => 0, "-" => 0, "*" => 1, "/" => 1}
$op_function = {
$op_function = {