Anonymous user
Arithmetic evaluation: Difference between revisions
→{{header|Tcl}}: renamed 'arieval' to the clearer 'ast'
(→{{header|Tcl}}: use 'in' operator) |
(→{{header|Tcl}}: renamed 'arieval' to the clearer 'ast') |
||
Line 1,452:
<lang Tcl>namespace import tcl::mathop::*
proc
# produce abstract syntax tree for an expression
regsub -all {[-+*/()]} $str { & } str ;# "tokenizer"
Line 1,485:
#-- Test suite
foreach test [split {
} \n] {
puts "$test ..... [eval $test] ..... [eval [eval $test]]"
}</lang>
Output:<pre>
</pre>
|