Parent Directory
|
Revision Log
Revision 3588 - (view) (download) (as text)
| 1 : | dpvc | 2576 | ########################################################################### |
| 2 : | ## | ||
| 3 : | ## Set up the functions needed by the Parser. | ||
| 4 : | ## | ||
| 5 : | |||
| 6 : | dpvc | 2602 | if (!$Parser::installed) { |
| 7 : | dpvc | 2576 | die "\n************************************************************\n" . |
| 8 : | "* This problem requires the Parser.pm package, which doesn't\n". | ||
| 9 : | "* seem to be installed. Please contact your WeBWorK system\n". | ||
| 10 : | "* administrator and ask him or her to install it first.\n". | ||
| 11 : | "************************************************************\n\n" | ||
| 12 : | } | ||
| 13 : | dpvc | 2602 | if (!$Value::installed) { |
| 14 : | die "\n************************************************************\n" . | ||
| 15 : | "* This problem requires the Value.pm package, which doesn't\n". | ||
| 16 : | "* seem to be installed. Please contact your WeBWorK system\n". | ||
| 17 : | "* administrator and ask him or her to install it first.\n". | ||
| 18 : | "************************************************************\n\n" | ||
| 19 : | } | ||
| 20 : | dpvc | 2576 | |
| 21 : | loadMacros("Value.pl"); | ||
| 22 : | loadMacros("PGcommonFunctions.pl"); | ||
| 23 : | |||
| 24 : | # | ||
| 25 : | # The main way to get a formula | ||
| 26 : | # | ||
| 27 : | dpvc | 2666 | sub Formula {Value::Formula->new(@_)} |
| 28 : | dpvc | 2576 | |
| 29 : | # | ||
| 30 : | # Parse a formula and evaluate it | ||
| 31 : | # | ||
| 32 : | sub Compute { | ||
| 33 : | dpvc | 3172 | my $string = shift; |
| 34 : | my $formula = Formula($string)->eval(@_); | ||
| 35 : | $formula->{correct_ans} = $string; | ||
| 36 : | return $formula; | ||
| 37 : | dpvc | 2576 | } |
| 38 : | |||
| 39 : | # | ||
| 40 : | # Deal with contexts | ||
| 41 : | # | ||
| 42 : | sub Context {Parser::Context->current(\%context,@_)} | ||
| 43 : | %context = (); # locally defined contexts, including 'current' context | ||
| 44 : | Context(); # Initialize context (for persistent mod_perl) | ||
| 45 : | |||
| 46 : | ########################################################################### | ||
| 47 : | # | ||
| 48 : | # stubs for trigonometric functions | ||
| 49 : | # | ||
| 50 : | |||
| 51 : | package Ignore; ## let PGauxiliaryFunctions.pl do these | ||
| 52 : | |||
| 53 : | #sub sin {Parser::Function->call('sin',@_)} # Let overload handle it | ||
| 54 : | #sub cos {Parser::Function->call('cos',@_)} # Let overload handle it | ||
| 55 : | sub tan {Parser::Function->call('tan',@_)} | ||
| 56 : | sub sec {Parser::Function->call('sec',@_)} | ||
| 57 : | sub csc {Parser::Function->call('csc',@_)} | ||
| 58 : | sub cot {Parser::Function->call('cot',@_)} | ||
| 59 : | |||
| 60 : | sub asin {Parser::Function->call('asin',@_)} | ||
| 61 : | sub acos {Parser::Function->call('acos',@_)} | ||
| 62 : | sub atan {Parser::Function->call('atan',@_)} | ||
| 63 : | sub asec {Parser::Function->call('asec',@_)} | ||
| 64 : | sub acsc {Parser::Function->call('acsc',@_)} | ||
| 65 : | sub acot {Parser::Function->call('acot',@_)} | ||
| 66 : | |||
| 67 : | sub arcsin {Parser::Function->call('asin',@_)} | ||
| 68 : | sub arccos {Parser::Function->call('acos',@_)} | ||
| 69 : | sub arctan {Parser::Function->call('atan',@_)} | ||
| 70 : | sub arcsec {Parser::Function->call('asec',@_)} | ||
| 71 : | sub arccsc {Parser::Function->call('acsc',@_)} | ||
| 72 : | sub arccot {Parser::Function->call('acot',@_)} | ||
| 73 : | |||
| 74 : | ########################################################################### | ||
| 75 : | # | ||
| 76 : | # stubs for hyperbolic functions | ||
| 77 : | # | ||
| 78 : | |||
| 79 : | sub sinh {Parser::Function->call('sinh',@_)} | ||
| 80 : | sub cosh {Parser::Function->call('cosh',@_)} | ||
| 81 : | sub tanh {Parser::Function->call('tanh',@_)} | ||
| 82 : | sub sech {Parser::Function->call('sech',@_)} | ||
| 83 : | sub csch {Parser::Function->call('csch',@_)} | ||
| 84 : | sub coth {Parser::Function->call('coth',@_)} | ||
| 85 : | |||
| 86 : | sub asinh {Parser::Function->call('asinh',@_)} | ||
| 87 : | sub acosh {Parser::Function->call('acosh',@_)} | ||
| 88 : | sub atanh {Parser::Function->call('atanh',@_)} | ||
| 89 : | sub asech {Parser::Function->call('asech',@_)} | ||
| 90 : | sub acsch {Parser::Function->call('acsch',@_)} | ||
| 91 : | sub acoth {Parser::Function->call('acoth',@_)} | ||
| 92 : | |||
| 93 : | sub arcsinh {Parser::Function->call('asinh',@_)} | ||
| 94 : | sub arccosh {Parser::Function->call('acosh',@_)} | ||
| 95 : | sub arctanh {Parser::Function->call('atanh',@_)} | ||
| 96 : | sub arcsech {Parser::Function->call('asech',@_)} | ||
| 97 : | sub arccsch {Parser::Function->call('acsch',@_)} | ||
| 98 : | sub arccoth {Parser::Function->call('acoth',@_)} | ||
| 99 : | |||
| 100 : | ########################################################################### | ||
| 101 : | # | ||
| 102 : | # stubs for numeric functions | ||
| 103 : | # | ||
| 104 : | |||
| 105 : | #sub log {Parser::Function->call('log',@_)} # Let overload handle it | ||
| 106 : | sub log10 {Parser::Function->call('log10',@_)} | ||
| 107 : | #sub exp {Parser::Function->call('exp',@_)} # Let overload handle it | ||
| 108 : | #sub sqrt {Parser::Function->call('sqrt',@_)} # Let overload handle it | ||
| 109 : | #sub abs {Parser::Function->call('abs',@_)} # Let overload handle it | ||
| 110 : | sub int {Parser::Function->call('int',@_)} | ||
| 111 : | sub sgn {Parser::Function->call('sgn',@_)} | ||
| 112 : | |||
| 113 : | sub ln {Parser::Function->call('log',@_)} | ||
| 114 : | sub logten {Parser::Function->call('log10',@_)} | ||
| 115 : | |||
| 116 : | package main; ## back to main | ||
| 117 : | |||
| 118 : | sub log10 {Parser::Function->call('log10',@_)} | ||
| 119 : | sub Factorial {Parser::UOP::factorial->call(@_)} | ||
| 120 : | |||
| 121 : | ########################################################################### | ||
| 122 : | # | ||
| 123 : | # stubs for special functions | ||
| 124 : | # | ||
| 125 : | |||
| 126 : | #sub atan2 {Parser::Function->call('atan2',@_)} # Let overload handle it | ||
| 127 : | |||
| 128 : | ########################################################################### | ||
| 129 : | # | ||
| 130 : | # stubs for numeric functions | ||
| 131 : | # | ||
| 132 : | |||
| 133 : | sub arg {Parser::Function->call('arg',@_)} | ||
| 134 : | sub mod {Parser::Function->call('mod',@_)} | ||
| 135 : | sub Re {Parser::Function->call('Re',@_)} | ||
| 136 : | sub Im {Parser::Function->call('Im',@_)} | ||
| 137 : | sub conj {Parser::Function->call('conj',@_)} | ||
| 138 : | |||
| 139 : | ########################################################################### | ||
| 140 : | # | ||
| 141 : | # stubs for vector functions | ||
| 142 : | # | ||
| 143 : | |||
| 144 : | sub norm {Parser::Function->call('norm',@_)} | ||
| 145 : | sub unit {Parser::Function->call('unit',@_)} | ||
| 146 : | |||
| 147 : | # | ||
| 148 : | # These need to be in dangerousMacros.pl for some reason | ||
| 149 : | # | ||
| 150 : | #sub i () {Compute('i')} | ||
| 151 : | #sub j () {Compute('j')} | ||
| 152 : | #sub k () {Compute('k')} | ||
| 153 : | |||
| 154 : | ########################################################################### | ||
| 155 : | |||
| 156 : | dpvc | 2602 | $_parser_loaded = 1; # use this to tell if Parser.pl is loaded |
| 157 : | |||
| 158 : | dpvc | 2644 | sub _Parser_init {}; # don't let loadMacros load it again |
| 159 : | |||
| 160 : | dpvc | 3588 | loadMacros("parserCustomization.pl"); |
| 161 : | |||
| 162 : | dpvc | 2602 | ########################################################################### |
| 163 : | |||
| 164 : | dpvc | 2576 | 1; |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |