42sh/src/parser/parser.c

70 lines
1.2 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"
// === Static functions
/* Returns true if c is a command terminator, false otherwise
*/
static bool isterminator(char c)
{
switch (c)
{
case '\n':
case ';':
case EOF:
return true;
default:
return false;
}
}
/* Parses a simple list of words (command and arguments)
* and returns the resulting ast
*/
static struct ast *parse_simple_command(void)
{
struct list *cmd_elements = NULL;
char *token = get_token();
if (token == NULL) // just in case ?
return NULL;
while (token != NULL && !isterminator(token[0]))
{
cmd_elements = list_append(cmd_elements, token);
token = get_token();
}
if (token == NULL)
return NULL; // TODO handle error
struct ast *result = ast_create_cmd(cmd_elements);
return result;
}
// === Functions
struct ast *get_ast()
{
struct ast *result = NULL;
struct ast *current_node = NULL;
// char *token = get_token();
return result;
}
// TODO
struct ast *get_ast_str(char *command)
{
2026-01-10 19:57:36 +01:00
(void)command;
return NULL;
}