2026-01-10 19:16:36 +01:00
|
|
|
#include "parser.h"
|
|
|
|
|
|
2026-01-13 16:53:25 +01:00
|
|
|
#include <stdbool.h>
|
2026-01-10 19:16:36 +01:00
|
|
|
#include <stddef.h>
|
2026-01-13 16:53:25 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "lexer/lexer.h"
|
2026-01-15 17:25:21 +01:00
|
|
|
#include "parser/parsing_utils.h"
|
2026-01-17 19:11:55 +01:00
|
|
|
#include "utils/lists/lists.h"
|
2026-01-13 16:53:25 +01:00
|
|
|
|
|
|
|
|
// === Static functions
|
2026-01-14 20:53:47 +01:00
|
|
|
// ...
|
2026-01-13 16:53:25 +01:00
|
|
|
|
|
|
|
|
// === Functions
|
2026-01-10 19:16:36 +01:00
|
|
|
|
|
|
|
|
struct ast *get_ast()
|
|
|
|
|
{
|
2026-01-20 19:54:29 +01:00
|
|
|
struct lexer_context *ctx = calloc(1, sizeof(struct lexer_context));
|
2026-01-16 19:31:58 +01:00
|
|
|
struct token *token = PEEK_TOKEN();
|
2026-01-16 20:27:57 +01:00
|
|
|
struct ast *res;
|
2026-01-14 20:53:47 +01:00
|
|
|
|
2026-01-16 19:31:58 +01:00
|
|
|
if (token->type == TOKEN_EOF)
|
2026-01-13 19:41:37 +01:00
|
|
|
{
|
2026-01-20 19:54:29 +01:00
|
|
|
token = pop_token(ctx);
|
2026-01-16 20:27:57 +01:00
|
|
|
return ast_create_end();
|
2026-01-16 19:31:58 +01:00
|
|
|
}
|
|
|
|
|
else if (token->type == TOKEN_NEWLINE)
|
|
|
|
|
{
|
2026-01-20 19:54:29 +01:00
|
|
|
token = pop_token(ctx);
|
2026-01-16 20:12:29 +01:00
|
|
|
return ast_create_void();
|
2026-01-16 19:31:58 +01:00
|
|
|
}
|
|
|
|
|
else // TOKEN WORD
|
|
|
|
|
{
|
2026-01-20 19:54:29 +01:00
|
|
|
res = parse_list(ctx);
|
2026-01-13 19:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-16 19:31:58 +01:00
|
|
|
/*
|
2026-01-16 20:12:29 +01:00
|
|
|
if (token == NULL)
|
|
|
|
|
{
|
|
|
|
|
puts("Internal error: cannot get the following token");
|
|
|
|
|
puts("Hint: EOF might be missing");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
*/
|
2026-01-20 19:54:29 +01:00
|
|
|
destroy_lexer_context(&ctx);
|
2026-01-13 16:53:25 +01:00
|
|
|
|
2026-01-16 20:27:57 +01:00
|
|
|
return res;
|
2026-01-10 19:16:36 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-13 16:53:25 +01:00
|
|
|
// TODO
|
2026-01-10 19:16:36 +01:00
|
|
|
struct ast *get_ast_str(char *command)
|
|
|
|
|
{
|
2026-01-10 19:57:36 +01:00
|
|
|
(void)command;
|
2026-01-10 19:16:36 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|