[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 2576 - (download) (as text) (annotate)
Wed Aug 4 20:52:28 2004 UTC (15 years, 5 months ago) by dpvc
File size: 4715 byte(s)
Make Parser work with PGauxiliaryFunctions.pl, and add the macro files
needed to initialize the parser.

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9