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