From 1e07cecafc62d18ba05f21101e13b131a10e8c45 Mon Sep 17 00:00:00 2001 From: Mel Date: Wed, 21 May 2025 16:19:59 +0200 Subject: Basic expression parser with operator precedence and associativity Signed-off-by: Mel --- boot/catboot.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'boot/catboot.c') diff --git a/boot/catboot.c b/boot/catboot.c index fec47c0..23b649e 100644 --- a/boot/catboot.c +++ b/boot/catboot.c @@ -23,6 +23,7 @@ #include "common.c" #include "lex.c" #include "tree.c" +#include "parse.c" const ascii* read_file(const ascii* path) @@ -57,10 +58,27 @@ main(const int32 argc, const ascii* argv[]) lexer_new(&lexer, source); struct Token token; + printf("tokens: "); do { token = lexer_next(&lexer); printf("%s ", token_kind_to_string(token.kind)); } while (token.kind != TOKEN_END_OF_FILE); + printf("\n"); + + // reset lexer + lexer_new(&lexer, source); + + struct Parser parser; + parser_new(&parser, &lexer); + + struct Parser_Error parser_error = parser_error_none(); + struct Tree tree = parser_do_your_thing(&parser, &parser_error); + if (!parser_error_is_none(&parser_error)) { + printf("parser error: %s\n", parser_error_to_string(&parser_error)); + return EXIT_FAILURE; + } + + tree_print(&tree); return EXIT_SUCCESS; } -- cgit 1.4.1