matemateak/src/main.c
2023-03-24 01:47:38 +01:00

31 lines
777 B
C

#include "lexer.h"
#include "parser.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char* text = "2 * (3 + 4)";
Lexer lexer1;
lexer(&lexer1, text, strlen(text));
Token current_token = lexer_next(&lexer1);
printf("tokens = [\n");
while (current_token.type != TokenTypeEof) {
char* token_string = token_to_string(&current_token, text);
printf(" %s,\n", token_string);
free(token_string);
current_token = lexer_next(&lexer1);
}
printf("]\n");
Lexer lexer2;
lexer(&lexer2, text, strlen(text));
Expr* ast = parse(&lexer2, text, strlen(text));
char* ast_string = expr_to_string(ast);
printf("ast = %s\n", ast_string);
free(ast_string);
free_expr(ast);
}