[system] / trunk / pg / macros / Parser.pl Repository: Repository Listing bbplugincoursesdistsnplrochestersystemwww

# Diff of /trunk/pg/macros/Parser.pl

Revision 5071 Revision 5368
53# 53#
54# \$x = Compute("x+3",x=>2) 54# \$x = Compute("x+3",x=>2)
55# 55#
56# will produce the equivalent of \$x = Real(5). 56# will produce the equivalent of \$x = Real(5).
57# 57#
58# The original parsed formula will be saved in the object's
59# original_formula field, and can be obtained by
60#
61# \$x->{original_formula};
62#
63# if needed later in the problem.
64#
58 65
59=cut 66=cut
60 67
61sub Compute { 68sub Compute {
62 my \$string = shift; 69 my \$string = shift;
63 my \$formula = Formula(\$string); 70 my \$formula = Formula(\$string);
64 \$formula = \$formula->eval(@_) if scalar(@_) || \$formula->isConstant; 71 \$formula = \$formula->{tree}->Compute if \$formula->{tree}{canCompute};
72 if (scalar(@_) || \$formula->isConstant) {
73 my \$f = \$formula;
74 \$formula = \$formula->eval(@_);
75 \$formula->{original_formula} = \$f;
76 }
65 \$formula->{correct_ans} = \$string; 77 \$formula->{correct_ans} = \$string;
66 return \$formula; 78 return \$formula;
67} 79}
68 80