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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4997 - (download) (as text) (annotate)
Mon Jun 11 18:16:40 2007 UTC (12 years, 8 months ago) by gage
File size: 5611 byte(s)
Fixing docementation so that it can be read from the web.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9