Subject: | Not handling '*-1' correctly |
Date: | Fri, 19 Mar 2010 08:31:22 -0500 |
To: | bug-Math-Expression-Evaluator [...] rt.cpan.org |
From: | "Claude R. CIRBA" <c-cirba2 [...] ti.com> |
Sir,
I may not be doing the right thing, but I get a:
FATAL ERROR: Parse error: Expected Float; got: 'AddOp'
when evaluating the following expression:
(a_private - b_private)*-1*c
the -1 seems to be tokenized as AddOp '-' followed by a Float '1'
instead of Float '-1' and the evaluation fails.
In the past I changed my files to replace such instances by *(-1), but
eventually decided to try to patch it with what may not be the right
way of doing it, in Parser.pm (commented code was added):
sub _match {
my $self = shift;
my $m = shift;
my $val;
my $next = $self->_next_token();
confess("Expected $m, got EOF") unless ref $next;
if ($next->[0] eq $m){
$val = $self->_next_token()->[1];
$self->_proceed();
return $val;
# } elsif ($next->[0] eq "AddOp" && $m eq "Float") {
# # Negative Float token mis-identified as AddOp i.e. *-1 case
# # the token after that should be a Float, if it is then let's
patch things up
# # if it's not then nevermind let's fail in peace
# $val = $self->_next_token()->[1];
# $self->_proceed();
# $next = $self->_next_token();
# confess("Expected $m in modification to handle *-1, got EOF")
unless ref $next;
# if ($next->[0] eq $m){
# $val .= $self->_next_token()->[1];
# $self->_proceed();
# return $val;
# }
# else {
# $self->_expected($m, $self->_next_token()->[0]);
# }
} else {
$self->_expected($m, $self->_next_token()->[0]);
}
}
Regards,
Claude
--
Claude R. Cirba
Modeling Specialist
TDI
Ph: (214) 567-3803 (DMOS5)
Texas Instruments Inc.
PO Box 655012, M/S 365
Dallas, TX 75265
13121 TI Boulevard, M/S 365
Dallas , TX 75243