forked from dlang/dlang.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex.dd
1256 lines (1059 loc) · 24.3 KB
/
lex.dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Ddoc
$(SPEC_S Lexical,
In D, the lexical analysis is independent of the syntax parsing and the
semantic analysis. The lexical analyzer splits the source text up into
tokens. The lexical grammar describes what those tokens are. The D
lexical grammar is designed to be suitable for high speed scanning, it
has a minimum of special case rules, there is only one phase of
translation, and to make it easy to write a correct scanner
for. The tokens are readily recognizable by those familiar with C and
C++.
<h3>Phases of Compilation</h3>
The process of compiling is divided into multiple phases. Each phase
has no dependence on subsequent phases. For example, the scanner is
not perturbed by the semantic analyzer. This separation of the passes
makes language tools like syntax
directed editors relatively easy to produce.
It also is possible to compress D source by storing it in
$(SINGLEQUOTE tokenized) form.
$(OL
$(LI $(B source character set)$(BR)
The source file is checked to see what character set it is,
and the appropriate scanner is loaded. ASCII and UTF
formats are accepted.
)
$(LI $(B script line) $(BR)
If the first line starts with $(GREEN #!) then the first line
is ignored.
)
$(LI $(B lexical analysis)$(BR)
The source file is divided up into a sequence of tokens.
$(LINK2 #specialtokens, Special tokens) are replaced with other tokens.
$(LINK2 #specialtokenseq, Special token sequences)
are processed and removed.
)
$(LI $(B syntax analysis)$(BR)
The sequence of tokens is parsed to form syntax trees.
)
$(LI $(B semantic analysis)$(BR)
The syntax trees are traversed to declare variables, load symbol tables, assign
types, and in general determine the meaning of the program.
)
$(LI $(B optimization)$(BR)
Optimization is an optional pass that tries to rewrite the program
in a semantically equivalent, but faster executing, version.
)
$(LI $(B code generation)$(BR)
Instructions are selected from the target architecture to implement
the semantics of the program. The typical result will be
an object file, suitable for input to a linker.
)
)
<h3>Source Text</h3>
D source text can be in one of the following formats:
$(UL
$(LI ASCII)
$(LI UTF-8)
$(LI UTF-16BE)
$(LI UTF-16LE)
$(LI UTF-32BE)
$(LI UTF-32LE)
)
UTF-8 is a superset of traditional 7-bit ASCII.
One of the
following UTF BOMs (Byte Order Marks) can be present at the beginning
of the source text:
<p>
$(TABLE2 UTF Byte Order Marks,
$(TR
$(TH Format)
$(TH BOM)
)
$(TR
$(TD UTF-8)
$(TD EF BB BF)
)
$(TR
$(TD UTF-16BE)
$(TD FE FF)
)
$(TR
$(TD UTF-16LE)
$(TD FF FE)
)
$(TR
$(TD UTF-32BE)
$(TD 00 00 FE FF)
)
$(TR
$(TD UTF-32LE)
$(TD FF FE 00 00)
)
$(TR
$(TD ASCII)
$(TD no BOM)
)
)
$(P If the source file does not start with a BOM, then the first
character must be less than or equal to U0000007F.)
$(P There are no digraphs or trigraphs in D.)
$(P The source text is decoded from its source representation
into Unicode $(I Character)s.
The $(I Character)s are further divided into:
$(LINK2 #whitespace, white space),
$(LINK2 #endofline, end of lines),
$(LINK2 #comment, comments),
$(LINK2 #specialtokens, special token sequences),
$(LINK2 #tokens, tokens),
all followed by $(LINK2 #eof, end of file).
)
$(P The source text is split into tokens using the maximal munch
technique, i.e., the
lexical analyzer tries to make the longest token it can. For example
<code>>></code> is a right shift token,
not two greater than tokens. An exception to this rule is that a ..
embedded inside what looks like two floating point literals, as in
1..2, is interpreted as if the .. was separated by a space from the
first integer.
)
<h3>$(LNAME2 eof, End of File)</h3>
$(GRAMMAR
$(I EndOfFile):
$(I physical end of the file)
\u0000
\u001A
)
The source text is terminated by whichever comes first.
<h3>$(LNAME2 endofline, End of Line)</h3>
$(GRAMMAR
$(I EndOfLine):
\u000D
\u000A
\u000D \u000A
$(I EndOfFile)
)
There is no backslash line splicing, nor are there any limits
on the length of a line.
<h3>$(LNAME2 whitespace, White Space)</h3>
$(GRAMMAR
$(I WhiteSpace):
$(I Space)
$(I Space) $(I WhiteSpace)
$(I Space):
\u0020
\u0009
\u000B
\u000C
)
<h3>$(LNAME2 comment, Comments)</h3>
$(GRAMMAR
$(I Comment):
$(B /*) $(I Characters) $(B */)
$(B //) $(I Characters) $(I EndOfLine)
$(I NestingBlockComment)
$(I Characters):
$(I Character)
$(I Character) $(I Characters)
$(I NestingBlockComment):
$(B /+) $(I NestingBlockCommentCharacters) $(B +/)
$(I NestingBlockCommentCharacters):
$(I NestingBlockCommentCharacter)
$(I NestingBlockCommentCharacter) $(I NestingBlockCommentCharacters)
$(I NestingBlockCommentCharacter):
$(I Character)
$(I NestingBlockComment)
)
D has three kinds of comments:
$(OL
$(LI Block comments can span multiple lines, but do not nest.)
$(LI Line comments terminate at the end of the line.)
$(LI Nesting comments can span multiple lines and can nest.)
)
$(P
The contents of strings and comments are not tokenized. Consequently,
comment openings occurring within a string do not begin a comment, and
string delimiters within a comment do not affect the recognition of
comment closings and nested "/+" comment openings. With the exception
of "/+" occurring within a "/+" comment, comment openings within a
comment are ignored.
)
-------------
a = /+ // +/ 1; // parses as if 'a = 1;'
a = /+ "+/" +/ 1"; // parses as if 'a = " +/ 1";'
a = /+ /* +/ */ 3; // parses as if 'a = */ 3;'
-------------
Comments cannot be used as token concatenators, for example,
<code>abc/**/def</code> is two tokens, $(TT abc) and $(TT def),
not one $(TT abcdef) token.
<h3>$(LNAME2 tokens, Tokens)</h3>
$(GRAMMAR
$(I Token):
$(LINK2 #identifier, $(I Identifier))
$(LINK2 #StringLiteral, $(I StringLiteral))
$(LINK2 #characterliteral, $(I CharacterLiteral))
$(LINK2 #integerliteral, $(I IntegerLiteral))
$(LINK2 #floatliteral, $(I FloatLiteral))
$(LINK2 #keyword, $(I Keyword))
$(B /)
$(B /=)
$(B .)
$(B ..)
$(B ...)
$(B &)
$(B &=)
$(B &&)
$(B |)
$(B |=)
$(B ||)
$(B -)
$(B -=)
$(B --)
$(B +)
$(B +=)
$(B ++)
$(B <)
$(B <=)
$(B <<)
$(B <<=)
$(B <>)
$(B <>=)
$(B >)
$(B >=)
$(B >>=)
$(B >>>=)
$(B >>)
$(B >>>)
$(B !)
$(B !=)
$(B !<>)
$(B !<>=)
$(B !<)
$(B !<=)
$(B !>)
$(B !>=)
$(B $(LPAREN))
$(B $(RPAREN))
$(B [)
$(B ])
$(B {)
$(B })
$(B ?)
$(B ,)
$(B ;)
$(B :)
$(B $)
$(B =)
$(B ==)
$(B *)
$(B *=)
$(B %)
$(B %=)
$(B ^)
$(B ^=)
$(B ~)
$(B ~=)
$(V2 $(B @))
)
<h3>$(LNAME2 identifier, Identifiers)</h3>
$(GRAMMAR
$(I Identifier):
$(I IdentiferStart)
$(I IdentiferStart) $(I IdentifierChars)
$(I IdentifierChars):
$(I IdentiferChar)
$(I IdentiferChar) $(I IdentifierChars)
$(I IdentifierStart):
$(B _)
$(I Letter)
$(I UniversalAlpha)
$(I IdentifierChar):
$(I IdentiferStart)
$(B 0)
$(I NonZeroDigit)
)
Identifiers start with a letter, $(B _), or universal alpha,
and are followed by any number
of letters, $(B _), digits, or universal alphas.
Universal alphas are as defined in ISO/IEC 9899:1999(E) Appendix D.
(This is the C99 Standard.)
Identifiers can be arbitrarily long, and are case sensitive.
Identifiers starting with $(B __) (two underscores) are reserved.
<h3>$(LNAME2 StringLiteral, String Literals)</h3>
$(GRAMMAR
$(I StringLiteral):
$(I WysiwygString)
$(I AlternateWysiwygString)
$(I DoubleQuotedString)
$(V1
$(I EscapeSequence))
$(I HexString)
$(V2
$(I DelimitedString)
$(I TokenString))
$(I WysiwygString):
$(B r") $(I WysiwygCharacters) $(B ") $(I Postfix<sub>opt</sub>)
$(I AlternateWysiwygString):
$(B `) $(I WysiwygCharacters) $(B `) $(I Postfix<sub>opt</sub>)
$(I WysiwygCharacters):
$(I WysiwygCharacter)
$(I WysiwygCharacter) $(I WysiwygCharacters)
$(I WysiwygCharacter):
$(I Character)
$(I EndOfLine)
$(I DoubleQuotedString):
$(B ") $(I DoubleQuotedCharacters) $(B ") $(I Postfix<sub>opt</sub>)
$(I DoubleQuotedCharacters):
$(I DoubleQuotedCharacter)
$(I DoubleQuotedCharacter) $(I DoubleQuotedCharacters)
$(I DoubleQuotedCharacter):
$(I Character)
$(I EscapeSequence)
$(I EndOfLine)
$(LNAME2 EscapeSequence, $(I EscapeSequence)):
$(B \')
$(B \")
$(B \?)
$(B \\)
$(B \a)
$(B \b)
$(B \f)
$(B \n)
$(B \r)
$(B \t)
$(B \v)
$(B \) $(I EndOfFile)
$(B \x) $(I HexDigit) $(I HexDigit)
$(B \) $(I OctalDigit)
$(B \) $(I OctalDigit) $(I OctalDigit)
$(B \) $(I OctalDigit) $(I OctalDigit) $(I OctalDigit)
$(B \u) $(I HexDigit) $(I HexDigit) $(I HexDigit) $(I HexDigit)
$(B \U) $(I HexDigit) $(I HexDigit) $(I HexDigit) $(I HexDigit) $(I HexDigit) $(I HexDigit) $(I HexDigit) $(I HexDigit)
$(B \&) $(LINK2 entity.html, $(I NamedCharacterEntity)) $(B ;)
$(I HexString):
$(B x") $(I HexStringChars) $(B ") $(I Postfix<sub>opt</sub>)
$(I HexStringChars):
$(I HexStringChar)
$(I HexStringChar) $(I HexStringChars)
$(I HexStringChar):
$(I HexDigit)
$(I WhiteSpace)
$(I EndOfLine)
$(I Postfix):
$(B c)
$(B w)
$(B d)
$(V2
$(I DelimitedString):
$(B q") $(I Delimiter) $(I WysiwygCharacters) $(I MatchingDelimiter) $(B ")
$(I TokenString):
$(B q{) $(I Tokens) $(B })
)
)
$(P
A string literal is either a double quoted string, a wysiwyg quoted
string, an escape sequence,
$(V2 a delimited string, a token string,)
or a hex string.
)
<h4>Wysiwyg Strings</h4>
$(P
Wysiwyg quoted strings are enclosed by r" and ".
All characters between
the r" and " are part of the string except for $(I EndOfLine) which is
regarded as a single \n character.
There are no escape sequences inside r" ":
)
---------------
r"hello"
r"c:\root\foo.exe"
r"ab\n" // string is 4 characters, 'a', 'b', '\', 'n'
---------------
$(P
An alternate form of wysiwyg strings are enclosed by backquotes,
the ` character. The ` character is not available on some keyboards
and the font rendering of it is sometimes indistinguishable from
the regular ' character. Since, however, the ` is rarely used,
it is useful to delineate strings with " in them.
)
---------------
`hello`
`c:\root\foo.exe`
`ab\n` // string is 4 characters, 'a', 'b', '\', 'n'
---------------
<h4>Double Quoted Strings</h4>
Double quoted strings are enclosed by "". Escape sequences can be
embedded into them with the typical \ notation.
$(I EndOfLine) is regarded as a single \n character.
---------------
"hello"
"c:\\root\\foo.exe"
"ab\n" // string is 3 characters, 'a', 'b', and a linefeed
"ab
" // string is 3 characters, 'a', 'b', and a linefeed
---------------
$(V1
<h4>Escape Strings</h4>
$(P Escape strings start with a \ and form an escape character sequence.
Adjacent escape strings are concatenated:
)
<pre>
\n the linefeed character
\t the tab character
\" the double quote character
\012 octal
\x1A hex
\u1234 wchar character
\U00101234 dchar character
\&reg; ® dchar character
\r\n carriage return, line feed
</pre>
$(P Undefined escape sequences are errors.
Although string literals are defined to be composed of
UTF characters, the octal and hex escape sequences allow
the insertion of arbitrary binary data.
\u and \U escape sequences can only be used to insert
valid UTF characters.
)
)
<h4>Hex Strings</h4>
$(P Hex strings allow string literals to be created using hex data.
The hex data need not form valid UTF characters.
)
--------------
x"0A" // same as "\x0A"
x"00 FBCD 32FD 0A" // same as "\x00\xFB\xCD\x32\xFD\x0A"
--------------
Whitespace and newlines are ignored, so the hex data can be
easily formatted.
The number of hex characters must be a multiple of 2.
<p>
Adjacent strings are concatenated with the ~ operator, or by simple
juxtaposition:
--------------
"hello " ~ "world" ~ \n // forms the string 'h','e','l','l','o',' ',
// 'w','o','r','l','d',linefeed
--------------
The following are all equivalent:
-----------------
"ab" "c"
r"ab" r"c"
r"a" "bc"
"a" ~ "b" ~ "c"
\x61"bc"
-----------------
The optional $(I Postfix) character gives a specific type
to the string, rather than it being inferred from the context.
This is useful when the type cannot be unambiguously inferred,
such as when overloading based on string type. The types corresponding
to the postfix characters are:
<p>
$(TABLE2 String Literal Postfix Characters,
$(TR
$(TH Postfix)
$(TH Type)
)
$(TR
$(TD $(B c))
$(TD char[ ])
)
$(TR
$(TD $(B w))
$(TD wchar[ ])
)
$(TR
$(TD $(B d))
$(TD dchar[ ])
)
)
---
"hello"c // char[]
"hello"w // wchar[]
"hello"d // dchar[]
---
$(P String literals are read only. Writes to string literals
cannot always be detected, but cause undefined behavior.)
$(V2
<h4>Delimited Strings</h4>
$(P Delimited strings use various forms of delimiters.
The delimiter, whether a character or identifer,
must immediately follow the " without any intervening whitespace.
The terminating delimiter must immediately precede the closing "
without any intervening whitespace.
A $(I nesting delimiter) nests, and is one of the
following characters:
)
$(TABLE2 Nesting Delimiters,
$(TR
$(TH Delimiter)
$(TH Matching Delimiter)
)
$(TR
$(TD [)
$(TD ])
)
$(TR
$(TD $(LPAREN))
$(TD $(RPAREN))
)
$(TR
$(TD <)
$(TD >)
)
$(TR
$(TD {)
$(TD })
)
)
---
q"(foo(xxx))" // "foo(xxx)"
q"[foo{]" // "foo{"
---
$(P If the delimiter is an identifier, the identifier must
be immediately followed by a newline, and the matching
delimiter is the same identifier starting at the beginning
of the line:
)
---
writefln(q"EOS
This
is a multi-line
heredoc string
EOS"
);
---
$(P The newline following the opening identifier is not part
of the string, but the last newline before the closing
identifier is part of the string.
)
$(P Otherwise, the matching delimiter is the same as
the delimiter character:)
---
q"/foo]/" // "foo]"
q"/abc/def/" // error
---
<h4>Token Strings</h4>
$(P Token strings open with the characters $(B q{) and close with
the token $(B }). In between must be valid D tokens.
The $(B {) and $(B }) tokens nest.
The string is formed of all the characters between the opening
and closing of the token string, including comments.
)
---
q{foo} // "foo"
q{/*}*/ } // "/*}*/ "
q{ foo(q{hello}); } // " foo(q{hello}); "
q{ @ } // error, @ is not a valid D token
q{ __TIME__ } // " __TIME__ ", i.e. it is not replaced with the time
q{ __EOF__ } // error, as __EOF__ is not a token, it's end of file
---
)
<h3>$(LNAME2 characterliteral, Character Literals)</h3>
$(GRAMMAR
$(I CharacterLiteral):
$(B ') $(I SingleQuotedCharacter) $(B ')
$(I SingleQuotedCharacter):
$(I Character)
$(I EscapeSequence)
)
Character literals are a single character or escape sequence
enclosed by single quotes, ' '.
<h3>$(LNAME2 integerliteral, Integer Literals)</h3>
$(GRAMMAR
$(GNAME IntegerLiteral):
$(I Integer)
$(I Integer) $(I IntegerSuffix)
$(I Integer):
$(I Decimal)
$(I Binary)
$(I Octal)
$(I Hexadecimal)
$(I IntegerSuffix):
$(B L)
$(B u)
$(B U)
$(B Lu)
$(B LU)
$(B uL)
$(B UL)
$(GNAME Decimal):
$(B 0)
$(I NonZeroDigit)
$(I NonZeroDigit) $(I DecimalDigits)
$(I Binary):
$(B 0b) $(I BinaryDigits)
$(B 0B) $(I BinaryDigits)
$(I Octal):
$(B 0) $(I OctalDigits)
$(I Hexadecimal):
$(B 0x) $(I HexDigits)
$(B 0X) $(I HexDigits)
$(I NonZeroDigit):
$(B 1)
$(B 2)
$(B 3)
$(B 4)
$(B 5)
$(B 6)
$(B 7)
$(B 8)
$(B 9)
$(GNAME DecimalDigits):
$(I DecimalDigit)
$(I DecimalDigit) $(I DecimalDigits)
$(GNAME DecimalDigit):
$(B 0)
$(I NonZeroDigit)
$(B _)
$(I BinaryDigits):
$(I BinaryDigit)
$(I BinaryDigit) $(I BinaryDigits)
$(I BinaryDigit):
$(B 0)
$(B 1)
$(B _)
$(I OctalDigits):
$(I OctalDigit)
$(I OctalDigit) $(I OctalDigits)
$(I OctalDigit):
$(B 0)
$(B 1)
$(B 2)
$(B 3)
$(B 4)
$(B 5)
$(B 6)
$(B 7)
$(B _)
$(I HexDigits):
$(I HexDigit)
$(I HexDigit) $(I HexDigits)
$(I HexDigit):
$(I DecimalDigit)
$(B a)
$(B b)
$(B c)
$(B d)
$(B e)
$(B f)
$(B A)
$(B B)
$(B C)
$(B D)
$(B E)
$(B F)
$(B _)
)
Integers can be specified in decimal, binary, octal, or hexadecimal.
<p>
Decimal integers are a sequence of decimal digits.
<p>
$(LNAME2 binary-literals, Binary integers) are a sequence of binary digits preceded
by a $(SINGLEQUOTE 0b).
<p>
Octal integers are a sequence of octal digits preceded by a $(SINGLEQUOTE 0).
<p>
Hexadecimal integers are a sequence of hexadecimal digits preceded
by a $(SINGLEQUOTE 0x).
<p>
Integers can have embedded $(SINGLEQUOTE _) characters, which are ignored.
The embedded $(SINGLEQUOTE _) are useful for formatting long literals, such
as using them as a thousands separator:
-------------
123_456 // 123456
1_2_3_4_5_6_ // 123456
-------------
Integers can be immediately followed by one $(SINGLEQUOTE L) or one
$(SINGLEQUOTE u) or both.
<p>
The type of the integer is resolved as follows:
<p>
$(TABLE2 Decimal Literal Types,
$(TR
$(TH Decimal Literal)
$(TH Type)
)
$(TR
$(TD 0 .. 2_147_483_647)
$(TD int)
)
$(TR
$(TD 2_147_483_648 .. 9_223_372_036_854_775_807L)
$(TD long)
)
$(TR
$(TH Decimal Literal, L Suffix)
$(TH Type)
)
$(TR
$(TD 0L .. 9_223_372_036_854_775_807L)
$(TD long)
)
$(TR
$(TH Decimal Literal, U Suffix)
$(TH Type)
)
$(TR
$(TD 0U .. 4_294_967_296U)
$(TD uint)
)
$(TR
$(TD 4_294_967_296U .. 18_446_744_073_709_551_615UL)
$(TD ulong)
)
$(TR
$(TH Decimal Literal, UL Suffix)
$(TH Type)
)
$(TR
$(TD 0UL .. 18_446_744_073_709_551_615UL)
$(TD ulong)
)
$(TR
$(TH Non-Decimal Literal)
$(TH Type)
)
$(TR
$(TD 0x0 .. 0x7FFF_FFFF)
$(TD int)
)
$(TR
$(TD 0x8000_0000 .. 0xFFFF_FFFF)
$(TD uint)
)
$(TR
$(TD 0x1_0000_0000 .. 0x7FFF_FFFF_FFFF_FFFF)
$(TD long)
)
$(TR
$(TD 0x8000_0000_0000_0000 .. 0xFFFF_FFFF_FFFF_FFFF)
$(TD ulong)
)
$(TR
$(TH Non-Decimal Literal, L Suffix)
$(TH Type)
)
$(TR
$(TD 0x0L .. 0x7FFF_FFFF_FFFF_FFFFL)
$(TD long)
)
$(TR
$(TD 0x8000_0000_0000_0000L .. 0xFFFF_FFFF_FFFF_FFFFL)
$(TD ulong)
)
$(TR
$(TH Non-Decimal Literal, U Suffix)
$(TH Type)
)
$(TR
$(TD 0x0U .. 0xFFFF_FFFFU)
$(TD uint)
)
$(TR
$(TD 0x1_0000_0000UL .. 0xFFFF_FFFF_FFFF_FFFFUL)
$(TD ulong)
)
$(TR
$(TH Non-Decimal Literal, UL Suffix)
$(TH Type)
)
$(TR
$(TD 0x0UL .. 0xFFFF_FFFF_FFFF_FFFFUL)
$(TD ulong)
)
)
<h3>$(LNAME2 floatliteral, Floating Literals)</h3>
$(GRAMMAR
$(GNAME FloatLiteral):
$(I Float)
$(I Float) $(I Suffix)
$(I Integer) $(I ImaginarySuffix)
$(I Integer) $(I FloatSuffix) $(I ImaginarySuffix)
$(I Integer) $(I RealSuffix) $(I ImaginarySuffix)
$(I Float):
$(I DecimalFloat)
$(I HexFloat)
$(I DecimalFloat):
$(GLINK LeadingDecimal) $(B .)
$(GLINK LeadingDecimal) $(B .) $(I DecimalDigits)
$(I DecimalDigits) $(B .) $(I DecimalDigits) $(I DecimalExponent)
$(B .) $(I Decimal)
$(B .) $(I Decimal) $(I DecimalExponent)
$(GLINK LeadingDecimal) $(I DecimalExponent)
$(I DecimalExponent)
$(B e) $(I DecimalDigits)
$(B E) $(I DecimalDigits)
$(B e+) $(I DecimalDigits)
$(B E+) $(I DecimalDigits)
$(B e-) $(I DecimalDigits)
$(B E-) $(I DecimalDigits)
$(I HexFloat):
$(I HexPrefix) $(I HexDigits) $(B .) $(I HexDigits) $(I HexExponent)
$(I HexPrefix) $(B .) $(I HexDigits) $(I HexExponent)
$(I HexPrefix) $(I HexDigits) $(I HexExponent)
$(I HexPrefix):
$(B 0x)
$(B 0X)
$(I HexExponent):
$(B p) $(I DecimalDigits)
$(B P) $(I DecimalDigits)
$(B p+) $(I DecimalDigits)
$(B P+) $(I DecimalDigits)
$(B p-) $(I DecimalDigits)
$(B P-) $(I DecimalDigits)
$(I Suffix):
$(I FloatSuffix)
$(I RealSuffix)
$(I ImaginarySuffix)
$(I FloatSuffix) $(I ImaginarySuffix)
$(I RealSuffix) $(I ImaginarySuffix)
$(I FloatSuffix):
$(B f)
$(B F)
$(I RealSuffix):
$(B L)
$(I ImaginarySuffix):
$(B i)
$(GNAME LeadingDecimal):
$(GLINK Decimal)
$(B 0) $(GLINK DecimalDigits)
)
Floats can be in decimal or hexadecimal format,
as in standard C.
<p>
Hexadecimal floats are preceded with a $(B 0x) and the
exponent is a $(B p)
or $(B P) followed by a decimal number serving as the exponent
of 2.
<p>
Floating literals can have embedded $(SINGLEQUOTE _) characters, which are ignored.
The embedded $(SINGLEQUOTE _) are useful for formatting long literals to
make them more readable, such
as using them as a thousands separator:
---------
123_456.567_8 // 123456.5678
1_2_3_4_5_6_._5_6_7_8 // 123456.5678
1_2_3_4_5_6_._5e-6_ // 123456.5e-6
---------
Floating literals with no suffix are of type double.
Floats can be followed by one $(B f), $(B F),
or $(B L) suffix.
The $(B f) or $(B F) suffix means it is a
float, and $(B L) means it is a real.
<p>
If a floating literal is followed by $(B i), then it is an