chharvey / counterpoint

A robust programming language.
GNU Affero General Public License v3.0
2 stars 0 forks source link

Lexical Grammar: Numeric Separators for Integers #10

Closed chharvey closed 4 years ago

chharvey commented 4 years ago

Allow numeric separators between digits in integer literals.

DigitSequenceDec ::= (DigitSequenceDec "_"?)? [0-9]
MV(DigitSequenceDec ::= DigitSequenceDec "_"? [0-9])
    is 10 * MV(DigitSequenceDec) + MV([0-9])

A numeric separator is a non-digit character allowed to appear in integer literal syntax to improve readability. They do not add/remove any semantics or change any values; they are only a writing tool.

The underscore _ is the symbol used as the numeric separator. Underscores can be placed in integer literals to separate groups of digits in the literal, as a comma or full stop would be used in some written languages.

Examples:

Numeric separators may not be adjacent to each other, nor may they appear at the start or end of the literal. The following tokens are not well-formed and should fail lexical analysis (a lexical error should be thrown):

There are future plans to include identifiers, which may begin with an underscore. Thus while the token _123123 is not an integer literal (having the value 123,123), it will be a well-formed token representing an identifier.

chharvey commented 4 years ago

commit 6046919 closes this