chharvey / counterpoint

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

Cook Integer Literals #3

Closed chharvey closed 4 years ago

chharvey commented 4 years ago

Compute the mathematical value of an integer literal token, a sequence of decimal digits 0-9.

IntegerLiteral ::= DigitSequenceDec

DigitSequenceDec ::= DigitSequenceDec? [0-9]
MV(DigitSequenceDec ::= [0-9])
    is MV([0-9])
MV(DigitSequenceDec ::= DigitSequenceDec [0-9])
    is 10 * MV(DigitSequenceDec) + MV([0-9])
MV([0-9] ::= "0") is 0
MV([0-9] ::= "1") is 1
MV([0-9] ::= "2") is 2
MV([0-9] ::= "3") is 3
MV([0-9] ::= "4") is 4
MV([0-9] ::= "5") is 5
MV([0-9] ::= "6") is 6
MV([0-9] ::= "7") is 7
MV([0-9] ::= "8") is 8
MV([0-9] ::= "9") is 9

Send the mathematical value of the token along with it to the parser, which in turn will send it down the pipeline to be evaluated.

Do not use JavaScript’s built-in parseInt(), as the compiler should be language-agnostic.

chharvey commented 4 years ago

commit f90c4dd closes this