feat: implement scientific notation parsing for number literals in wren compiler

Add support for parsing scientific notation (e.g., 2.55e2, -2.55e-2) in the
readNumber function of wren_compiler.c. The implementation handles optional
negative exponents, validates that exponent digits follow 'e'/'E', and emits
a lex error for unterminated scientific notation. Also adds comprehensive
test cases covering valid scientific literals, missing exponents, floating
exponents, missing fractional parts, and multiple exponents.
This commit is contained in:
minirop
2015-07-10 16:07:48 +00:00
parent 8d315517e5
commit dba104a696
9 changed files with 32 additions and 3 deletions
-1
View File
@@ -6,5 +6,4 @@ IO.print(-0) // expect: -0
IO.print(123.456) // expect: 123.456
IO.print(-0.001) // expect: -0.001
// TODO: Scientific notation?
// TODO: Literals at and beyond numeric limits.
@@ -0,0 +1 @@
var x = 1.2e // expect error
@@ -0,0 +1 @@
var x = 1.2e3.4 // expect error
@@ -0,0 +1,9 @@
var x = 2.55e2
IO.print(x) // expect: 255
IO.print(x + 1) // expect: 256
IO.print(x == 255) // expect: true
IO.print(2.55e-2 is Num) // expect: true
IO.print(x is Num) // expect: true
IO.print(-2.55e2) // expect: -255
IO.print(-25500e-2) // expect: -255
@@ -0,0 +1 @@
var x = 1e // expect error
@@ -0,0 +1 @@
var x = 1.e // expect runtime error: Num does not implement 'e'.
@@ -0,0 +1 @@
var x = 1.2e3e4 // expect error