词条 | Integer literal |
释义 |
In computer science, an integer literal is a kind of literal for an integer whose value is directly represented in source code. For example, in the assignment statement By contrast, in ParsingRecognizing a string (sequence of characters in the source code) as an integer literal is part of the lexical analysis (lexing) phase, while evaluating the literal to its value is part of the semantic analysis phase. Within the lexer and phrase grammar, the token class is often denoted Integer literals are generally lexed with regular expressions, as in Python.[1] EvaluationAs with other literals, integer literals are generally evaluated at compile time, as part of the semantic analysis phase. In some cases this semantic analysis is done in the lexer, immediately on recognition of an integer literal, while in other cases this is deferred until the parsing stage, or until after the parse tree has been completely constructed. For example, on recognizing the string Once literals have been evaluated, further semantic analysis in the form of constant folding is possible, meaning that literal expressions involving literal values can be evaluated at the compile phase. For example, in the statement AffixesInteger literals frequently have prefixes indicating base, and less frequently suffixes indicating type.[1] For example, in C++ Common prefixes include:
Common suffixes include:
These affixes are somewhat similar to sigils, though sigils attach to identifiers (names), not literals. Digit separatorsIn some languages, integer literals may contain digit separators to allow digit grouping into more legible forms. If this is available, it can usually be done for floating point literals as well. This is particularly useful for bit fields, and makes it easier to see the size of large numbers (such as a million) at a glance by subitizing rather than counting digits. It is also useful for numbers that are typically grouped, such as credit card number or social security numbers.{{efn|Typically sensitive numbers such as these would not be included as literals, however.}} Very long numbers can be further grouped by doubling up separators. Typically decimal numbers (base-10) are grouped in three digit groups (representing one of 1000 possible values), binary numbers (base-2) in four digit groups (one nibble, representing one of 16 possible values), and hexadecimal numbers (base-16) in two digit groups (each digit is one nibble, so two digits are one byte, representing one of 256 possible values). Numbers from other systems (such as id numbers) are grouped following whatever convention is in use. ExamplesIn Ada,[2][3] C# (from version 7.0), D, Eiffel, Haskell (from GHC version 8.6.1),[4] Java (from version 7),[5] Julia, Perl, Python (from version 3.6),[6] Ruby, and Swift,[7] integer literals and float literals can be separated with an underscore ( Examples include: In C++14 (2014), the apostrophe character may be used to separate digits arbitrarily in numeric literals.[8] The underscore was initially proposed, with an initial proposal in 1993,[9] and again for C++11,[10] following other languages. However, this caused conflict with user-defined literals, so the apostrophe was proposed instead, as an "upper comma" (which is used in some other contexts).[11][12] Notes{{notelist}}References1. ^1 "[https://docs.python.org/2/reference/lexical_analysis.html#integer-and-long-integer-literals 2.4.4. Integer and long integer literals]" 2. ^{{cite web |url=http://archive.adaic.com/standards/83lrm/html/lrm-02-04.html#2.4 |title=Ada '83 Language Reference Manual: 2.4. Numeric Literals}} 3. ^{{cite web |url=http://archive.adaic.com/standards/83rat/html/ratl-02-01.html#2.1 |title="Rationale for the Design of the Ada® Programming Language": 2.1 Lexical Structure}} 4. ^{{cite web |url=https://downloads.haskell.org/~ghc/8.6.3/docs/html/users_guide/glasgow_exts.html#numeric-underscores |title=Glasgow Haskell Compiler User's Guide: 11.3.7. Numeric underscores |accessdate=2019-01-31}} 5. ^{{cite web |url=https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html |title=Underscores in Numeric Literals |accessdate=2015-08-12}} 6. ^{{cite web|url=https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep515 |title=What’s New In Python 3.6}} 7. ^{{cite web|url=https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID415 |title=The Swift Programming Language: Lexical Structure}} 8. ^{{cite web|title=N3781 Single-Quotation-Mark as a Digit Separator|url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.pdf|date=25 September 2013|first1=Lawrence|last1=Crowl|first2=Richard|last2=Smith|first3=Jeff|last3=Snyder|first4=Daveed|last4=Vandevoorde}} 9. ^{{cite web |url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1993/N0259.pdf |title=N0259: A Proposal to allow Binary Literals, and some other small changes to Chapter 2: Lexical Conventions. |author=John Max Skaller |date=March 26, 1993}} 10. ^{{cite web |url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2281.html |title=N2281: Digit Separators |date=2007-05-02 |author=Lawrence Crowl}} 11. ^{{cite web |url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3448.pdf |title=N3448: Painless Digit Separation |author=Daveed Vandevoorde |date=2012-09-21}} 12. ^{{cite web |url=http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3499.html |title=N3499: Digit Separators |author=Lawrence Crowl |date=2012-12-19}} 2 : Integers|Source code |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。