* fixed bug 42

This commit is contained in:
peter 1998-08-18 20:51:32 +00:00
parent d72ca253fe
commit df5ca5be09

View File

@ -451,6 +451,7 @@ begin
end; end;
end; end;
Function TExprParse.Evaluate(Expr : String):longint; Function TExprParse.Evaluate(Expr : String):longint;
Var Var
I : Integer; I : Integer;
@ -462,7 +463,7 @@ begin
Token := ''; Token := '';
For I := 1 to Length(Expr) DO For I := 1 to Length(Expr) DO
begin
if Expr[I] in ['0'..'9'] then if Expr[I] in ['0'..'9'] then
begin { Build multi-digit numbers } begin { Build multi-digit numbers }
Token := Token + Expr[I]; Token := Token + Expr[I];
@ -480,8 +481,7 @@ begin
Case Expr[I] OF Case Expr[I] OF
'(' : OpPush('(',false); '(' : OpPush('(',false);
')' : ')' : begin
begin
While OpStack[OpTop].ch <> '(' DO While OpStack[OpTop].ch <> '(' DO
Begin Begin
OpPop(opr); OpPop(opr);
@ -489,33 +489,32 @@ begin
end; end;
OpPop(opr); { Pop off and ignore the '(' } OpPop(opr); { Pop off and ignore the '(' }
end; end;
'+','-','~' : Begin '+','-','~' : Begin
While (OpTop > 0) AND
(Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO
Begin
OpPop(opr);
RPNCalc(opr.ch,opr.is_prefix);
end;
{ if start of expression then surely a prefix }
{ or if previous char was also an operator }
{ push it and don't evaluate normally }
{ workaround for -2147483648 } { workaround for -2147483648 }
if (expr[I]='-') and (expr[i+1] in ['0'..'9']) then if (expr[I]='-') and (expr[i+1] in ['0'..'9']) then
begin begin
token:='-'; token:='-';
expr[i]:='+'; expr[i]:='+';
end; end;
{ if start of expression then surely a prefix }
{ or if previous char was also an operator }
if (I = 1) or (not (Expr[I-1] in ['0'..'9','(',')'])) then if (I = 1) or (not (Expr[I-1] in ['0'..'9','(',')'])) then
OpPush(Expr[I],true) OpPush(Expr[I],true)
else else
OpPush(Expr[I],false); Begin
{ Evaluate all higher priority operators }
While (OpTop > 0) AND (Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO
Begin
OpPop(opr);
RPNCalc(opr.ch,opr.is_prefix);
end; end;
OpPush(Expr[I],false);
'*', '/','^','|','&','%','<','>' : End;
begin end;
While (OpTop > 0) AND '*', '/',
(Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO '^','|','&',
'%','<','>' : begin
While (OpTop > 0) and (Priority(Expr[I]) <= Priority(OpStack[OpTop].ch)) DO
Begin Begin
OpPop(opr); OpPop(opr);
RPNCalc(opr.ch,opr.is_prefix); RPNCalc(opr.ch,opr.is_prefix);
@ -524,10 +523,12 @@ begin
end; end;
end; { Case } end; { Case }
end end
else Error(invalid_op); else
{ Handle bad input error } Error(invalid_op); { Handle bad input error }
end;
While OpTop > 0 do { Pop off the remaining operators } { Pop off the remaining operators }
While OpTop > 0 do
Begin Begin
OpPop(opr); OpPop(opr);
RPNCalc(opr.ch,opr.is_prefix); RPNCalc(opr.ch,opr.is_prefix);
@ -1628,7 +1629,10 @@ end;
end. end.
{ {
$Log$ $Log$
Revision 1.6 1998-08-10 14:49:40 peter Revision 1.7 1998-08-18 20:51:32 peter
* fixed bug 42
Revision 1.6 1998/08/10 14:49:40 peter
+ localswitches, moduleswitches, globalswitches splitting + localswitches, moduleswitches, globalswitches splitting
Revision 1.5 1998/07/14 21:46:38 peter Revision 1.5 1998/07/14 21:46:38 peter