Refactor lexing of fixed-point numbers (#1915)

This incidentally fixes a bug with too-long fixed-point literals
that have precision suffixes.
This commit is contained in:
Rangi
2026-04-06 21:45:34 -04:00
committed by GitHub
parent ede9405daf
commit 11f6278d95
5 changed files with 116 additions and 97 deletions
+6 -2
View File
@@ -8,8 +8,12 @@ println 1.q2
; bad
println 12.34q0
println 12.34q_15
println 12.34q1_5
println 12.34q_15 ; lexes as `12.34q` (invalid) then symbol `_15`
println 12.34q1_5 ; lexes as `12.34q1` (valid) then symbol `_5`
println 1_.2
println 1._2
println 1.__2
println 1.2q
println 1.999_999_999_999_999
println 1.999_999_999_999_999q16
println 1.999_999_999_999_999q.16
+14 -4
View File
@@ -1,6 +1,6 @@
error: Invalid fixed-point constant, no significant digits after 'q'
error: Fixed-point constant precision must be between 1 and 31
at fixed-point-syntax.asm(10)
error: Invalid fixed-point constant, no significant digits after 'q'
error: Invalid fixed-point constant, no digits after 'q'
at fixed-point-syntax.asm(11)
error: syntax error, unexpected symbol
at fixed-point-syntax.asm(11)
@@ -10,6 +10,16 @@ error: Invalid integer constant, trailing '_'
at fixed-point-syntax.asm(13)
error: Invalid fixed-point constant, '_' after '.'
at fixed-point-syntax.asm(14)
error: Invalid fixed-point constant, no significant digits after 'q'
error: Invalid fixed-point constant, '_' after '.'
at fixed-point-syntax.asm(15)
Assembly aborted with 7 errors
error: Invalid fixed-point constant, '_' after another '_'
at fixed-point-syntax.asm(15)
error: Invalid fixed-point constant, no digits after 'q'
at fixed-point-syntax.asm(16)
warning: Precision of fixed-point constant is too large [-Wlarge-constant]
at fixed-point-syntax.asm(17)
warning: Precision of fixed-point constant is too large [-Wlarge-constant]
at fixed-point-syntax.asm(18)
warning: Precision of fixed-point constant is too large [-Wlarge-constant]
at fixed-point-syntax.asm(19)
Assembly aborted with 9 errors
+4
View File
@@ -8,3 +8,7 @@ $C570A
$13333
$13333
$13333
$13333
$10000
$10000
$10000
+1 -1
View File
@@ -20,7 +20,7 @@ warning: Graphics constant is too large; only first 8 pixels considered [-Wlarge
at invalid-numbers.asm::try(2) <- invalid-numbers.asm(22)
warning: Magnitude of fixed-point constant is too large [-Wlarge-constant]
at invalid-numbers.asm::try(2) <- invalid-numbers.asm(23)
error: Invalid fixed-point constant, no significant digits after 'q'
error: Invalid fixed-point constant, no digits after 'q'
at invalid-numbers.asm::try(2) <- invalid-numbers.asm(26)
error: Fixed-point constant precision must be between 1 and 31
at invalid-numbers.asm::try(2) <- invalid-numbers.asm(29)