[system] / trunk / pg / lib / Parser / BOP / subtract.pm Repository:
ViewVC logotype

View of /trunk/pg/lib/Parser/BOP/subtract.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2678 - (download) (as text) (annotate)
Mon Aug 23 23:55:37 2004 UTC (15 years, 5 months ago) by dpvc
File size: 1371 byte(s)
Modified the parser so that the classes for the various object
constructors are stored in the context table rather than hard-coded
into the parser.  That way, you can override the default classes with
your own.  This gives you even more complete control to modify the
parser.  (You had been able to replace the definitions of operators,
functions and list-like objects, but could not override the behaviour
of numbers, strings, variables, and so on.  Now you can.)

This effects most of the files, but only by changing the name of the
calls that create the various objects.

There are also a couple of other minor fixes.

    1 #########################################################################
    2 #
    3 #  Implements subtraction
    4 #
    5 package Parser::BOP::subtract;
    6 use strict; use vars qw(@ISA);
    7 @ISA = qw(Parser::BOP);
    8 
    9 #
   10 #  Check that the operand types match.
   11 #
   12 sub _check {
   13   my $self = shift;
   14   return if ($self->checkStrings());
   15   return if ($self->checkLists());
   16   return if ($self->checkNumbers());
   17   my ($ltype,$rtype) = $self->promotePoints();
   18   if (Parser::Item::typeMatch($ltype,$rtype)) {$self->{type} = $ltype}
   19   else {$self->matchError($ltype,$rtype)}
   20 }
   21 
   22 #
   23 #  Do subtraction
   24 #
   25 sub _eval {$_[1] - $_[2]}
   26 
   27 #
   28 #  Remove subtracting zero
   29 #  Turn subtraction from zero into negation.
   30 #  Turn subtracting a negative into addition.
   31 #  Factor out common negatives.
   32 #
   33 sub _reduce {
   34   my $self = shift; my $equation = $self->{equation};
   35   my $parser = $equation->{context}{parser};
   36   return $self->{lop} if ($self->{rop}{isZero});
   37   return Parser::UOP::Neg($self->{rop}) if ($self->{lop}{isZero});
   38   if ($self->{rop}->isNeg) {
   39     $self = $parser->{BOP}->new($equation,'+',$self->{lop},$self->{rop}{op});
   40     $self = $self->reduce;
   41   } elsif ($self->{lop}->isNeg) {
   42     $self = Parser::UOP::Neg
   43       ($parser->{BOP}->new($equation,'+',$self->{lop}{op},$self->{rop}));
   44     $self = $self->reduce;
   45   }
   46   return $self;
   47 }
   48 
   49 #########################################################################
   50 
   51 1;
   52 

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9