sic

The sic programming language
Log | Files | Refs

commit 22431dde6c27500c87b65711292996a44855c5ff
parent fd51bdc72f09644fdae4c3c3345798db6b18e1e1
Author: keyle <keyle@capsule.org>
Date:   Sat,  9 May 2026 19:53:00 +1000

lexer wip

Diffstat:
Msrc/common.h | 21++++++++++++++-------
Msrc/lexer.c | 10++++++----
Msrc/lexer.h | 2+-
Msrc/main.c | 10+++++-----
4 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/src/common.h b/src/common.h @@ -1,5 +1,8 @@ #pragma once +#include <stdbool.h> +#include <stddef.h> + typedef enum TokenType { TERMINUS = 4, IDENT, @@ -50,17 +53,21 @@ typedef struct Token { union Value { char* as_string; char as_char; - int as_int; - int as_bool; - } Value; + size_t as_int; + bool as_bool; + } value; const char* path; const char* filename; - int line; - int col; + size_t line; + size_t col; } Token; typedef struct Lexer { + const char* code; + const char* path; + const char* filename; + size_t pos; Token* tokens; - int count; - int cap; + size_t count; + size_t cap; } Lexer; diff --git a/src/lexer.c b/src/lexer.c @@ -1,8 +1,10 @@ +#include "lexer.h" #include <stdio.h> #include <stdlib.h> -#include "lexer.h" -Token* lex(const char* code, const char* path, const char* filename) { - Token* tokens = calloc(250, sizeof(Token)); - return tokens; +Lexer* add_token(Lexer* l, Token); + +Lexer* lex(Lexer* l) { + l->tokens = calloc(250, sizeof(Token)); + return l; } diff --git a/src/lexer.h b/src/lexer.h @@ -2,4 +2,4 @@ #include "common.h" -Lexer* lex(const char* code, const char* path, const char* filename); +Lexer* lex(Lexer* lexer); diff --git a/src/main.c b/src/main.c @@ -1,16 +1,16 @@ -#include <stdio.h> #include "utils.h" +#include <stdio.h> int main(int argc, char** args) { - if (argc < 1) return 1; + if (argc < 1) + return 1; char* filename = args[1]; - printf("hello, meh: %s\n", filename); char* contents = read_file(filename); - if (contents == NULL) return 1; + if (contents == NULL) + return 1; printf("%s\n", contents); - // TODO load file // TODO parse the content through a scanner return 0; }