54 lines
966 B
C
54 lines
966 B
C
#include "parser.h"
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "lexer/lexer.h"
|
|
#include "parser/parsing_utils.h"
|
|
#include "utils/lists/lists.h"
|
|
|
|
// === Static functions
|
|
// ...
|
|
|
|
// === Functions
|
|
|
|
struct ast *get_ast(struct lexer_context *ctx)
|
|
{
|
|
struct token *token = PEEK_TOKEN();
|
|
struct ast *res;
|
|
|
|
if (token->type == TOKEN_EOF)
|
|
{
|
|
token = pop_token(ctx);
|
|
return ast_create_end();
|
|
}
|
|
else if (token->type == TOKEN_NEWLINE)
|
|
{
|
|
token = pop_token(ctx);
|
|
return ast_create_void();
|
|
}
|
|
else // TOKEN WORD
|
|
{
|
|
res = parse_list(ctx);
|
|
}
|
|
|
|
/*
|
|
if (token == NULL)
|
|
{
|
|
puts("Internal error: cannot get the following token");
|
|
puts("Hint: EOF might be missing");
|
|
return NULL;
|
|
}
|
|
*/
|
|
return res;
|
|
}
|
|
|
|
// TODO
|
|
struct ast *get_ast_str(char *command)
|
|
{
|
|
(void)command;
|
|
return NULL;
|
|
}
|