Skip to content

"Values" text about integer literals disagree with grammar #515

Description

@lrhn

The text states:

We only support positive, decimal integer literals; negative integers are produced by the unary negation operator.

The grammar is:

INT_LIT ::= -? DIGIT+ | -? 0x HEXDIGIT+

which includes the minus sign in the grammar and accepts hexadecimal literals.

It makes a difference whether -1.abs() is parsed as -(1.abs()) or (-1).abs(), and . binds tighter than prefix -,
so one might want the - to be included in the grammar, if there is, or can be, functions on integers.
(It has other issues to do that, though, so I understand why the text wants to say that the sign is not part of the literal, and is just the normal unary minus operator.)

The grammar also continues:

UINT_LIT ::= INT_LIT [uU]

which reused INT_LIT, which means -42u is an unsigned integer literal. That's probably not desirable.
(There is no specification of which value a literal has, because it's "obvious", but if -42u is an unsigned literal, it's not obvious which unsigned value that has.)

Maybe this would be more practical:

INT_NUMERAL ::= DIGIT+ | 0x HEXDIGIT+
INT_LIT ::= -? INT_NUMERAL
UINT_LIT ::= INT_NUMERAL [uU]

In any case, the text should not say that there are only decimal literals, when there are hexadecimal ones, and it should decide whether they have a leading - as part of the grammar or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions