feat: suport for the new lexer and if/else structures

This commit is contained in:
Guillem George 2026-01-14 20:53:47 +01:00
parent e9d702efb4
commit 80e4b6c2fd
3 changed files with 194 additions and 46 deletions

View file

@ -10,25 +10,7 @@
#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
*/
// ...
// === Functions
@ -37,19 +19,29 @@ struct ast *get_ast()
struct list *result_list = NULL;
struct ast *current_node = NULL;
char *token = peek_token();
if (token != NULL)
struct token *token = peek_token();
while (token != NULL && token->type != TOKEN_EOF)
{
switch (token->type)
{
case TOKEN_WORD:
struct ast *cmd = parse_simple_command();
result_list = list_append(result_list, cmd);
break;
default:
// Forward
token = pop_token();
break;
}
}
if (token == NULL)
{
puts("Internal error: cannot get the following token");
return NULL;
}
while (token[0] != EOF)
{
struct ast *cmd = parse_simple_command();
result_list = list_append(result_list, cmd);
}
struct ast *result = ast_create_list(result_list);
return result;
}