scripting: wip number lexing
authorLukas Krickl <lukas@krickl.dev>
Fri, 13 Mar 2026 12:34:37 +0000 (13:34 +0100)
committerLukas Krickl <lukas@krickl.dev>
Fri, 13 Mar 2026 12:34:37 +0000 (13:34 +0100)
README.md
src/l_lsl.c

index 937c5fb19acef43f12552d28b6ed1de7a92ae713..fbd80b70c0f2a80e6b33ccf1bc71d3ccfddb43af 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
 # lrts
 
-lukas' real time strategy.
+lukas' real time simulation.
 
 ## Table of content
 
index 2ae40300da44cfb6627acd87ada19cb54febd4a3..e4c0c316d03e101b50eb5712bca01c04017fc6c2 100644 (file)
@@ -27,6 +27,28 @@ lrts_bool l_lsl_isnum(char c) {
        return c >= '0' && c <= '9';
 }
 
+lrts_bool l_lsl_ishexnum(char c) {
+       return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')
+               || l_lsl_isnum(c);
+}
+
+lrts_bool l_lsl_isbin(char c) {
+       return c == '1' || c == '0';
+}
+
+/* peeks current token */
+#define l_lsl_lex_peek(v, code) \
+       (code)[v->lex_pos]
+
+/* peeks current token and then advances cursor */
+#define l_lsl_lex_consume(v, code)\
+       (code)[v->lex_pos++]
+
+/* advances cursor and then peeks current token */
+#define l_lsl_lex_advance(v, code) \
+       (code)[++v->lex_pos]
+
+
 char tokbuf[L_LSL_TOK_MAX];
 const char* l_lsl_next_token(struct l_lsl_vm *v, const char *code,
                u32 *token_len) {
@@ -34,15 +56,31 @@ const char* l_lsl_next_token(struct l_lsl_vm *v, const char *code,
 
        *token_len = 0;
        
-       c = code[v->lex_pos];
+       c = l_lsl_lex_peek(v, code);
 
        if (l_lsl_isnum(c)) {
                /* decimal number */
                while (l_lsl_isnum(c)) {
                        tokbuf[*token_len] = c;
                        *token_len += 1;
-                       c = code[++v->lex_pos];
+                       c = l_lsl_lex_advance(v, code);
+               }
+       } else if (c == '0') {
+               /* specific base number */
+               c = l_lsl_lex_advance(v, code);
+
+               if (l_lsl_isnum(c)) {
+                       /* octal */
+               } else if (c == 'x') {
+                       /* hex */
+               } else if (c == 'b') {
+                       /* bin */
+               } else {
+                       u_log(U_LOG_CRIT, "unknown number base: 0%c\n", c);
+                       return LRTS_NULL;
                }
+
+
        } else {
                        u_log(U_LOG_CRIT, "unknown char: %c\n", c);
                        return LRTS_NULL;