diff --git a/src/read.c b/src/read.c index 02756069a1f..3be5c11e1a2 100644 --- a/src/read.c +++ b/src/read.c @@ -1390,8 +1390,10 @@ static void ReadFuncExprAbbrevSingle(ScannerState * s, TypSymbolSet follow) ** all symbols up to one contained in . ** ** := +** | ** | 'true' ** | 'false' +** | '~' ** | ** | ** | @@ -1407,13 +1409,6 @@ static void ReadFuncExprAbbrevSingle(ScannerState * s, TypSymbolSet follow) */ static void ReadLiteral(ScannerState * s, TypSymbolSet follow, Char mode) { - if (s->Symbol == S_DOT) { - // HACK: The only way a dot could turn up here is in a floating point - // literal that starts with '.'. Call back to the scanner to deal - // with this. - ScanForFloatAfterDotHACK(s); - } - switch (s->Symbol) { /* */ @@ -1456,7 +1451,7 @@ static void ReadLiteral(ScannerState * s, TypSymbolSet follow, Char mode) Match(s, S_CHAR, "character", follow); break; - /* string */ + /* */ case S_STRING: GAP_ASSERT(s->ValueObj != 0); TRY_IF_NO_ERROR { IntrStringExpr(s->ValueObj); } @@ -1469,7 +1464,7 @@ static void ReadLiteral(ScannerState * s, TypSymbolSet follow, Char mode) ReadListExpr(s, follow); break; - /* */ + /* */ case S_REC: ReadRecExpr(s, follow); break; diff --git a/src/scanner.c b/src/scanner.c index 14a9846afc5..932a9c66b72 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -367,10 +367,6 @@ static UInt GetIdent(ScannerState * s, Int i) ** ** When 's->Value' is completely filled, then a GAP string object is ** created in 's->ValueObj' and all data is stored there. -** -** The argument is used to signal if a decimal point was already read, -** or whether we are starting from scratch.. -** */ static UInt AddCharToBuf(Obj * string, Char * buf, UInt bufsize, UInt pos, Char c) { @@ -387,26 +383,22 @@ static UInt AddCharToValue(ScannerState * s, UInt pos, Char c) return AddCharToBuf(&s->ValueObj, s->Value, MAX_VALUE_LEN - 1, pos, c); } -static UInt GetNumber(ScannerState * s, Int readDecimalPoint) +static UInt GetNumber(ScannerState * s) { UInt symbol = S_ILLEGAL; UInt i = 0; Char c; - UInt seenADigit = 0; UInt seenExp = 0; UInt seenExpDigit = 0; s->ValueObj = 0; c = PEEK_CURR_CHAR(); - if (readDecimalPoint) { - s->Value[i++] = '.'; - } - else { + GAP_ASSERT(IsDigit(c)); + // read initial sequence of digits into 'Value' while (IsDigit(c)) { i = AddCharToValue(s, i, c); - seenADigit = 1; c = GET_NEXT_CHAR(); } @@ -455,21 +447,15 @@ static UInt GetNumber(ScannerState * s, Int readDecimalPoint) symbol = S_INT; goto finish; } - } - // When we get here we have read possibly some digits, a . and possibly - // some more digits, but not an e,E,d,D,q or Q + // When we get here we have read some digits and a dot - // read digits + // read digits after dot while (IsDigit(c)) { i = AddCharToValue(s, i, c); - seenADigit = 1; c = GET_NEXT_CHAR(); } - if (!seenADigit) - SyntaxError(s, "Badly formed number: need a digit before or after the " - "decimal point"); if (c == '\\') SyntaxError(s, "Badly formed number"); @@ -509,9 +495,6 @@ static UInt GetNumber(ScannerState * s, Int readDecimalPoint) // If the next thing is the start of the exponential notation, read it now. if (IsAlpha(c)) { - if (!seenADigit) - SyntaxError(s, "Badly formed number: need a digit before or after " - "the decimal point"); seenExp = 1; i = AddCharToValue(s, i, c); c = GET_NEXT_CHAR(); @@ -524,9 +507,6 @@ static UInt GetNumber(ScannerState * s, Int readDecimalPoint) // Either we saw an exponent indicator, or we hit end of token deal with // the end of token case if (!seenExp) { - if (!seenADigit) - SyntaxError(s, "Badly formed number: need a digit before or after " - "the decimal point"); // Might be a conversion marker if (IsAlpha(c) && c != 'e' && c != 'E' && c != 'd' && c != 'D' && c != 'q' && c != 'Q') { @@ -600,17 +580,6 @@ static UInt GetNumber(ScannerState * s, Int readDecimalPoint) } -/**************************************************************************** -** -*F ScanForFloatAfterDotHACK() -** -*/ -void ScanForFloatAfterDotHACK(ScannerState * s) -{ - s->Symbol = GetNumber(s, 1); -} - - /**************************************************************************** ** *F GetOctalDigits() @@ -1052,7 +1021,7 @@ static UInt NextSymbol(ScannerState * s) case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - return GetNumber(s, 0); + return GetNumber(s); case '\377': symbol = S_EOF; *STATE(In) = '\0'; break; diff --git a/src/scanner.h b/src/scanner.h index babd6629697..fe8bdbd9275 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -374,19 +374,6 @@ void Match(ScannerState * s, TypSymbolSet skipto); -/**************************************************************************** -** -*F ScanForFloatAfterDotHACK() -** -** This function is called by 'ReadLiteral' if it encounters a single dot in -** form the of the symbol 'S_DOT'. The only legal way this could happen is -** if the dot is the start of a float literal like '.123'. As the scanner -** cannot detect this without being context aware, we must provide this -** function to allow the reader to signal to the scanner about this. -*/ -void ScanForFloatAfterDotHACK(ScannerState * s); - - /**************************************************************************** ** *F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * * diff --git a/tst/testbugfix/2013-08-21-t00295.tst b/tst/testbugfix/2013-08-21-t00295.tst index f95f5b1d120..2cfc48f40db 100644 --- a/tst/testbugfix/2013-08-21-t00295.tst +++ b/tst/testbugfix/2013-08-21-t00295.tst @@ -1,8 +1,7 @@ # 2013/08/21 (MH) gap> . . . . -Syntax error: Badly formed number: need a digit before or after the decimal po\ -int in stream:1 +Syntax error: literal expected in stream:1 . . . . ^ -Syntax error: Record component name expected in stream:2 +Syntax error: ; expected in stream:2 diff --git a/tst/testinstall/float.tst b/tst/testinstall/float.tst index 821dc658bfe..2bceb2643e1 100644 --- a/tst/testinstall/float.tst +++ b/tst/testinstall/float.tst @@ -696,7 +696,7 @@ gap> ComplexConjugate(1.3); # gap> Display(1.3); 1.3 -gap> Display(-.4e6); +gap> Display(-0.4e6); -400000. gap> PrintObj(1.3); Print("Q\n"); 1.3Q diff --git a/tst/testinstall/longnumber.tst b/tst/testinstall/longnumber.tst index df3ca6d849f..b0bee07b420 100644 --- a/tst/testinstall/longnumber.tst +++ b/tst/testinstall/longnumber.tst @@ -152,8 +152,6 @@ gap> 1.; 1. gap> 0.; 0. -gap> .1; -0.1 gap> 0.1; 0.1 gap> 1111111111111111111111111111111111111.1; @@ -161,31 +159,28 @@ gap> 1111111111111111111111111111111111111.1; gap> 1.11111111111111111111111111111111111111; 1.11111 gap> .; -Syntax error: Badly formed number: need a digit before or after the decimal po\ -int in stream:1 +Syntax error: literal expected in stream:1 .; ^ gap> .n; -Syntax error: Badly formed number: need a digit before or after the decimal po\ -int in stream:1 +Syntax error: literal expected in stream:1 .n; ^ gap> .q; -Syntax error: Badly formed number: need a digit before or after the decimal po\ -int in stream:1 +Syntax error: literal expected in stream:1 .q; ^ gap> .0n; -Error, failed to convert float literal +Syntax error: literal expected in stream:1 +.0n; +^ gap> .0q; -Syntax error: Badly formed number: need at least one digit in the exponent in \ -stream:1 +Syntax error: literal expected in stream:1 .0q; -^^^ +^ gap> .0qn; -Syntax error: Badly formed number: need at least one digit in the exponent in \ -stream:1 +Syntax error: literal expected in stream:1 .0qn; -^^^ +^ gap> Unbind(x); gap> STOP_TEST( "longnumber.tst", 1);