[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 4990 - (download) (as text) (annotate)
Thu Jun 7 23:48:20 2007 UTC (12 years, 7 months ago) by dpvc
File size: 5480 byte(s)
More updates to use the new Value->Package() call.  This will make the
standard object-creation functions like Real() and Complex() use the
new lookup method.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9