Skip to content

HexFloatLiterals - #500

Open
ijouw wants to merge 7 commits into
augustss:masterfrom
ijouw:hexfloatparse
Open

HexFloatLiterals#500
ijouw wants to merge 7 commits into
augustss:masterfrom
ijouw:hexfloatparse

Conversation

@ijouw

@ijouw ijouw commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Allow more numerical literals.
Allow non-decimal dot:

0x1.1 = 1*16^0 + 1*16^(-1) = 1 + 1/16 = 1.0625
  1.1 = 1*10^0 + 1*10^(-1) = 1 + 1/10 = 1.1
0o1.1 = 1*8 ^0 + 1*8 ^(-1) = 1 + 1/8  = 1.125
0b1.1 = 1*2 ^0 + 1*2 ^(-1) = 1 + 1/2  = 1.5

Allow non-decimal scientific notation (using e):

  2e1 = 2*10^  1
0b1e1 = 1*2 ^0b1
0o2e1 = 2*8 ^0o1

Introduce new scientific notation using p instead of e (s.t it does not conflict with hex 0xe = 14). Note that following HexFloatLiterals, the exponent is always base10.

  3p1 = 2*2^1
0x3p1 = 3*2^1
0o3p1 = 3*2^1
0b1p3 = 1*2^3

Comment thread src/MicroHs/Lex.hs Outdated
(Right q, len, rs) -> TRat loc q : lexSkipHash (addCol loc (2+len)) rs
| toLower x == 'b' = case readNumBin cs of
(Left n, len, rs) -> TInt loc n : lexSkipHash (addCol loc (2+len)) rs
(Right q, len, rs) -> TRat loc q : lexSkipHash (addCol loc (2+len)) rs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all the branches do the same thing, refactor the common code.
It's probably best to get rid of return Left/Right and just have readNum return the right thing.

The reason I'm picky about this is that the performance of the lexer is important.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readNum now outputs [Token]

Comment thread src/MicroHs/Lex.hs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants