RosettaCodeData/Task/Range-expansion/XPL0/range-expansion.xpl0
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

42 lines
1.1 KiB
Text

include c:\cxpl\codes; \intrinsic 'code' declarations
string 0; \use zero-terminated strings, instead of MSb
char Str;
int Char, Inx;
proc GetCh; \Get character from Str
[Char:= Str(Inx);
Inx:= Inx+1;
]; \GetCh
func GetNum; \Get number from Str and return its value
int Neg, Num;
[Neg:= false;
if Char = ^- then [Neg:= true; GetCh];
Num:= 0;
while Char>=^0 & Char<=^9 do
[Num:= Num*10 + Char-^0;
GetCh;
];
return if Neg then -Num else Num;
]; \GetNum
int I, N0, N1;
[Str:= "-6,-3--1,3-5,7-11,14,15,17-20";
Inx:= 0;
GetCh; \one character look ahead
loop [N0:= GetNum;
IntOut(0,N0);
case Char of
^,: [GetCh; ChOut(0,^,)];
^-: [GetCh;
N1:= GetNum;
for I:= N0+1 to N1 do \expand range
[ChOut(0,^,); IntOut(0,I)];
if Char=^, then [GetCh; ChOut(0,^,)] else quit]
other quit; \must be 0 string terminator
];
CrLf(0);
]