with ada.text_io; with ada.integer_text_io; with stack; procedure program4_V1 is -- need a blank line to initialize & reinitialize strings blank_line : CONSTANT String(1..80) := (OTHERS => ' '); blank : CONSTANT character := ' '; infix_String : String (1..80); -- original string in infix form postfix_String : String (1..80); -- result string in postfix form last_in : integer; -- to indicate position of last character in input string done : boolean := false; -- will indicate when processing input string is complete -- instantiation of a stack to hold the characters package Character_Stack is new Stack (Element_Type => Character); myStack : Character_Stack.Stack_Type (Max_Size => 50); -- to hold operators and parentheses from input string begin loop -- program will handle multiple strings -- code for a single string -- initialize strings to all blanks so as not to have any old characters in it -- prompt user for a string in infix form -- get string from user -- echo the infix string with a label -- initialize empty stack -- while not entire string processed while not done loop -- while more characters in infix string -- OTHER KIND OF LOOP? -- get a character from the infix string -- if it's a blank ignore it -- else if it's alphabetic add it to the postfix string followed by a blank -- else if it's a left parenthesis, put it on stack -- else if it is a right parenthesis, pop the stack and append each of the -- OPERATORS on it, to the postfix string followed by a blank. Stop -- popping the stack after popping a left parenthesis. -- else if it's an operator loop -- pop operators from the stack and append them null; -- to the postfix string followed by a blank UNTIL -- 1. the stack is empty -- 2. an operator of lower priority than the operator is found -- 3. a left parenthesis is found -- push 2 OR 3 back to the stack followed by operator end loop; -- when operator pushed on stack end loop; -- leave loop when no more characters in input string -- pop rest of stack a character at a time and append each followed -- by a blank to postfix string -- print the postfix string with a label end loop; -- for line 21 -- print ending message (i.e. Program has processed all the input data) end program4_V1;