fixes
This commit is contained in:
parent
ea69982a26
commit
b93c1cb093
3 changed files with 31 additions and 32 deletions
lang/m2/libm2
|
@ -82,7 +82,7 @@ DEFINITION MODULE PascalIo;
|
||||||
result in "card".
|
result in "card".
|
||||||
Syntax:
|
Syntax:
|
||||||
real --> [(+|-)] digit {digit} [. digit {digit}]
|
real --> [(+|-)] digit {digit} [. digit {digit}]
|
||||||
[ (e|E) [(+|-)] digit {digit} ]
|
[ E [(+|-)] digit {digit} ]
|
||||||
If no real is read, or when overflow/underflow occurs, a runtime error
|
If no real is read, or when overflow/underflow occurs, a runtime error
|
||||||
results.
|
results.
|
||||||
Input stops at the character following the integer.
|
Input stops at the character following the integer.
|
||||||
|
|
|
@ -143,7 +143,8 @@ IMPLEMENTATION MODULE PascalIo;
|
||||||
chk(inputtext, reading);
|
chk(inputtext, reading);
|
||||||
WITH inputtext^ DO
|
WITH inputtext^ DO
|
||||||
IF eof THEN
|
IF eof THEN
|
||||||
(* ??? trap here ??? *)
|
Traps.Message("unexpected EOF");
|
||||||
|
HALT;
|
||||||
END;
|
END;
|
||||||
IF cnt > maxcnt THEN
|
IF cnt > maxcnt THEN
|
||||||
dummy := FillBuf(inputtext);
|
dummy := FillBuf(inputtext);
|
||||||
|
@ -312,6 +313,15 @@ IMPLEMENTATION MODULE PascalIo;
|
||||||
ch: CHAR;
|
ch: CHAR;
|
||||||
ok: BOOLEAN;
|
ok: BOOLEAN;
|
||||||
index: INTEGER;
|
index: INTEGER;
|
||||||
|
|
||||||
|
PROCEDURE inch(): CHAR;
|
||||||
|
BEGIN
|
||||||
|
buf[index] := ch;
|
||||||
|
INC(index);
|
||||||
|
Get(inputtext);
|
||||||
|
RETURN NextCHAR(inputtext);
|
||||||
|
END inch;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
index := 0;
|
index := 0;
|
||||||
WHILE NextCHAR(inputtext) IN spaces DO
|
WHILE NextCHAR(inputtext) IN spaces DO
|
||||||
|
@ -319,45 +329,30 @@ IMPLEMENTATION MODULE PascalIo;
|
||||||
END;
|
END;
|
||||||
ch := NextCHAR(inputtext);
|
ch := NextCHAR(inputtext);
|
||||||
IF (ch ='+') OR (ch = '-') THEN
|
IF (ch ='+') OR (ch = '-') THEN
|
||||||
buf[index] := ch;
|
ch := inch();
|
||||||
INC(index);
|
|
||||||
Get(inputtext);
|
|
||||||
ch := NextCHAR(inputtext);
|
|
||||||
END;
|
END;
|
||||||
IF (ch >= '0') AND (ch <= '9') THEN
|
IF (ch >= '0') AND (ch <= '9') THEN
|
||||||
WHILE (ch >= '0') AND (ch <= '9') DO
|
WHILE (ch >= '0') AND (ch <= '9') DO
|
||||||
buf[index] := ch;
|
ch := inch();
|
||||||
INC(index);
|
|
||||||
Get(inputtext);
|
|
||||||
ch := NextCHAR(inputtext);
|
|
||||||
END;
|
END;
|
||||||
IF (ch = '.') THEN
|
IF (ch = '.') THEN
|
||||||
|
ch := inch();
|
||||||
IF (ch >= '0') AND (ch <= '9') THEN
|
IF (ch >= '0') AND (ch <= '9') THEN
|
||||||
WHILE (ch >= '0') AND (ch <= '9') DO
|
WHILE (ch >= '0') AND (ch <= '9') DO
|
||||||
buf[index] := ch;
|
ch := inch();
|
||||||
INC(index);
|
|
||||||
Get(inputtext);
|
|
||||||
ch := NextCHAR(inputtext);
|
|
||||||
END;
|
END;
|
||||||
ELSE
|
ELSE
|
||||||
ok := FALSE;
|
ok := FALSE;
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
IF ok AND (ch = 'E') THEN
|
IF ok AND (ch = 'E') THEN
|
||||||
Get(inputtext);
|
ch := inch();
|
||||||
ch := NextCHAR(inputtext);
|
|
||||||
IF (ch ='+') OR (ch = '-') THEN
|
IF (ch ='+') OR (ch = '-') THEN
|
||||||
buf[index] := ch;
|
ch := inch();
|
||||||
INC(index);
|
|
||||||
Get(inputtext);
|
|
||||||
ch := NextCHAR(inputtext);
|
|
||||||
END;
|
END;
|
||||||
IF (ch >= '0') AND (ch <= '9') THEN
|
IF (ch >= '0') AND (ch <= '9') THEN
|
||||||
WHILE (ch >= '0') AND (ch <= '9') DO
|
WHILE (ch >= '0') AND (ch <= '9') DO
|
||||||
buf[index] := ch;
|
ch := inch();
|
||||||
INC(index);
|
|
||||||
Get(inputtext);
|
|
||||||
ch := NextCHAR(inputtext);
|
|
||||||
END;
|
END;
|
||||||
ELSE
|
ELSE
|
||||||
ok := FALSE;
|
ok := FALSE;
|
||||||
|
@ -411,7 +406,7 @@ IMPLEMENTATION MODULE PascalIo;
|
||||||
width := SIZE(buf);
|
width := SIZE(buf);
|
||||||
END;
|
END;
|
||||||
IF nfrac > 0 THEN
|
IF nfrac > 0 THEN
|
||||||
RealConversions.RealToString(real, nfrac, width, buf, ok);
|
RealConversions.RealToString(real, width, nfrac, buf, ok);
|
||||||
ELSE
|
ELSE
|
||||||
IF width < 9 THEN width := 9; END;
|
IF width < 9 THEN width := 9; END;
|
||||||
IF real < 0.0 THEN
|
IF real < 0.0 THEN
|
||||||
|
@ -419,7 +414,7 @@ IMPLEMENTATION MODULE PascalIo;
|
||||||
ELSE
|
ELSE
|
||||||
digits := 6 - INTEGER(width);
|
digits := 6 - INTEGER(width);
|
||||||
END;
|
END;
|
||||||
RealConversions.RealToString(real, digits, width, buf, ok);
|
RealConversions.RealToString(real, width, digits, buf, ok);
|
||||||
END;
|
END;
|
||||||
WriteSTRING(outputtext, buf, 0);
|
WriteSTRING(outputtext, buf, 0);
|
||||||
END WriteREAL;
|
END WriteREAL;
|
||||||
|
|
|
@ -26,7 +26,6 @@ IMPLEMENTATION MODULE RealConversions;
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
r := arg;
|
r := arg;
|
||||||
DEC(width);
|
|
||||||
IF digits < 0 THEN
|
IF digits < 0 THEN
|
||||||
ecvtflag := TRUE;
|
ecvtflag := TRUE;
|
||||||
ndigits := -digits;
|
ndigits := -digits;
|
||||||
|
@ -34,7 +33,9 @@ IMPLEMENTATION MODULE RealConversions;
|
||||||
ecvtflag := FALSE;
|
ecvtflag := FALSE;
|
||||||
ndigits := digits;
|
ndigits := digits;
|
||||||
END;
|
END;
|
||||||
IF HIGH(str) < ndigits + 3 THEN str[0] := 0C; ok := FALSE; RETURN END;
|
IF (HIGH(str) < ndigits + 3) THEN
|
||||||
|
str[0] := 0C; ok := FALSE; RETURN
|
||||||
|
END;
|
||||||
pointpos := 0;
|
pointpos := 0;
|
||||||
sign := r < 0.0D;
|
sign := r < 0.0D;
|
||||||
IF sign THEN r := -r END;
|
IF sign THEN r := -r END;
|
||||||
|
@ -124,7 +125,6 @@ IMPLEMENTATION MODULE RealConversions;
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
str[ind1] := 0C;
|
|
||||||
IF ecvtflag THEN
|
IF ecvtflag THEN
|
||||||
FOR i := ind1 TO 2 BY -1 DO
|
FOR i := ind1 TO 2 BY -1 DO
|
||||||
str[i] := str[i-1];
|
str[i] := str[i-1];
|
||||||
|
@ -185,11 +185,15 @@ IMPLEMENTATION MODULE RealConversions;
|
||||||
INC(ind1);
|
INC(ind1);
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
IF ind1 > CARDINAL(width) THEN
|
IF (ind1+1) <= HIGH(str) THEN str[ind1+1] := 0C; END;
|
||||||
|
IF ind1 >= CARDINAL(width) THEN
|
||||||
ok := FALSE;
|
ok := FALSE;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;
|
END;
|
||||||
IF ind1 < CARDINAL(width) THEN
|
IF width > 0 THEN
|
||||||
|
DEC(width);
|
||||||
|
END;
|
||||||
|
IF (width > 0) AND (ind1 < CARDINAL(width)) THEN
|
||||||
FOR i := ind1 TO 0 BY -1 DO
|
FOR i := ind1 TO 0 BY -1 DO
|
||||||
str[i + CARDINAL(width) - ind1] := str[i];
|
str[i + CARDINAL(width) - ind1] := str[i];
|
||||||
END;
|
END;
|
||||||
|
@ -197,8 +201,8 @@ IMPLEMENTATION MODULE RealConversions;
|
||||||
str[i] := ' ';
|
str[i] := ' ';
|
||||||
END;
|
END;
|
||||||
ind1 := CARDINAL(width);
|
ind1 := CARDINAL(width);
|
||||||
|
IF (ind1+1) <= HIGH(str) THEN str[ind1+1] := 0C; END;
|
||||||
END;
|
END;
|
||||||
IF (ind1+1) <= HIGH(str) THEN str[ind1+1] := 0C; END;
|
|
||||||
|
|
||||||
END LongRealToString;
|
END LongRealToString;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue