mateusfccp / pinto

The pint° programming language
https://mateusfccp.me/pinto
MIT License
5 stars 1 forks source link

Implement number literals #5

Closed mateusfccp closed 1 day ago

mateusfccp commented 3 weeks ago

We currently (main) have implemented the following literals:

For 0.0.4 I want us to also implement number literals (both integer and double literals).

There are still many things to decide about number literals, specially regarding different bases (you can see and contribute to the discussion here). I'm not sure how or when we will solve them, so for this version we will have a limited version of numbers literals, with just support for decimal base (nothing indicating the base), both integer and double, with support for separators.

The grammar is as follows:

<digit>           ::= [0-9]
<digit_separator> ::= "_"
<integer_literal> ::= <digit>+ ( <digit_separator> <digit>+ )*
<double_literal>  ::= <integer_literal> "." <integer_literal>

Some examples:

0100      // int
1094812   // int
100_000   // int
0.100     // double
0.000_001 // double

Notice that, different from Dart, .0 is not a valid double. The prefix has always to include a 0 for double, so 0.5.

The implementation should compile to the equivalent Dart number literal, which is mostly the same.

mateusfccp commented 1 day ago

Solved by #6, I'm not sure why this didn't close automatically.