Repository navigation
parser: read large real literals and report out-of-range literals - #51
Merged
Merged
Conversation
A real literal whose integer part did not fit in ulong was not recognized at all: 100000000000000000000.0, 100000000000000000000d, and even 79228162514264337593543950335m (decimal.MaxValue) failed with "Expected [!+\-~], ...". The integer scanner gave up on overflow before anything could see the fraction, exponent, or suffix after the digits. Read the digits to the end and decide afterwards whether the literal is real. As in C#, digits followed by d, f, or m form a real literal. Report literals out of range as C# does, at the position of the literal: - an integer too large for ulong, in any base, with "Integral constant is too large." Decimal digits failed with "Expected ...", and hexadecimal and binary ones were read as 0 followed by an unexpected x or b; - a real too large for its type, with "Floating-point constant is outside the range of type 'System.Double'." and the like. 1e400 and 1e39f evaluated to infinity, which double.PositiveInfinity and float.PositiveInfinity still give, and 1e100m put an OverflowException with its stack trace into the error message. A value too small for its type still becomes zero, as in C#.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A real literal whose integer part does not fit in
ulongwas not recognized at all.100000000000000000000.0,100000000000000000000d, and even79228162514264337593543950335m(decimal.MaxValue) failed withExpected [!+\-~], ...: the integer scanner gave up on overflow before anything could see the fraction, exponent, or suffix after the digits.This PR reads the digits to the end and decides afterwards whether the literal is real. As in C#, digits followed by
d,f, ormform a real literal.Literals out of range are now reported as C# reports them, at the position of the literal:
100000000000000000000(1:1) Expected [!+\-~], ...(1:1) Integral constant is too large.(CS1021)0x10000000000000000, 65-bit0b...(1:2) Expected '(', '[', ...(1:1) Integral constant is too large.1e400,1e39fInfinity(1:1) Floating-point constant is outside the range of type 'System.Double'.('System.Single'for1e39f, CS0594)1e100m(1:1) System.OverflowException: ...with the stack trace(1:1) Floating-point constant is outside the range of type 'System.Decimal'.A value too small for its type still becomes zero, as in C#:
1e-400is0d.Expressions that relied on
1e400evaluating to infinity are now rejected;double.PositiveInfinityandfloat.PositiveInfinitystill give one.