commit b243ff1b9a3707ef37dab4cc5e135aef8bd4aa3e
parent 3b3b54d12dc4973505371b5b28a7a577c4211a88
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Wed, 10 Dec 2025 11:55:10 +0000
started work on floats
Diffstat:
5 files changed, 34 insertions(+), 19 deletions(-)
diff --git a/lexer.c b/lexer.c
@@ -12,8 +12,18 @@ lexErr(lex *l) {
exit(1);
}
+double
+lexFloat(lex *l) {
+ l->prev = l->ptr;
+ char *end = NULL;
+ double n = strtold(l->ptr, &end);
+ l->ptr = end;
+ return n;
+}
+
uint64_t
lexNum(lex *l) {
+ l->prev = l->ptr;
char *end = NULL;
uint64_t n = strtoll(l->ptr, &end, 0);
l->ptr = end;
@@ -75,6 +85,10 @@ next(lex *l) {
} else if (isdigit(*l->ptr)) {
t.op = INT;
t.n = lexNum(l);
+ if (*l->ptr == '.') {
+ unlex(l);
+ t.f = lexFloat(l);
+ }
} else if (isalpha(*l->ptr)) {
t.op = NAME;
t.name = lexName(l);
diff --git a/lexer.h b/lexer.h
@@ -8,7 +8,6 @@
enum lex_ops {
NOP = 0,
- INT = -1,
ADD = '+',
SUB = '-',
MUL = '*',
@@ -23,6 +22,8 @@ enum lex_ops {
COMMA = ',',
FUNC = 256,
NEGATE,
+ INT,
+ FLOAT,
NAME,
WALRUS,
};
@@ -31,6 +32,7 @@ typedef struct tok {
enum lex_ops op;
union {
int64_t n;
+ double f;
char *name;
};
} tok;
diff --git a/parse.c b/parse.c
@@ -131,8 +131,6 @@ parsebin(tok *start, tok *end, tok *lowest, mctx *ctx) {
return NULL;
}
- // I think this is the spot!
-
e->op = lowest->op;
e->expr[0] = parserexpr(start, &lowest[-1], ctx);
e->expr[1] = parserexpr(&lowest[1], end, ctx);
@@ -151,7 +149,8 @@ parserexpr(tok *start, tok *end, mctx *ctx) {
/* binary ops */
else e = parsebin(start, end, lowest, ctx);
-
+
+ /* TODO something here that sets the type of an rexpr */
return e;
}
diff --git a/parse.h b/parse.h
@@ -14,8 +14,18 @@ enum type_types {
BASIC,
};
+typedef struct type {
+ enum type_types type;
+ union {
+ struct { /* basic types */
+ char *name;
+ };
+ };
+} type;
+
typedef struct rexpr {
enum lex_ops op;
+ type *type;
union {
struct { /* unary ops */
struct rexpr *e;
@@ -23,21 +33,12 @@ typedef struct rexpr {
struct { /* operators */
struct rexpr *expr[2];
};
- struct { /* litterals */
- uint64_t n;
- };
+ /* litterals */
+ uint64_t n;
+ double f;
};
} rexpr;
-typedef struct type {
- enum type_types type;
- union {
- struct { /* basic types */
- char *name;
- };
- };
-} type;
-
typedef struct lexpr {
enum lexpr_ops op;
union {
diff --git a/test.spl b/test.spl
@@ -1,4 +1,3 @@
-func main(arg1 i32) i32 {
- a i64 = (5 * 2) + 4;
- a = 0;
+func main() i32 {
+ i i32 = 50;
}