aboutsummaryrefslogtreecommitdiff
path: root/boot/lexer.ll
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-08-13 22:55:06 +0200
committerEugen Wissner <belka@caraus.de>2026-08-13 22:55:06 +0200
commitbf7416a3ef9f0b787dcaebf816f3f3e6e385ff42 (patch)
tree26359c705133dbd8e98f06483008a720d0dae9d7 /boot/lexer.ll
parentae29de96c94e5c582f4424804464cdd29bf2a013 (diff)
downloadelna-bf7416a3ef9f0b787dcaebf816f3f3e6e385ff42.tar.gz
Implement fixed-size integers
Diffstat (limited to 'boot/lexer.ll')
-rw-r--r--boot/lexer.ll146
1 files changed, 126 insertions, 20 deletions
diff --git a/boot/lexer.ll b/boot/lexer.ll
index e944560..691034a 100644
--- a/boot/lexer.ll
+++ b/boot/lexer.ll
@@ -47,7 +47,9 @@ along with GCC; see the file COPYING3. If not see
ID1 [A-Za-z_]
ID2 [A-Za-z0-9_]
HIGIT [0-9a-fA-F]
+HEXADECIMAL 0[xX]{HIGIT}+
BIGIT [01]
+NATURAL [1-9][[:digit:]]*
%%
%{
@@ -173,55 +175,158 @@ to {
#{ID1}{ID2}* {
return yy::parser::make_TRAIT(yytext + 1, this->location);
}
-[[:digit:]]+u {
- std::uint64_t result = strtoull(yytext, NULL, 10);
-
- if (errno == ERANGE)
+(0|{NATURAL})u|{HEXADECIMAL} {
+ if (auto result = parse_integer<std::uint64_t>(yytext, 0))
+ {
+ return yy::parser::make_WORD(result.value(), this->location);
+ }
+ else
{
REJECT;
}
+}
+(0|{NATURAL}|{HEXADECIMAL})u8 {
+ if (auto result = parse_integer<std::uint8_t>(yytext, 0))
+ {
+ return yy::parser::make_WORD8(result.value(), this->location);
+ }
else
{
- return yy::parser::make_WORD(result, this->location);
+ REJECT;
}
}
-[[:digit:]]+ {
- std::int64_t result = strtoll(yytext, NULL, 10);
-
- if (errno == ERANGE)
+(0|{NATURAL}|{HEXADECIMAL})u16 {
+ if (auto result = parse_integer<std::uint16_t>(yytext, 0))
+ {
+ return yy::parser::make_WORD16(result.value(), this->location);
+ }
+ else
{
REJECT;
}
+}
+(0|{NATURAL}|{HEXADECIMAL})u32 {
+ if (auto result = parse_integer<std::uint32_t>(yytext, 0))
+ {
+ return yy::parser::make_WORD32(result.value(), this->location);
+ }
else
{
- return yy::parser::make_INTEGER(result, this->location);
+ REJECT;
}
}
-0[x|X]{HIGIT}+ {
- std::uint64_t result = strtoull(yytext, NULL, 16);
-
- if (errno == ERANGE)
+(0|{NATURAL}|{HEXADECIMAL})u64 {
+ if (auto result = parse_integer<std::uint64_t>(yytext, 0))
+ {
+ return yy::parser::make_WORD64(result.value(), this->location);
+ }
+ else
{
REJECT;
}
+}
+0|{NATURAL} {
+ if (auto result = parse_integer<std::int64_t>(yytext, 10))
+ {
+ return yy::parser::make_INTEGER(result.value(), this->location);
+ }
else
{
- return yy::parser::make_WORD(result, this->location);
+ REJECT;
}
}
-0[b|B]{BIGIT}+ {
- std::uint64_t result = strtoull(yytext + 2, NULL, 2);
-
- if (errno == ERANGE)
+(0|{NATURAL})i8 {
+ if (auto result = parse_integer<std::int8_t>(yytext, 10))
+ {
+ return yy::parser::make_INTEGER8(result.value(), this->location);
+ }
+ else
{
REJECT;
}
+}
+(0|{NATURAL})i16 {
+ if (auto result = parse_integer<std::int16_t>(yytext, 10))
+ {
+ return yy::parser::make_INTEGER16(result.value(), this->location);
+ }
+ else
+ {
+ REJECT;
+ }
+}
+(0|{NATURAL})i32 {
+ if (auto result = parse_integer<std::int32_t>(yytext, 10))
+ {
+ return yy::parser::make_INTEGER32(result.value(), this->location);
+ }
else
{
- return yy::parser::make_WORD(result, this->location);
+ REJECT;
+ }
+}
+(0|{NATURAL})i64 {
+ if (auto result = parse_integer<std::int64_t>(yytext, 10))
+ {
+ return yy::parser::make_INTEGER64(result.value(), this->location);
+ }
+ else
+ {
+ REJECT;
+ }
+}
+0[bB]{BIGIT}+ {
+ if (auto result = parse_integer<std::uint64_t>(yytext + 2, 2))
+ {
+ return yy::parser::make_WORD(result.value(), this->location);
+ }
+ else
+ {
+ REJECT;
+ }
+}
+0[bB]{BIGIT}+u8 {
+ if (auto result = parse_integer<std::uint8_t>(yytext + 2, 2))
+ {
+ return yy::parser::make_WORD8(result.value(), this->location);
+ }
+ else
+ {
+ REJECT;
+ }
+}
+0[bB]{BIGIT}+u16 {
+ if (auto result = parse_integer<std::uint16_t>(yytext + 2, 2))
+ {
+ return yy::parser::make_WORD16(result.value(), this->location);
+ }
+ else
+ {
+ REJECT;
+ }
+}
+0[bB]{BIGIT}+u32 {
+ if (auto result = parse_integer<std::uint32_t>(yytext + 2, 2))
+ {
+ return yy::parser::make_WORD32(result.value(), this->location);
+ }
+ else
+ {
+ REJECT;
+ }
+}
+0[bB]{BIGIT}+u64 {
+ if (auto result = parse_integer<std::uint64_t>(yytext + 2, 2))
+ {
+ return yy::parser::make_WORD64(result.value(), this->location);
+ }
+ else
+ {
+ REJECT;
}
}
[[:digit:]]+\.[[:digit:]]+([eE][+-]?[[:digit:]]+)? {
+ errno = 0;
double result = strtod(yytext, NULL);
if (errno == ERANGE)
@@ -234,6 +339,7 @@ to {
}
}
[[:digit:]]+[eE][+-]?[[:digit:]]+ {
+ errno = 0;
double result = strtod(yytext, NULL);
if (errno == ERANGE)