[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 4990 Revision 4997
1
2
3=head1 DESCRIPTION
4
1########################################################################### 5###########################################################################
2## 6##
3## Set up the functions needed by the Parser. 7## Set up the functions needed by the Parser.
4## 8##
9
10=cut
5 11
6if (!$Parser::installed) { 12if (!$Parser::installed) {
7 die "\n************************************************************\n" . 13 die "\n************************************************************\n" .
8 "* This problem requires the Parser.pm package, which doesn't\n". 14 "* This problem requires the Parser.pm package, which doesn't\n".
9 "* seem to be installed. Please contact your WeBWorK system\n". 15 "* seem to be installed. Please contact your WeBWorK system\n".
19} 25}
20 26
21loadMacros("Value.pl"); 27loadMacros("Value.pl");
22loadMacros("PGcommonFunctions.pl"); 28loadMacros("PGcommonFunctions.pl");
23 29
30=head3 Formula("$formula")
31
24# 32#
25# The main way to get a formula 33# The main way to get a formula
26# 34#
35
36=cut
37
38
27sub Formula {Value->Package("Formula")->new(@_)} 39sub Formula {Value->Package("Formula")->new(@_)}
40
41
42
43=head3 Compute($formula,$value)
28 44
29# 45#
30# Parse a formula and evaluate it 46# Parse a formula and evaluate it
31# 47#
48
49=cut
50
32sub Compute { 51sub Compute {
33 my $string = shift; 52 my $string = shift;
34 my $formula = Formula($string); 53 my $formula = Formula($string);
35 $formula = $formula->eval(@_) if scalar(@_) || $formula->isConstant; 54 $formula = $formula->eval(@_) if scalar(@_) || $formula->isConstant;
36 $formula->{correct_ans} = $string; 55 $formula->{correct_ans} = $string;
37 return $formula; 56 return $formula;
38} 57}
39 58
59=head3 Context()
60
40# 61#
41# Deal with contexts 62# Deal with contexts
42# 63#
64
65=cut
66
43sub Context {Parser::Context->current(\%context,@_)} 67sub Context {Parser::Context->current(\%context,@_)}
44%context = (); # locally defined contexts, including 'current' context 68%context = (); # locally defined contexts, including 'current' context
45Context(); # Initialize context (for persistent mod_perl) 69Context(); # Initialize context (for persistent mod_perl)
46 70
47########################################################################### 71###########################################################################

Legend:
Removed from v.4990  
changed lines
  Added in v.4997

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9