2015-03-15 22:56:09 +03:00
|
|
|
with Ada.Text_IO;
|
|
|
|
with Ada.IO_Exceptions;
|
|
|
|
with Printer;
|
|
|
|
with Reader;
|
|
|
|
with Types;
|
|
|
|
|
|
|
|
procedure Step1_Read_Print is
|
|
|
|
|
2015-04-03 16:35:24 +03:00
|
|
|
function Read (Param : String) return Types.Mal_Handle is
|
2015-03-15 22:56:09 +03:00
|
|
|
begin
|
|
|
|
return Reader.Read_Str (Param);
|
|
|
|
end Read;
|
|
|
|
|
2015-04-03 16:35:24 +03:00
|
|
|
function Eval (Param : Types.Mal_Handle) return Types.Mal_Handle is
|
2015-03-15 22:56:09 +03:00
|
|
|
begin
|
|
|
|
return Param;
|
|
|
|
end Eval;
|
|
|
|
|
2015-04-03 16:35:24 +03:00
|
|
|
function Print (Param : Types.Mal_Handle) return String is
|
2015-03-15 22:56:09 +03:00
|
|
|
begin
|
|
|
|
return Printer.Pr_Str (Param);
|
|
|
|
end Print;
|
|
|
|
|
|
|
|
function Rep (Param : String) return String is
|
2016-03-15 11:05:20 +03:00
|
|
|
AST, Evaluated_AST : Types.Mal_Handle;
|
2015-03-15 22:56:09 +03:00
|
|
|
begin
|
2015-03-19 00:12:54 +03:00
|
|
|
|
2016-03-15 11:05:20 +03:00
|
|
|
AST := Read (Param);
|
2015-03-19 00:12:54 +03:00
|
|
|
|
2016-03-15 11:05:20 +03:00
|
|
|
if Types.Is_Null (AST) then
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
Evaluated_AST := Eval (AST);
|
|
|
|
return Print (Evaluated_AST);
|
|
|
|
end if;
|
2015-03-19 00:12:54 +03:00
|
|
|
|
2015-03-15 22:56:09 +03:00
|
|
|
end Rep;
|
|
|
|
|
2015-03-19 00:12:54 +03:00
|
|
|
S : String (1..Reader.Max_Line_Len);
|
2015-03-15 22:56:09 +03:00
|
|
|
Last : Natural;
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
loop
|
|
|
|
Ada.Text_IO.Put ("user> ");
|
|
|
|
Ada.Text_IO.Get_Line (S, Last);
|
2015-03-19 00:12:54 +03:00
|
|
|
Ada.Text_IO.Put_Line (Rep (S (1..Last)));
|
2015-03-15 22:56:09 +03:00
|
|
|
end loop;
|
|
|
|
|
|
|
|
exception
|
|
|
|
when Ada.IO_Exceptions.End_Error => null;
|
|
|
|
-- i.e. exit without textual output
|
|
|
|
end Step1_Read_Print;
|