aboutsummaryrefslogtreecommitdiff
path: root/boot/lexer.ll
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-08-21 00:05:03 +0200
committerEugen Wissner <belka@caraus.de>2026-08-21 00:05:03 +0200
commit39269cc68a32f6e1a7524b00da36a1fe4cc7fb8b (patch)
tree9558cd6107d60e22127faeddbdeac5031ee2fdbe /boot/lexer.ll
parent4f77ad5d019618893c59a0f8d5bfa6b98e50a3be (diff)
downloadelna-39269cc68a32f6e1a7524b00da36a1fe4cc7fb8b.tar.gz
Implement Single and Double floats
Diffstat (limited to 'boot/lexer.ll')
-rw-r--r--boot/lexer.ll26
1 files changed, 7 insertions, 19 deletions
diff --git a/boot/lexer.ll b/boot/lexer.ll
index 888c17d..eb1bbd3 100644
--- a/boot/lexer.ll
+++ b/boot/lexer.ll
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
} while (0);
#include <sstream>
+#include <cmath>
#include "parser.hh"
#undef YY_DECL
@@ -50,6 +51,7 @@ HIGIT [0-9a-fA-F]
HEXADECIMAL 0[xX]{HIGIT}+
BIGIT [01]
NATURAL [1-9][[:digit:]]*
+EXPONENT [eE][+-]?[[:digit:]]+
%%
%{
@@ -325,31 +327,17 @@ to {
REJECT;
}
}
-[[:digit:]]+\.[[:digit:]]+([eE][+-]?[[:digit:]]+)? {
+[[:digit:]]+(\.[[:digit:]]+{EXPONENT}?|{EXPONENT}) {
errno = 0;
double result = strtod(yytext, NULL);
- if (errno == ERANGE)
- {
- REJECT;
- }
- else
- {
- return yy::parser::make_FLOAT(result, this->location);
- }
+ return yy::parser::make_DOUBLE(result, this->location);
}
-[[:digit:]]+[eE][+-]?[[:digit:]]+ {
+[[:digit:]]+(\.[[:digit:]]+{EXPONENT}?|{EXPONENT})f {
errno = 0;
- double result = strtod(yytext, NULL);
+ float result = strtof(yytext, NULL);
- if (errno == ERANGE)
- {
- REJECT;
- }
- else
- {
- return yy::parser::make_FLOAT(result, this->location);
- }
+ return yy::parser::make_SINGLE(result, this->location);
}
'([^'\\\n]|\\.|\\\n)+' {
std::optional<std::uint8_t> result = parse_byte_literal(yytext);