MODULE Dev0Interp;

	(*
		A. V. Shiryaev, 2012.10
	*)

	IMPORT Console, HostConsole (* required *), Strings, Dialog, StdInterpreter (* required (Dialog.SetCallHook) *);

	PROCEDURE WriteInt (x: INTEGER);
		VAR s: ARRAY 16 OF CHAR;
	BEGIN
		Strings.IntToString(x, s);
		Console.WriteStr(s)
	END WriteInt;

	PROCEDURE Call (VAR s: ARRAY OF CHAR): BOOLEAN;
		VAR i: INTEGER;
			res: BOOLEAN;
	BEGIN
		i := 0;
		WHILE (i < LEN(s)) & (s[i] # 0AX) & (s[i] # 0DX) & (s[i] # 0X) DO
			INC(i)
		END;
		IF (i < LEN(s)) & (s[i] # 0X) THEN
			IF (i > 0) & (s[0] # '#') THEN
				s[i] := 0X;
				Dialog.Call(s, "", i);
				IF i = 0 THEN
					res := TRUE
				ELSE
					WriteInt(i); Console.WriteLn;
					res := FALSE (* stop on Dialog.Call error *)
				END
			ELSE (* skip empty strings and comments *)
				res := TRUE
			END
		ELSE (* end of input *)
			res := FALSE
		END;
	RETURN res
	END Call;

	PROCEDURE Init;
		VAR s: ARRAY 1024 OF CHAR;
	BEGIN
		Console.ReadLn(s);
		WHILE Call(s) DO
			Console.ReadLn(s)
		END
	END Init;

BEGIN
	Init
END Dev0Interp.
