Справочник по Ada (Ada 2022)
4.2 Литералы
A literal represents a value literally, that is, by means of notation suited to its kind. A literal is either a numeric_literal, a character_literal, the literal null, or a string_literal.
Правила разрешения имен
Этот абзац был удалён.
For a name that consists of a character_literal, either its expected type shall be a single character type, in which case it is interpreted as a parameterless function_call that yields the corresponding value of the character type, or its expected profile shall correspond to a parameterless function with a character result type, in which case it is interpreted as the name of the corresponding parameterless function declared as part of the character type's definition (see 3.5.1). In either case, the character_literal denotes the enumeration_literal_specification.
The expected type for a primary that is a string_literal shall be a single string type or a type with a specified String_Literal aspect (see 4.2.1). In either case, the string_literal is interpreted to be of its expected type. If the expected type of an integer literal is a type with a specified Integer_Literal aspect (see 4.2.1), the literal is interpreted to be of its expected type; otherwise it is interpreted to be of type universal_integer. If the expected type of a real literal is a type with a specified Real_Literal aspect (see 4.2.1), it is interpreted to be of its expected type; otherwise, it is interpreted to be of type universal_real.
Правила легальности
A character_literal that is a name shall correspond to a defining_character_literal of the expected type, or of the result type of the expected profile.
If the expected type for a string_literal is a string type, then for each character of the string_literal there shall be a corresponding defining_character_literal of the component type of the expected string type.
Этот абзац был удалён.
Статическая семантика
The literal null is of type universal_access.
Динамическая семантика
If its expected type is a numeric type, the evaluation of a numeric literal yields the represented value. In other cases, the effect of evaluating a numeric literal is determined by the Integer_Literal or Real_Literal aspect that applies (see 4.2.1).
The evaluation of the literal null yields the null value of the expected type.
The evaluation of a string_literal that is a primary and has an expected type that is a string type, yields an array value containing the value of each character of the sequence of characters of the string_literal, as defined in 2.6. The bounds of this array value are determined according to the rules for positional_array_aggregates (see 4.3.3), except that for a null string literal, the upper bound is the predecessor of the lower bound. In other cases, the effect of evaluating a string_literal is determined by the String_Literal aspect that applies (see 4.2.1).
For the evaluation of a string_literal of a string type T, a check is made that the value of each character of the string_literal belongs to the component subtype of T. For the evaluation of a null string literal of a string type, a check is made that its lower bound is greater than the lower bound of the base range of the index type. The exception Constraint_Error is raised if either of these checks fails.
ПРИМЕЧАНИЕ Литералы перечислений, которые являются идентификаторами, а не character_literals, следуют стандартным правилам для идентификаторов, когда используются в имени (см. 4.1 и 4.1.3). Character_literals used as selector_names follow the normal rules for expanded names (see 4.1.3).
Примеры
Примеры литералов:
3.14159_26536 -- вещественный литерал
1_345 -- целочисленный литерал
'A' -- литерал символа
"Некоторые Текст" -- строковый литерал
1_345 -- целочисленный литерал
'A' -- литерал символа
"Некоторые Текст" -- строковый литерал