42sh/src/parser/parser.c
2026-01-16 19:31:58 +01:00

63 lines
1.2 KiB
C

#include "parser.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lexer/lexer.h"
#include "utils/lists/lists.h"
#include "parser/parsing_utils.h"
// === Static functions
// ...
// === Functions
struct ast *get_ast()
{
// struct list *result_list = NULL;
// struct ast *current_node = NULL;
struct token *token = PEEK_TOKEN();
if (token->type == TOKEN_EOF)
{
token = pop_token();
// TODO
// return ast END.
}
else if (token->type == TOKEN_NEWLINE)
{
token = pop_token();
// TODO
// return ast EMPTY.
}
else // TOKEN WORD
{
// TODO
// call parse_list
current_node = parse_simple_command();
result_list = list_append(result_list, current_node);
}
/*
if (token == NULL)
{
puts("Internal error: cannot get the following token");
puts("Hint: EOF might be missing");
return NULL;
}
*/
struct ast *result = ast_create_list(result_list);
return result;
}
// TODO
struct ast *get_ast_str(char *command)
{
(void)command;
return NULL;
}