diff options
| author | hachem <im@hachem.wtf> | 2026-08-30 03:32:51 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-30 03:32:51 +0200 |
| commit | 5767110816ca9452ef77d15245d1a747bfdd896b (patch) | |
| tree | 1f7e5dec5f1fb4fe7a53c1c81f94043ba7db5676 /src/main.c | |
| parent | 6a6e79cb233e795b78c9ec750dbae9d26bd51654 (diff) | |
add: top level parser
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -1,8 +1,10 @@ #include <stdio.h> +#include <stddef.h> #include "io/file.h" #include "cli/args.h" #include "lexer/lexer.h" +#include "parser/parser.h" int main(int argc, char** argv) { @@ -20,14 +22,22 @@ int main(int argc, char** argv) struct Lexer lexer = create_lexer(source.data); - for (;;) + struct Program program; + if (!parse_program(&lexer, &program)) { - struct Token token = scan_token(&lexer); - printf("%4u %-14s %.*s\n", token.line, token_type_name(token.type), (int)token.length, token.start); - if (token.type == TOKEN_EOF) - break; + free_program(&program); + free_file(&source); + return 1; + } + + for (size_t i = 0; i < program.const_count; i += 1) + { + struct ConstDecl decl = program.consts[i]; + printf("const %.*s = %.*s\n", + (int)decl.name.length, decl.name.start, + (int)decl.value.length, decl.value.start); } + free_program(&program); free_file(&source); - return 0; } |
