2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 
 
 | 
 program project3;
uses StackPackageForSolveExpression,StackPackageForConvertExpression;
 
 const
 D1=['0'..'9'];
 D2 = ['-','+','*','/'];
 
 
 function Priority (Var aCh :Char):integer;
 begin
 case aCh of
 '*','/': Priority:=3;
 '+','-': Priority:=2;
 '(': Priority:=1;
 end;
 end;
 
 
 function StringToReal(StringElement: string): real;
 var
 RealResult,c: integer;
 begin
 val(StringElement,RealResult,c);
 if c<>0 then RealResult:=0;
 StringToReal:=RealResult;
 end;
 
 
 
 function ResultOfExpression(var S1: string):real;
 var
 j:integer;
 BinaryResult,a,b,IntResult :real;
 begin
 
 InitStack1;
 
 for j:=1 to Length(S1) do
 begin
 if S1[j] in D1 then
 begin
 IntResult:=StrToInt(S1[j]);
 IntStackPush(IntStack,IntResult);
 end
 else
 if S1[j] in D2 then
 begin
 a:= IntStackPop(IntStack);
 b:= IntStackPop(IntStack);
 case S1[j] of
 '+':BinaryResult:=a+b;
 '-':BinaryResult:=b-a;
 '*':BinaryResult:=a*b;
 '/':BinaryResult:=b/a;
 end;
 IntStackPush(IntStack,BinaryResult);
 end;
 end;
 with IntStack do
 begin
 ResultOfExpression:=IntData[IntTop];
 end;
 end;
 
 
 
 
 
 
 
   
   
   
   
   
 |