Execute HQ9+: Difference between revisions

Content added Content deleted
No edit summary
(→‎{{header|REXX}}: added the REXX language. ~~~~)
Line 649: Line 649:


See [[RCHQ9+/Python]].
See [[RCHQ9+/Python]].

=={{header|REXX}}==
<lang rexx>
/*the HQ9+ language.*/ parse arg pgm .

do instructions=1 for length(pgm)
_=substr(pgm,instructions,1)
select
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 if symbol(accumulator)=='VAR' then accumulator=accumulator+1
otherwise say 'invalid HQ9+ instruction:' _
end /*select*/
end /*instructions*/
exit

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: if arg(1)=1 then return ''; return 's' /*a simple pluralizer.*/
</lang>
Output when using the input of:
<br><br>
H+Q
<pre style="height:40ex;overflow:scroll">
hello, world
/*the HQ9+ language.*/ parse arg pgm .

do instructions=1 for length(pgm)
_=substr(pgm,instructions,1)
select
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 if symbol(accumulator)=='VAR' then accumulator=accumulator+1
otherwise say 'invalid HQ9+ instruction:' _
end /*select*/
end /*instructions*/
exit

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: if arg(1)=1 then return ''; return 's' /*a simple pluralizer.*/
</pre>


=={{header|Ruby}}==
=={{header|Ruby}}==