Skip to content

Commit cf0e08d

Browse files
authored
Revert "C# 7.x: numeric literal syntax improvements" (#408)
* Revert "Update lexical-structure.md" This reverts commit edfe37a. * Revert "Update lexical-structure.md" This reverts commit 72a6d54. * Revert "Update lexical-structure.md" This reverts commit e90c654.
1 parent 6e56634 commit cf0e08d

File tree

1 file changed

+22
-95
lines changed

1 file changed

+22
-95
lines changed

standard/lexical-structure.md

Lines changed: 22 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -489,75 +489,34 @@ The type of a *boolean_literal* is `bool`.
489489

490490
#### 7.4.5.3 Integer literals
491491

492-
Integer literals are used to write values of types `int`, `uint`, `long`, and `ulong`. Integer literals have three possible forms: decimal, hexadecimal, and binary.
492+
Integer literals are used to write values of types `int`, `uint`, `long`, and `ulong`. Integer literals have two possible forms: decimal and hexadecimal.
493493

494494
```ANTLR
495495
integer_literal
496496
: decimal_integer_literal
497497
| hexadecimal_integer_literal
498-
| Binary_Integer_Literal
499498
;
500499
501500
decimal_integer_literal
502-
: decimal_digits integer_type_suffix?
501+
: decimal_digit+ integer_type_suffix?
503502
;
504503
505-
decimal_digits
506-
: decimal_digit
507-
| decimal_digit decimal_digit_or_underscore* decimal_digit
508-
;
509-
510504
decimal_digit
511505
: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
512506
;
513-
514-
decimal_digit_or_underscore
515-
: decimal_digit
516-
| '_'
517-
;
518507
519508
integer_type_suffix
520509
: 'U' | 'u' | 'L' | 'l' | 'UL' | 'Ul' | 'uL' | 'ul' | 'LU' | 'Lu' | 'lU' | 'lu'
521510
;
522511
523512
hexadecimal_integer_literal
524-
: '0x' hex_digits+ integer_type_suffix?
525-
| '0X' hex_digits+ integer_type_suffix?
526-
;
527-
528-
hex_digits
529-
: '_'* hex_digit
530-
| '_'* hex_digit hex_digit_or_underscore* hex_digit
513+
: '0x' hex_digit+ integer_type_suffix?
514+
| '0X' hex_digit+ integer_type_suffix?
531515
;
532516
533517
hex_digit
534518
: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
535519
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f';
536-
537-
hex_digit_or_underscore
538-
: hex_digit
539-
| '_'
540-
;
541-
542-
Binary_Integer_Literal
543-
: '_'* '0b' Binary_Digits+ Integer_Type_Suffix?
544-
| '_'* '0B' Binary_Digits+ Integer_Type_Suffix?
545-
;
546-
547-
Binary_Digits
548-
: Binary_Digit
549-
| Binary_Digit Binary_Digit_Or_Underscore* Binary_Digit
550-
;
551-
552-
Binary_Digit
553-
: '0'
554-
| '1'
555-
;
556-
557-
Binary_Digit_Or_Underscore
558-
: Binary_Digit
559-
| '_'
560-
;
561520
```
562521

563522
The type of an integer literal is determined as follows:
@@ -569,51 +528,32 @@ The type of an integer literal is determined as follows:
569528

570529
If the value represented by an integer literal is outside the range of the `ulong` type, a compile-time error occurs.
571530

572-
> *Note*: As a matter of style, it is suggested that "`L`" be used instead of "`l`" when writing literals of type `long`, since it is easy to confuse the letter "`l`" with the digit "`1`". *end note*
531+
> *Note*: As a matter of style, it is suggested that "`L`" be used instead of "`l`" when writing literals of type `long`, since it is easy to confuse the letter "`l`" with the digit "`1`". *end note*
573532
574533
To permit the smallest possible `int` and `long` values to be written as integer literals, the following two rules exist:
575534

576-
- When an *integer_literal* representing the value `2147483648` (2³¹) and no *integer_type_suffix* appears as the token immediately following a unary minus operator token ([§12.8.3](expressions.md#1283-unary-minus-operator)), the result (of both tokens) is a constant of type `int` with the value `−2147483648` (−2³¹). In all other situations, such an *integer_literal* is of type `uint`.
577-
- When an *integer_literal* representing the value `9223372036854775808` (2⁶³) and no *integer_type_suffix* or the *integer_type_suffix* `L` or `l` appears as the token immediately following a unary minus operator token), the result (of both tokens) is a constant of type `long` with the value `−9223372036854775808` (−2⁶³). In all other situations, such an *integer_literal* is of type `ulong`.
578-
579-
> *Example*:
580-
> ```csharp
581-
> 123 // decimal, int
582-
> 10_543_765Lu // decimal, ulong
583-
> 1__234__567 // decimal, int
584-
>
585-
> 0xFf // hex, int
586-
> 0X1b_a0_44_fEL // hex, long
587-
> 0x1ade_3FE1_29AaUL // hex, ulong
588-
> 0xabc_ // invalid; no trailing _ allowed
589-
>
590-
> 0b101 // binary, int
591-
> 0B1001_1010u // binary, uint
592-
> 0b1111_1111_0000UL // binary, ulong
593-
> 0B__111 // OK; leading _ allowed
594-
> ```
595-
> *end example*
535+
- When an *integer_literal* representing the value `2147483648` (2³¹) and no *integer_type_suffix* appears as the token immediately following a unary minus operator token ([§12.8.3](expressions.md#1283-unary-minus-operator)), the result (of both tokens) is a constant of type int with the value `−2147483648` (−2³¹</sup>). In all other situations, such an *integer_literal* is of type `uint`.
536+
- When an *integer_literal* representing the value `9223372036854775808` (2⁶³) and no *integer_type_suffix* or the *integer_type_suffix* `L` or `l` appears as the token immediately following a unary minus operator token ([§12.8.3](expressions.md#1283-unary-minus-operator)), the result (of both tokens) is a constant of type `long` with the value `−9223372036854775808` (−2⁶³). In all other situations, such an *integer_literal* is of type `ulong`.
596537

597538
#### 7.4.5.4 Real literals
598539

599540
Real literals are used to write values of types `float`, `double`, and `decimal`.
600541

601542
```ANTLR
602543
real_literal
603-
: decimal_digits '.' decimal_digits exponent_part? real_type_suffix?
604-
| '.' decimal_digits exponent_part? real_type_suffix?
605-
| decimal_digits exponent_part real_type_suffix?
606-
| decimal_digits real_type_suffix
544+
: decimal_digit+ '.' decimal_digit+ exponent_part? real_type_suffix?
545+
| '.' decimal_digit+ exponent_part? real_type_suffix?
546+
| decimal_digit+ exponent_part real_type_suffix?
547+
| decimal_digit+ real_type_suffix
607548
;
608549
609550
exponent_part
610-
: 'e' sign? decimal_digits
611-
| 'E' sign? decimal_digits
551+
: 'e' sign? decimal_digit+
552+
| 'E' sign? decimal_digit+
612553
;
613554
614555
sign
615-
: '+'
616-
| '-'
556+
: '+' | '-'
617557
;
618558
619559
real_type_suffix
@@ -623,14 +563,14 @@ real_type_suffix
623563

624564
If no *real_type_suffix* is specified, the type of the *real_literal* is `double`. Otherwise, the *real_type_suffix* determines the type of the real literal, as follows:
625565

626-
- A real literal suffixed by `F` or `f` is of type `float`.
627-
> *Example*: The literals `1f, 1.5f, 1e10f`, and `123.456F` are all of type `float`. *end example*
628-
- A real literal suffixed by `D` or `d` is of type `double`.
629-
> *Example*: The literals `1d, 1.5d, 1e10d`, and `123.456D` are all of type `double`. *end example*
630-
- A real literal suffixed by `M` or `m` is of type `decimal`.
631-
> *Example*: The literals `1m, 1.5m, 1e10m`, and `123.456M` are all of type `decimal`. *end example*
632-
This literal is converted to a `decimal` value by taking the exact value, and, if necessary, rounding to the nearest representable value using banker's rounding ([§9.3.8](types.md#938-the-decimal-type)). Any scale apparent in the literal is preserved unless the value is rounded.
633-
> *Note*: Hence, the literal `2.900m` will be parsed to form the `decimal` with sign `0`, coefficient `2900`, and scale `3`. *end note*
566+
- A real literal suffixed by `F` or `f` is of type `float`.
567+
> *Example*: The literals `1f, 1.5f, 1e10f`, and `123.456F` are all of type `float`. *end example*
568+
- A real literal suffixed by `D` or `d` is of type `double`.
569+
> *Example*: The literals `1d, 1.5d, 1e10d`, and `123.456D` are all of type `double`. *end example*
570+
- A real literal suffixed by `M` or `m` is of type `decimal`.
571+
> *Example*: The literals `1m, 1.5m, 1e10m`, and `123.456M` are all of type `decimal`. *end example*
572+
This literal is converted to a `decimal` value by taking the exact value, and, if necessary, rounding to the nearest representable value using banker's rounding ([§9.3.8](types.md#938-the-decimal-type)). Any scale apparent in the literal is preserved unless the value is rounded.
573+
> *Note*: Hence, the literal `2.900m` will be parsed to form the `decimal` with sign `0`, coefficient `2900`, and scale `3`. *end note*
634574
635575
If the magnitude of the specified literal is too large to be represented in the indicated type, a compile-time error occurs.
636576

@@ -640,19 +580,6 @@ The value of a real literal of type `float` or `double` is determined by using t
640580

641581
> *Note*: In a real literal, decimal digits are always required after the decimal point. For example, `1.3F` is a real literal but `1.F` is not. *end note*
642582
643-
> *Example*:
644-
> ```csharp
645-
> 1.234_567 // double
646-
> .3e5f // float
647-
> 2_345E-2_0 // double
648-
> 15D // double
649-
> 19.73M // decimal
650-
> 1.F // invalid; ill-formed (parsed as "1." and "F")
651-
> 1.234_ // invalid; no trailing _ allowed in fraction
652-
> .3e5_F // invalid; no trailing _ allowed in exponent
653-
> ```
654-
> *end example*
655-
656583
#### 7.4.5.5 Character literals
657584

658585
A character literal represents a single character, and consists of a character in quotes, as in `'a'`.

0 commit comments

Comments
 (0)