How to resolve the algorithm Execute HQ9+ step by step in the Seed7 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Execute HQ9+ step by step in the Seed7 programming language
Table of Contents
Problem Statement
Implement a HQ9+ interpreter or compiler.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Execute HQ9+ step by step in the Seed7 programming language
Source code in the seed7 programming language
$ include "seed7_05.s7i";
const proc: runCode (in string: code) is func
local
var char: ch is ' ';
var integer: bottles is 0;
var integer: accumulator is 0;
begin
for ch range code do
case ch of
when {'H'}: writeln("Hello, world!");
when {'Q'}: writeln(code);
when {'9'}: bottles := 99;
repeat
writeln(bottles <& " bottles of beer on the wall");
writeln(bottles <& " bottles of beer");
writeln("Take one down, pass it around");
decr(bottles);
writeln(bottles <& " bottles of beer on the wall");
writeln;
until bottles = 0;
when {'+'}: incr(accumulator);
end case;
end for;
end func;
const proc: main is func
begin
if length(argv(PROGRAM)) >= 1 then
runCode(argv(PROGRAM)[1]);
end if;
end func;
You may also check:How to resolve the algorithm Command-line arguments step by step in the min programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the XLISP programming language
You may also check:How to resolve the algorithm Filter step by step in the PHL programming language
You may also check:How to resolve the algorithm Rep-string step by step in the BQN programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Toka programming language