Odd word problem: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: split compound statements, used a template for the output section, simplified the code.)
m (→‎{{header|REXX}}: simplified the program, changed some comments.)
Line 2,281: Line 2,281:
do until x==. /* [↓] perform until reaching a period*/
do until x==. /* [↓] perform until reaching a period*/
do until \datatype(x, 'M') /* [↓] " " punctuation found*/
do until \datatype(x, 'M') /* [↓] " " punctuation found*/
call readChar /*read a single character. */
call rChar /*read a single character. */
call writeChar /*write " " " */
call wChar /*write " " " */
end /*until \data···*/ /* [↑] read/write until punctuation. */
end /*until \data···*/ /* [↑] read/write until punctuation. */
if x==. then leave /*is this the end─of─sentence (period)?*/
if x==. then leave /*is this the end─of─sentence (period)?*/
call readLetters; punct= # /*save the location of the punctuation.*/
call readLetters; punct= # /*save the location of the punctuation.*/
do j=#-1 by -1 /*read some characters backwards. */
do j=#-1 by -1 /*read some characters backwards. */
call readChar j /*read previous word (backwards). */
call rChar j /*read previous word (backwards). */
if \datatype(x, 'M') then leave /*Found punctuation? Then leave J. */
if \datatype(x, 'M') then leave /*Found punctuation? Then leave J. */
call writeChar /*write a character (which is a letter)*/
call wChar /*write a character (which is a letter)*/
end /*j*/ /* [↑] perform for "even" words. */
end /*j*/ /* [↑] perform for "even" words. */
call readLetters /*read a letter (and maybe punctuation)*/
call rLett /*read a letter (and maybe punctuation)*/
call writeChar; #= punct /*write a char; punctuation location. */
call wChar; #= punct /*write a char; punctuation location. */
end /*until x==.*/
end /*until x==.*/
end /*case*/ /* [↑] process both of the input files*/
end /*case*/ /* [↑] process both of the input files*/
exit /*stick a fork in it, we're all done. */
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
readLetters: do until \datatype(x, 'M'); call readChar; end; return
rLett: do until \datatype(x, 'M'); call rChar; end; return
writeChar: call charout , x /*console*/; call charout oFID, x /*file*/; return
wChar: call charout , x /*console*/; call charout oFID, x /*file*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
readChar: if arg(1)=='' then do; x= charin(iFID); #= #+1; end /*read next char*/
rChar: if arg()==0 then do; x= charin(iFID); #= #+1; end /*read next char*/
else x= charin(iFID, arg(1) ) /* " specific " */
else x= charin(iFID, arg(1) ); /* " specific " */ return</lang>
return</lang>
{{out|output|text=&nbsp; when using the two (default) input files which contain:}}
{{out|output|text=&nbsp; when using the 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.IN1''' &nbsp; ───► &nbsp; <tt> what,is,the;meaning,of:life. </tt>