[system] / trunk / pg / macros / Parser.pl Repository:
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5372 Revision 5373
1 1
2 2
3=head1 DESCRIPTION 3=head1 DESCRIPTION
4 4
5########################################################################### 5 ###########################################################################
6## 6 ##
7## Set up the functions needed by the Parser. 7 ## Set up the functions needed by the Parser.
8## 8 ##
9 9
10=cut 10=cut
11 11
12if (!$Parser::installed) { 12if (!$Parser::installed) {
13 die "\n************************************************************\n" . 13 die "\n************************************************************\n" .
27loadMacros("Value.pl"); 27loadMacros("Value.pl");
28loadMacros("PGcommonFunctions.pl"); 28loadMacros("PGcommonFunctions.pl");
29 29
30=head3 Formula("formula") 30=head3 Formula("formula")
31 31
32# 32 #
33# The main way to get a MathObject Formula object (an equation 33 # The main way to get a MathObject Formula object (an equation
34# that depends on one or more variables). 34 # that depends on one or more variables).
35# 35 #
36 36
37=cut 37=cut
38 38
39 39
40sub Formula {Value->Package("Formula")->new(@_)} 40sub Formula {Value->Package("Formula")->new(@_)}
41 41
42 42
43 43
44=head3 Compute("formula"[,var=>value,...]) 44=head3 Compute("formula"[,var=>value,...])
45 45
46# 46 #
47# Compute the value of a formula and return a MathObject appropriate 47 # Compute the value of a formula and return a MathObject appropriate
48# to its value. Set the object so that the correct answer will be 48 # to its value. Set the object so that the correct answer will be
49# shown exatly as in the given string rather than by its usual 49 # shown exatly as in the given string rather than by its usual
50# stringification. If the value is a Formula and any var=>value 50 # stringification. If the value is a Formula and any var=>value
51# pairs are specified, then the formula will be evaluated using 51 # pairs are specified, then the formula will be evaluated using
52# the given variable values. E.g., 52 # the given variable values. E.g.,
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 58 # The original parsed formula will be saved in the object's
59# original_formula field, and can be obtained by 59 # original_formula field, and can be obtained by
60# 60 #
61# $x->{original_formula}; 61 # $x->{original_formula};
62# 62 #
63# if needed later in the problem. 63 # if needed later in the problem.
64# 64 #
65 65
66=cut 66=cut
67 67
68sub Compute { 68sub Compute {
69 my $string = shift; 69 my $string = shift;
78 return $formula; 78 return $formula;
79} 79}
80 80
81=head3 Context(), Context(name) or Context(context) 81=head3 Context(), Context(name) or Context(context)
82 82
83# 83 #
84# Set or get the current context. When a name is given, the context 84 # Set or get the current context. When a name is given, the context
85# with that name is selected as the current context. When a context 85 # with that name is selected as the current context. When a context
86# reference is provided, that context is set as the current one. In 86 # reference is provided, that context is set as the current one. In
87# all three cases, the current context (after setting) is returned. 87 # all three cases, the current context (after setting) is returned.
88# 88 #
89 89
90=cut 90=cut
91 91
92sub Context {Parser::Context->current(\%context,@_)} 92sub Context {Parser::Context->current(\%context,@_)}
93%context = (); # Locally defined contexts, including 'current' context 93%context = (); # Locally defined contexts, including 'current' context

Legend:
Removed from v.5372  
changed lines
  Added in v.5373

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9