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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2726 - (download) (as text) (annotate)
Sat Sep 4 20:21:32 2004 UTC (15 years, 5 months ago) by dpvc
File size: 1299 byte(s)
These files provide contexts for the Parser in which only limited
operations are allowed.  The LimitedNumeric context is analogous to
strict_num_cmp().  The other contexts are similar, but for the
indicated type of answer.  In the LimitedVector context, for example,
the student can enter vectors, and can perform numeric operations
within the coordinates of the vectors, but can't perform vector
operations like vector addition or cross product.

    1 loadMacros("Parser.pl");
    2 
    3 sub _contextLimitedNumeric_init {}; # don't load it again
    4 
    5 ##########################################################
    6 #
    7 #  Implements a context in which numbers can be entered,
    8 #  but no operations are permitted between them.
    9 #
   10 #  There are two versions:  one for lists of numbers
   11 #  and one for a single number.  Select them using
   12 #  one of the following commands:
   13 #
   14 #      Context("LimitedNumeric-list");
   15 #      Context("LimiteNumeric");
   16 #
   17 
   18 package LimitedNumeric::UOP::minus;
   19 our @ISA = qw(Parser::UOP::minus);
   20 
   21 sub _check {
   22   my $self = shift;
   23   $self->SUPER::_check;
   24   my $uop = $self->{def}{string} || $self->{uop};
   25   $self->Error("Can't use '$uop' in this context")
   26     unless $self->{op}->class eq 'Number';
   27 }
   28 
   29 package main;
   30 
   31 $context{LimitedNumeric} = Context("Numeric");
   32 $context{LimitedNumeric}->operators->set('u-' => {class => 'LimitedNumeric::UOP::minus'});
   33 $context{LimitedNumeric}->operators->undefine(
   34    '+', '-', '*', '* ', ' *', ' ', '/', '/ ', ' /', '^', '**',
   35    'U', '.', '><', 'u+', '!', '_',
   36 );
   37 $context{LimitedNumeric}->parens->undefine('|','{','(','[');
   38 Parser::Context::Functions::Disable('All');
   39 
   40 $context{'LimitedNumeric-List'} = $context{LimitedNumeric}->copy;
   41 
   42 $context{LimitedNumeric}->operators->undefine(',');
   43 
   44 Context("LimitedNumeric");

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9