Execute HQ9+/Ada: Difference between revisions
Content added Content deleted
(Created page with "{{implementation|HQ9+}}{{collection|RCHQ9+}} the language specs of HQ9+ don't tell what is meant by "accumulator". therefore it is not possible to tell if it is implemented ...") |
(Implemented Accumulator) |
||
Line 1: | Line 1: | ||
{{implementation|HQ9+}}{{collection|RCHQ9+}} |
{{implementation|HQ9+}}{{collection|RCHQ9+}} |
||
the language specs of [[HQ9+]] don't tell what is meant by "accumulator". therefore it is not possible to tell if it is implemented correctly. |
|||
<lang Ada>with Ada.Text_IO; |
<lang Ada>with Ada.Text_IO; |
||
Line 18: | Line 16: | ||
procedure Interpret_HQ9Plus (Input : in String) is |
procedure Interpret_HQ9Plus (Input : in String) is |
||
Accumulator : Natural := 0; |
|||
begin |
begin |
||
for I in Input'Range loop |
for I in Input'Range loop |
||
Line 28: | Line 27: | ||
Bottles; |
Bottles; |
||
when '+' => |
when '+' => |
||
Accumulator := Accumulator + 1; |
|||
null; |
|||
when others => |
when others => |
||
null; |
null; |
Revision as of 12:55, 4 January 2017
Execute HQ9+/Ada is an implementation of HQ9+.
Other implementations of HQ9+.
Execute HQ9+/Ada is part of RCHQ9+. You may find other members of RCHQ9+ at Category:RCHQ9+.
<lang Ada>with Ada.Text_IO; procedure HQ9Plus is
-- took example from bottle-task procedure Bottles is begin for X in reverse 1..99 loop Ada.Text_IO.Put_Line(Integer'Image(X) & " bottles of beer on the wall"); Ada.Text_IO.Put_Line(Integer'Image(X) & " bottles of beer"); Ada.Text_IO.Put_Line("Take one down, pass it around"); Ada.Text_IO.Put_Line(Integer'Image(X - 1) & " bottles of beer on the wall"); Ada.Text_IO.New_Line; end loop; end Bottles;
procedure Interpret_HQ9Plus (Input : in String) is Accumulator : Natural := 0; begin for I in Input'Range loop case Input (I) is when 'H'|'h' => Ada.Text_IO.Put_Line ("Hello, World!"); when 'Q'|'q' => Ada.Text_IO.Put_Line (Input); when '9' => Bottles; when '+' => Accumulator := Accumulator + 1; when others => null; end case; end loop; end Interpret_HQ9Plus;
Test_Code : String := "hq9+HqQ+Qq";
begin
Interpret_HQ9Plus (Test_Code);
end HQ9Plus;</lang>