Files
gnatstudio/examples/tutorial/struct/instructions.adb
Pascal Obry 9478d269f2 Fix file permissions.
git-svn-id: svn+ssh://svn.eu/Dev/trunk/gps@131475 936e1b1b-40f2-da11-902a-00137254ae57
2008-10-25 14:18:11 +00:00

60 lines
1.3 KiB
Ada

with Except;
with Screen_Output;
with Stack;
with Values;
package body Instructions is
----------
-- Read --
----------
function Read (Word : String) return Instruction is
begin
-- Loop through each instruction asking if its string representation
-- matches the word we have just encountered in the input.
for I in Instruction loop
-- Technical Note: Given a scalar type (such as an integer, an
-- enumeration, etc), Type'Image (X) returns the value of X
-- converted to a string.
if Instruction'Image (I) = Word then
return I;
end if;
end loop;
-- If we have found an unrecognized instruction raise an exception.
raise Except.User_Error;
end Read;
-------------
-- Process --
-------------
procedure Process (I : Instruction) is
begin
case I is
when Clear =>
Stack.Clear;
when Print =>
Screen_Output.Msg (" -> ", End_Line => False);
if Stack.Empty then
Screen_Output.Msg ("stack is empty");
else
Screen_Output.Msg (Values.To_String (Stack.Top));
end if;
when Quit =>
raise Except.Exit_SDC;
end case;
end Process;
end Instructions;