Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Parsing numbers #59

Open
PavelVozenilek opened this issue Apr 17, 2020 · 0 comments
Open

Parsing numbers #59

PavelVozenilek opened this issue Apr 17, 2020 · 0 comments

Comments

@PavelVozenilek
Copy link

Looking on parsing numbers in lex.cpp, I have few notes:

  1. Octal numbers are relic of the ancient past. I think it was a PDP computer which used them regularly last time.

    Walter Bright, author of the D language recently talked, how having them in his language was mistake (here at 12:14 https://youtu.be/p22MM1wc7xQ?t=734 ). D allows leading zeros, making things more bug prone.

  2. It would improve readability, if it was possible to insert a visual separator between the numerals, e.g. underscore _:
    132_780, 0xFF60_88A1_73E9_6620, 0b0110_1110

    The separator could be single quote ', as they do it in India; or minus -, if math operators require space before and after. (This would also allow to use - in names, making them more readable.)

  3. Binary and hex numbers should always have size 1, 2, 4, or 8 bytes (filled with leading zeros, if needed). People are not used to read/write them, it is much easier to make a mistake here. Possible separator inside these numbers should preferably be also on these boundaries. If binary/hex is assigned to a known sized integer, the whole sized number should be written.

  4. A bug. This code accepts integer value out of its range (has to be negative, overflow of positives is checked):

    void main() {
        int8 a = -0xFFFF;
        println(a); 
    }
    
    
  5. Scientific float notation could be supported.

  6. Hex notation for floats could be supported, to make precise values and NaNs.

  7. In lex.ccp, function Lexer::readNumber(), I was surprised to see the name end to be used as both a local identifier and as a label. It is a bit confusing to see such a (valid by standard) trick.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant