[system] / trunk / pg / lib / Parser / Context / Variables.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/Context/Variables.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2622 - (download) (as text) (annotate)
Sun Aug 15 22:46:57 2004 UTC (15 years, 5 months ago) by dpvc
File size: 1640 byte(s)
Created the first draft of the Parser's function answer checker.  Some
work still needs to be done, in particular, type mismatches are not
being reported, and lists are being processed only as ordered lists
with no partial credit.

This doesn't implement everything from fun_cmp.  In particular, there
is no support for parameter matching at the moment.  This will have to
be added, but I'm not quite sure how to do it when the function's
return value is not a real number (e.g., an interval).

On the other hand, this checker is more forgiving about domain errors:
if tries a point where the professor's function is not defined, it
ignores that one and looks for another (until it decides it can't find
one).  Once it has these points, it tries them on the student's
answer, and if the student's function is undefined, then the student
answer is wrong (since it is not defined somewhere that the
professor's funciton is).  This avoids the "Error evaluating student
function at ..." messages, which just confused most students anyway.

    1 #########################################################################
    2 #
    3 #  Implements the list of known variables and their types
    4 #
    5 package Parser::Context::Variables;
    6 use strict;
    7 use vars qw(@ISA %type);
    8 @ISA = qw(Value::Context::Data);
    9 
   10 #
   11 #  The types that variables can be
   12 #  @@@ Should also include domain ranges for when
   13 #      we use these in answer checkers @@@
   14 #
   15 %type = (
   16   'Real'    => $Value::Type{number},
   17   'Complex' => $Value::Type{complex},
   18 );
   19 
   20 sub init {
   21   my $self = shift;
   22   $self->{dataName} = 'variables';
   23   $self->{name} = 'variable';
   24   $self->{Name} = 'Variable';
   25   $self->{namePattern} = '[a-zA-Z]';
   26 }
   27 
   28 #
   29 #  Our pattern should match ANY variable name
   30 #    (Parser takes care of reporting unknown ones)
   31 #
   32 sub update {
   33   my $self = shift;
   34   $self->{pattern} = $self->{namePattern};
   35 }
   36 
   37 #
   38 #  If the type is one of the names ones, use it's known type
   39 #  Otherwise if it is a Value object use its type,
   40 #  Otherwise, if it is a signed number, use the Real type
   41 #  Otherwise report an error
   42 #
   43 sub create {
   44   my $self = shift; my $value = shift;
   45   return $value if ref($value) eq 'HASH';
   46   if (defined($type{$value})) {
   47     $value = $type{$value};
   48   } elsif (Value::isValue($value)) {
   49     $value = $value->typeRef;
   50   } elsif ($value =~ m/$self->{context}{pattern}{signedNumber}/) {
   51     $value = $type{'Real'};
   52   } else {
   53     Value::Error("Unrecognized variable type '$value'");
   54   }
   55   return {type => $value};
   56 }
   57 
   58 #
   59 #  Return a variable's type
   60 #
   61 sub type {
   62   my $self = shift; my $x = shift;
   63   return $self->{context}{variables}{$x}{type};
   64 }
   65 
   66 #########################################################################
   67 
   68 1;
   69 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9