Execute HQ9+: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed indentation, added/changed comments. -- ~~~~)
Line 712:
 
=={{header|REXX}}==
<lang rexx>/*REXX program to implement the HQ9+ language.*/ parse arg pgm .
accumulator=0
 
do instructions=1 for length(pgm); ?=substr(pgm,instructions,1)
select
_=substr(pgm,instructions,1)
when ?=='H' then say "hello, world"
select
when _?=='HQ' then do j=1 for sourceline(); say "hello,sourceline(j); world"end
when _?=='Q' then9 do j=1then forcall sourceline()99
when ?=='+' then say sourceline(j)accumulator=accumulator+1
otherwise say 'invalid HQ9+ instruction:' end?
when _==9 thenend call 99 /*select*/
_=substr(pgm, end /*instructions,1)*/
when _=='+' then if symbol(accumulator)=='VAR' then accumulator=accumulator+1
exit /*stick a fork in it, we're done.*/
otherwise say 'invalid HQ9+ instruction:' _
/*──────────────────────────────────99 subroutine───────────────────────*/
end /*select*/
end /*instructions*/
exit
/*─────────────────────────────────────99 subroutine────────────────────*/
99: do j=99 by -1 to 1
say j 'bottle's(j) "of beer the wall,"
Line 742 ⟶ 739:
say '99 bottles of beer on the wall.'
return
/*──────────────────────────────────S subroutine────────────────────────*/
/*─────────────────────────────────────S subroutine─────────────────────*/
s: if arg(1)==1 then return ''; return '"s' " /*a simple pluralizer.*/</lang>
'''output''' when using the input of: <tt> H+Q </tt>
<pre style="height:40ex;overflow:scroll">
hello, world
/*REXX program to implement the HQ9+ language.*/ parse arg pgm .
accumulator=0
 
do instructions=1 for length(pgm); ?=substr(pgm,instructions,1)
end /*select*/
_=substr(pgm,instructions,1)
when ?=='H' then say "hello, world"
select
when _?=='HQ' then do j=1 for sourceline(); say "hello,sourceline(j); world"end
when _?=='Q' then9 do j=1then forcall sourceline()99
when ?=='+' then say sourceline(j)accumulator=accumulator+1
otherwise say 'invalid HQ9+ instruction:' end?
when _==9 thenend call 99 /*select*/
end end /*instructions*/
when _=='+' then if symbol(accumulator)=='VAR' then accumulator=accumulator+1
exit /*stick a fork in it, we're done.*/
otherwise say 'invalid HQ9+ instruction:' _
/*──────────────────────────────────99 subroutine───────────────────────*/
end /*select*/
end /*instructions*/
exit
/*─────────────────────────────────────99 subroutine────────────────────*/
99: do j=99 by -1 to 1
say j 'bottle's(j) "of beer the wall,"
Line 777 ⟶ 771:
say '99 bottles of beer on the wall.'
return
/*──────────────────────────────────S subroutine────────────────────────*/
/*─────────────────────────────────────S subroutine─────────────────────*/
s: if arg(1)==1 then return ''; return '"s' " /*a simple pluralizer.*/
</pre>