Execute HQ9+: Difference between revisions

m
→‎{{header|REXX}}: changed/added comments and whitespace, changed indentations, added comment in the REXX section header.
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:
 
=={{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)
accumulator=0 if n==0 then n='no' /*cheatingassign default to use 0accum. */
select
 
when ?=='H' then say "hello, world" /*this salutation varies. */
when ?=='Q' then do jinstructions=1 for sourcelinelength(pgm); say sourceline ?=substr(j);pgm, instructions, end1)
when ?== 9 then call 99select
when ?=='+H' then accumulator=accumulator+1say "Hello, world!" /*text varies on definition*/
when ?=='Q' then do j=1 for sourceline(); say sourceline(j); end /*j*/
otherwise say 'invalid HQ9+ instruction:' ?
end /*select*/when ?== 9 then call 99
when ?=='+' then accumulator=accumulator+1
end /*instructions*/
otherwise say 'invalid HQ9+ instruction:' ?
exit /*stick a fork in it, we're done.*/
end /*select*/
/*──────────────────────────────────99 subroutine───────────────────────*/
end /*instructions*/
99: do j=99 by -1 to 1
exit /*stick a fork in it, we're all done. */
say j 'bottle's(j) "of beer the wall,"
/*──────────────────────────────────────────────────────────────────────────────────────*/
say j 'bottle's(j) "of beer."
99: do j=99 by -1 to 1
say 'Take one down, pass it around,'
say j 'bottle's(j) "of beer the wall,"
n=j-1
if n==0 then n='no' say j 'bottle's(j) "of /*cheating to use 0beer. */"
say 'Take one down, pass it around,'
say n 'bottle's(j-1) "of beer the wall."
say n=j-1
if n==0 then n='no' /*cheating to use 0. */
end
say jn 'bottle's(j-1) "of beer the wall."
say 'No more bottles of beer on the wall,' /*finally, last verse.*/
select say
say 'no more bottles of beer.'
end /*selectj*/
say 'Go to the store and buy some more,'
say '99No more bottles of beer on the wall.,' /*finally, last verse.*/
say 'no more bottles of beer.'
return
say 'Go to the store and buy some more,'
/*──────────────────────────────────S subroutine────────────────────────*/
say n 'bottle's(j-1)99 bottles "of beer on the wall."'
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer.*/</lang>
return
'''output''' when using the input of: <tt> H+Q </tt>
/*──────────────────────────────────────────────────────────────────────────────────────*/
<pre style="height:40ex">
s: if arg(1)==1 then return ''; return "s" /*a simple pluralizer.*/</lang>
hello, world
'''output''' &nbsp; when using the input of: &nbsp; <tt> H+QHHH </tt>
/*REXX program to implement the HQ9+ language.*/ parse arg pgm .
<pre>
accumulator=0
helloHello, world!
do instructions=1 for length(pgm); ?=substr(pgm,instructions,1)
Hello, world!
select
Hello, world!
when ?=='H' then say "hello, world"
when ?=='Q' then do j=1 for sourceline(); say sourceline(j); end
when ?== 9 then call 99
when ?=='+' then accumulator=accumulator+1
otherwise say 'invalid HQ9+ instruction:' ?
end /*select*/
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
if n==0 then n='no' /*cheating to use 0. */
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>