-- file REP.adb 2:44PM 10/25/95 -- just defines procedure REP, a read-eval-print loop for expressions, -- that takes optional parameters specifying input and output files. -- In Ada95, that means two versions of the procedure must be defined, one -- with two parameters, and without. with evaluate, text_io; use evaluate, text_io; procedure REP is InFileName, OutFileName : String(1..8):= " "; yes : String(1..70); OldIn : File_Type renames Current_Input; OldOut : File_Type renames Current_Output; NewIn, NewOut : File_Type; N: Natural; begin put( " would you like me to go to a file for input? "); get_line(Yes, N); if Yes(1) = 'y' or Yes(1) = 'Y' then put(" please supply input filename (at most 8 characters): "); N:= 1; get(InFileName(N)); while not (End_Of_Line or InFileName(N)=' ' or N=8) loop N := N+1; get(InFileName(N)); end loop; new_line; put(" please supply output filename (at most 8 characters): "); N := 1; get(OutFileName(N)); while not (End_Of_Line or OutFileName(N)=' ' or N=8) loop N := N+1; get(OutFileName(N)); end loop; open(NewIn, In_File, InFileName); set_input(NewIn); create(NewOut, Out_File, OutFileName); set_output(NewOut); else put_line("please type expression to be evaluated, remember that ALL"); put_line("tokens must be separated by spaces --- extremely dumb scanner,"); put_line(" and variable lookups are case sensitive. "); end if; driver; if Yes(1) = 'y' or Yes(1) = 'Y' then set_input(OldIn); set_output(OldOut); close(NewIn); close(NewOut); end if; end REP;