Execute HQ9+: Difference between revisions
Content deleted Content added
m added whitespace before the TOC (table of contents), added whitespace around al link. |
m →{{header|REXX}}: changed/added comments and whitespace, changed indentations, added comment in the REXX section header. |
||
Line 1,313: | Line 1,313: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Note that the actual text of the ''Hello, world!'' message can differ among definitions. |
|||
<lang rexx>/*REXX program to implement the HQ9+ language.*/ parse arg pgm . |
|||
<lang rexx>/*REXX program implements the HQ9+ language. ───────────────────────────────────────*/ |
|||
accumulator=0 |
|||
arg pgm . /*obtain optional argument.*/ |
|||
do instructions=1 for length(pgm); ?=substr(pgm,instructions,1) |
|||
⚫ | |||
⚫ | |||
when ?=='H' then say "hello, world" /*this salutation varies. */ |
|||
do instructions=1 for length(pgm); ?=substr(pgm, instructions, 1) |
|||
select |
|||
when ?==' |
when ?=='H' then say "Hello, world!" /*text varies on definition*/ |
||
⚫ | |||
⚫ | |||
when ?== 9 then call 99 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
/*──────────────────────────────────99 subroutine───────────────────────*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
n=j-1 |
|||
say j 'bottle's(j) "of beer." |
|||
⚫ | |||
⚫ | |||
n=j-1 |
|||
if n==0 then n='no' /*cheating to use 0. */ |
|||
end |
|||
⚫ | |||
say 'No more bottles of beer on the wall,' /*finally, last verse.*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
say ' |
say 'No more bottles of beer on the wall,' /*finally, last verse.*/ |
||
⚫ | |||
⚫ | |||
⚫ | |||
/*──────────────────────────────────S subroutine────────────────────────*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
<pre style="height:40ex"> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
/*REXX program to implement the HQ9+ language.*/ parse arg pgm . |
|||
<pre> |
|||
accumulator=0 |
|||
⚫ | |||
do instructions=1 for length(pgm); ?=substr(pgm,instructions,1) |
|||
Hello, world! |
|||
⚫ | |||
Hello, world! |
|||
when ?=='H' then say "hello, world" |
|||
⚫ | |||
when ?== 9 then call 99 |
|||
⚫ | |||
otherwise say 'invalid HQ9+ instruction:' ? |
|||
⚫ | |||
end /*instructions*/ |
|||
exit /*stick a fork in it, we're done.*/ |
|||
/*──────────────────────────────────99 subroutine───────────────────────*/ |
|||
99: do j=99 by -1 to 1 |
|||
say j 'bottle's(j) "of beer the wall," |
|||
say j 'bottle's(j) "of beer." |
|||
say 'Take one down, pass it around,' |
|||
n=j-1 |
|||
⚫ | |||
say n 'bottle's(j-1) "of beer the wall." |
|||
say |
|||
end |
|||
say 'No more bottles of beer on the wall,' /*finally, last verse.*/ |
|||
say 'no more bottles of beer.' |
|||
say 'Go to the store and buy some more,' |
|||
say '99 bottles of beer on the wall.' |
|||
return |
|||
/*──────────────────────────────────S subroutine────────────────────────*/ |
|||
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer.*/ |
|||
</pre> |
</pre> |
||