with simple_i, stacks; use simple_i, stacks; procedure post2 is end_of_exp : boolean := false; st : Stack; next, val : character; function ISP(x : in character) return integer is begin case x is when '^' => return(4); when '*' | '/' => return(3); when '+' | '-' => return(1); when '(' => return(0); when '.' => return(-1); when others => null; end case; end ISP; function ICP(y : in character) return integer is begin case y is when '^' => return(4); when '*' | '/' => return(3); when '+' | '-' => return(1); when '(' => return(5); when others => null; end case; end ICP; begin Push ('.', st); put("Please input the infix expression > "); while (not end_of_exp) loop get(next); case next is when '.' => while (not Empty(st)) loop put(Top(st)); Pop(st); end loop; end_of_exp := true; when '1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'0' => put(next); when ')' => while (Top(st) /= '(') loop put(Top(st)); Pop(st); end loop; Pop(st); when others => while (ISP(Top(st)) >= ICP(next)) loop put(Top(st)); Pop(st); end loop; Push(next, st); end case; end loop; end post2;