42sh/src/parser/parser.c

58 lines
1.1 KiB
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"
#include "utils/lists/lists.h"
2026-01-15 17:25:21 +01:00
#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();
while (token != NULL && token->type != TOKEN_EOF)
{
switch (token->type)
{
case TOKEN_WORD:
2026-01-15 17:25:21 +01:00
current_node = parse_simple_command();
result_list = list_append(result_list, current_node);
break;
default:
// Forward
token = pop_token();
break;
}
token = peek_token();
}
if (token == NULL)
{
puts("Internal error: cannot get the following token");
2026-01-15 17:25:21 +01:00
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)
{
2026-01-10 19:57:36 +01:00
(void)command;
return NULL;
}