42sh/src/parser/parser.c

55 lines
966 B
C
Raw Normal View History

#include "parser.h"
#include <stdbool.h>
#include <stddef.h>
#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"
#include "utils/lists/lists.h"
// === Static functions
// ...
// === Functions
2026-01-20 20:32:59 +01:00
struct ast *get_ast(struct lexer_context *ctx)
{
struct token *token = PEEK_TOKEN();
2026-01-16 20:27:57 +01:00
struct ast *res;
if (token->type == TOKEN_EOF)
{
token = pop_token(ctx);
2026-01-16 20:27:57 +01:00
return ast_create_end();
}
else if (token->type == TOKEN_NEWLINE)
{
token = pop_token(ctx);
2026-01-16 20:12:29 +01:00
return ast_create_void();
}
else // TOKEN WORD
{
res = parse_list(ctx);
}
/*
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-16 20:27:57 +01:00
return res;
}
// TODO
struct ast *get_ast_str(char *command)
{
2026-01-10 19:57:36 +01:00
(void)command;
return NULL;
}