#include "lexer.h" #include "parser.h" #include #include #include void test_print_lexer(void) { char text[] = "abc 123 123.. 0xFF 0b101 .5 1. 3.14 'a' '\\n' \"hello\" " "\"world\\\"\\n\" if else /* /* while */ */ " "while for in // in \n break let match false true not and or fn " "return mut " "defer (){}[],: :: ::< ; & _ . .. ..= ..< += -= *= /= %= == != <= >= " "+ - * / % " "% = ! < >"; printf("text = \"%s\"\n", text); Lexer lexer; lexer_create(&lexer, text, strlen(text)); printf("tokens = [\n"); Token token = lexer_next(&lexer); while (token.type != TokenTypeEof) { char* stringified = token_to_string(&token, text); printf(" %s\n", stringified); free(stringified); token = lexer_next(&lexer); } printf("]\n"); } int main(void) { char text[] = "abc"; Lexer lexer; lexer_create(&lexer, text, strlen(text)); Parser parser; parser_create(&parser, text, &lexer); ParsedExpr* expr = parser_parse_expression(&parser); printf("%d, %s\n", expr->type, expr->id.value); // printf("%d, %ld\n", expr->type, expr->int_value); parsed_expr_free(expr); }