![]() # add a space to terminate the final token and an expression terminator # Print( ( "Result is: ", fixed( stack, 12, 8 ), newline ) ) # push the new value on the stack and show the new stack # Print( ( "Unknown operator: """ + op + """", newline ) ) IF rpn expression = end of expression character # evaluate tokens from the expression until we get the end of expression # PROC evaluate = ( STRING rpn expression )VOID: # evaluates the specified rpn expression # # the right-hand operand for ^ is converted to an integer #ĬHAR end of expression character = REPR 12 ![]() # RPN Expression evaluator - handles numbers and + - * / ^ # Last_Element, Aft => 5, Exp => 0 ) end RPN_Calculator Element ( I ), Aft => 5, Exp => 0 ) end loop Ada. Append ( X ** Integer ( Float ' Rounding ( Y ))) when others => raise Program_Error with "unecpected token '" & Input ( Cursor ) & "' at column" & Integer ' Image ( Cursor ) end case Cursor := New_Cursor end for I in Stack. Delete_Last - from the stack case Input ( Cursor ) is when '+' => Stack. Delete_Last - pick two elements X := Stack. Append ( Value ) Cursor := New_Cursor exception - if reading the number fails, try to read an operator token when others => Y := Stack. New_Cursor - 1 ), Item => Value, Last => Last ) Stack. Get_Line Cursor : Positive := Input ' First New_Cursor : Positive begin loop - read spaces while Cursor Input ' Last New_Cursor := Cursor while New_Cursor Input ( Cursor. Vectors procedure RPN_Calculator is package IIO is new Ada.Text_IO.Float_IO (Float ) package Float_Vec is new ( Index_Type => Positive, Element_Type => Float ) Stack : Float_Vec. INCLUDE "D2:REAL.ACT" from the Action! Tool KitīYTE FUNC GetToken(CHAR ARRAY s BYTE start CHAR ARRAY t) LM R14,R12,12(R13) restore previous context L R13,4(0,R13) restore previous savearea pointer ![]() L R0,STACK-4(R4) r0=stack(j) ĮXPONENT M R2,STACK-8(R4) r3=r3*stack(j-1)īCT R0,EXPONENT if r0-0 then goto exponent LA R7,TEXT CC,0(R7) cc first char of tokenĭO WHILE=(CLI,CC,NE,X'00') do while cc'0'x STM R14,R12,12(R13) save previous context So I will put 2 into a cell->data, 5 into the cell->next->data, and then I put all the cell into the cell used in the structure number, and push the structure number into the stack. Then it push the number before the space into the stack ! }įor example StrIn=2 STrIn=5 strIn=(space) *Here I want to write the code that reads the string untill it finds a space , The problem is I do not know how to separate the numbers from the string when it reads a space. In the example above, when I write 25 35 +, I have to stock the 25 as a number and push it into the stack, and do the same with the 35, and when the operator is read, I do the operation calling 2 pops. The idea is I have to write an input string, like ( 25 35 + ), and display the result using linked lists. I was asked to do an RPN calculator using linked lists. I have an assignment due to tomorrow and I have just started it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |