RosettaCodeData/Task/Range-expansion/XPL0/range-expansion.xpl0
2023-07-01 13:44:08 -04:00

22 lines
586 B
Text

proc Expand(Range);
char Range;
int Lo, Hi, N;
[Text(8, Range);
loop [Lo:= IntIn(8);
BackUp; \get what terminated number
case ChIn(8) of
^-: [Hi:= IntIn(8);
for N:= Lo to Hi do
[IntOut(0, N);
if N < Hi then Text(0, ", ");
];
BackUp;
if ChIn(8) = $1A \EOF\ then quit;
];
^,: IntOut(0, Lo)
other \EOF\ [IntOut(0, Lo); quit];
Text(0, ", ");
];
];
Expand("-6,-3--1,3-5,7-11,14,15,17-20")