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

Diff of /trunk/pg/lib/Parser.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2664 Revision 2676
136 die $message . Value::getCaller(); 136 die $message . Value::getCaller();
137} 137}
138 138
139# 139#
140# Insert an implicit multiplication 140# Insert an implicit multiplication
141# (fix up the reference for spaces or juxtaposition)
141# 142#
142sub ImplicitMult { 143sub ImplicitMult {
143 my $self = shift; 144 my $self = shift;
144 my $ref = $self->{ref}; 145 my $ref = $self->{ref}; my $iref = [@{$ref}];
146 $iref->[2]--; $iref->[3] = $iref->[2]+1;
147 $iref->[3]++ unless substr($self->{string},$iref->[2],1) eq ' ';
145 $self->Error("Can't perform implied multiplication in this context",$ref) 148 $self->Error("Can't perform implied multiplication in this context",$iref)
146 unless $self->{context}{operators}{' '}{class}; 149 unless $self->{context}{operators}{' '}{class};
147 $self->Op(' '); 150 $self->Op(' ',$iref);
148 $self->{ref} = $ref; 151 $self->{ref} = $ref;
149} 152}
150 153
151# 154#
152# Push an operator onto the expression stack. 155# Push an operator onto the expression stack.
649 652
650 653
651################################################## 654##################################################
652################################################## 655##################################################
653# 656#
654# Convert a student answer to a formula, with error trapping.
655# If the result is undef, there was an error (message is in Context()->{error} object)
656#
657
658sub Formula {
659 my $f = shift;
660 my $v = eval {Value::Formula->new($f)};
661 $$Value::context->setError($@) unless defined($v) ||
662 $$Value::context->{error}{flag};
663 return $v;
664}
665
666#
667# Evaluate a formula, with error trapping.
668# If the result is undef, there was an error (message is in Context()->{error} object)
669# If the result was a real, make it a fuzzy one.
670#
671sub Evaluate {
672 my $f = shift;
673 return unless defined($f);
674 my $v = eval {$f->eval(@_)};
675 if (defined($v)) {$v = Value::makeValue($v)}
676 else {$f->setError($@) unless $f->{context}{error}{flag}}
677 return $v;
678}
679
680
681##################################################
682##################################################
683#
684# Produce a vector in ijk form 657# Produce a vector in ijk form
685# 658#
686sub ijk { 659sub ijk {
687 my $self = shift; 660 my $self = shift;
688 $self->{tree}->ijk; 661 $self->{tree}->ijk;

Legend:
Removed from v.2664  
changed lines
  Added in v.2676

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9