Reverse words in a string: Difference between revisions

Added XPL0 example.
m (→‎{{header|Phix}}: syntax coloured)
(Added XPL0 example.)
Line 4,003:
... last paragraph elided ...
 
----------------------- Robert Frost
</pre>
 
=={{header|XPL0}}==
<lang XPL0>string 0;
def LF=$0A, CR=$0D;
 
proc Reverse(Str, Len); \Reverse order of chars in string
char Str; int Len;
int I, J, T;
[I:= 0;
J:= Len-1;
while I < J do
[T:= Str(I); Str(I):= Str(J); Str(J):= T;
I:= I+1; J:= J-1;
];
];
 
char Str;
int I, LineBase, WordBase;
[Str:=
"---------- Ice and Fire ------------
fire, in end will world the say Some
ice. in say Some
desire of tasted I've what From
fire. favor who those with hold I
... elided paragraph last ...
Frost Robert -----------------------";
I:= 0;
repeat LineBase:= I;
loop [WordBase:= I;
repeat I:= I+1 until Str(I) <= $20;
Reverse(@Str(WordBase), I-WordBase);
if Str(I)=CR or Str(I)=LF or Str(I)=0 then quit;
I:= I+1; \skip space
];
Reverse(@Str(LineBase), I-LineBase);
while Str(I)=CR or Str(I)=LF do I:= I+1;
until Str(I) = 0;
Text(0, Str);
CrLf(0);
]</lang>
 
{{out}}
<pre>
------------ Fire and Ice ----------
Some say the world will end in fire,
Some say in ice.
From what I've tasted of desire
I hold with those who favor fire.
... last paragraph elided ...
----------------------- Robert Frost
</pre>
772

edits