Odd word problem: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.
m (added whitespace before the TOC (table of contents), added other whitespace to the task's preamble.)
m (→‎{{header|REXX}}: added/changed comments and whitespace, changed indentations.)
Line 1,718:
 
No recursion or the stack is used.   The program could've been written without subroutines.
<lang rexx>/*REXX program solves the odd word problem by only using byte input/output. */
iFID_ = 'ODDWORD.IN' /*Note: numeric suffix is added later.*/
oFID_ = 'ODDWORD.' /* " " " " " " */
 
do case=1 for 2; #=0 /*#: is the number of characters read.*/
iFID=iFID_ || case /*read ODDWORD.IN1 or ODDWORD.IN2 */
oFID=oFID_ || case /*write ODDWORD.1 o r ODDWORD.2 */
say; say; say '════════ reading file: ' iFID "════════"
 
do until x==. /* [↓] perform DO loop for odd words.*/
do until \isMix(x); call readChar; call writeChar; end
if x==. then leave end /*is this end─of─sentence? until ¬isMix(full stopx)*/
if x==. then leave /*is this end─of─sentence? (full stop)*/
call readLetters; punctuation_location=#
do j=#-1 by -1; call readChar j
if \isMix(x) then leave; call writeChar
end /*j*/ /* [↑] perform for the "even" words.*/
call readLetters; call writeChar; #=punctuation_location
end /*until x ···*/
end /*case*/ /* [↑] process both of the input files*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────one─liner subroutines─────────────────────*/
isMix: return datatype(arg(1),'M') /*return 1 if argargument is a letter.*/
readLetters: do until \isMix(x); call readChar; end; return
writeChar: call charout ,x; call charout oFID,x; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────readChar subroutine───────────────────────*/
readChar\eadChar: if arg(1)=='' then do; x=charin(iFID); #=#+1; end /*read next char*/
else x=charin(iFID, arg(1)) /* " specific "*/
return</lang>
'''output''' &nbsp; when using two (default) input files which contain:
:* &nbsp; input file &nbsp; '''ODDWORD.IN1''' &nbsp; ───► &nbsp; <tt> what,is,the;meaning,of:life. </tt>
:* &nbsp; input file &nbsp; '''ODDWORD.IN2''' &nbsp; ───► &nbsp; <tt> we,are;not,in,kansas;any,more. </tt>