2026-01-24 15:34:10 +01:00
|
|
|
#include "grammar_advanced.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2026-01-24 16:13:16 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2026-01-24 15:34:10 +01:00
|
|
|
|
|
|
|
|
#include "grammar_basic.h"
|
|
|
|
|
|
2026-01-27 16:17:40 +01:00
|
|
|
static enum ast_redir_type redir_tok_to_ast_type(enum token_type tok_type)
|
|
|
|
|
{
|
|
|
|
|
switch(tok_type)
|
|
|
|
|
{
|
|
|
|
|
case TOKEN_REDIR_LEFT:
|
|
|
|
|
return AST_REDIR_TYPE_LESS;
|
|
|
|
|
case TOKEN_REDIR_RIGHT:
|
|
|
|
|
return AST_REDIR_TYPE_GREAT;
|
|
|
|
|
// TODO finish this
|
|
|
|
|
default:
|
|
|
|
|
return AST_REDIR_TYPE_NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-27 16:05:11 +01:00
|
|
|
|
2026-01-24 15:34:10 +01:00
|
|
|
struct ast *parse_redirection(struct lexer_context *ctx)
|
|
|
|
|
{
|
2026-01-27 18:00:59 +01:00
|
|
|
(void)ctx;
|
|
|
|
|
return NULL;
|
|
|
|
|
/*
|
2026-01-24 15:34:10 +01:00
|
|
|
struct token *token = PEEK_TOKEN();
|
2026-01-24 16:13:16 +01:00
|
|
|
int io_number = -1;
|
|
|
|
|
if (token->type == TOKEN_IONUMBER)
|
|
|
|
|
{
|
|
|
|
|
io_number = atoi(token->data);
|
2026-01-24 15:34:10 +01:00
|
|
|
POP_TOKEN();
|
|
|
|
|
token = PEEK_TOKEN();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-27 16:05:11 +01:00
|
|
|
if (!is_token_redir(token))
|
2026-01-24 15:34:10 +01:00
|
|
|
{
|
2026-01-27 16:05:11 +01:00
|
|
|
perror("Syntax error: expected a redirection token but got something "
|
2026-01-24 15:34:10 +01:00
|
|
|
"else");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2026-01-27 16:05:11 +01:00
|
|
|
// char *redir_op = strdup(token->data);
|
2026-01-27 16:17:40 +01:00
|
|
|
|
|
|
|
|
enum ast_redir_type redir_type = redir_tok_to_ast_type(token->type);
|
2026-01-24 16:13:16 +01:00
|
|
|
POP_TOKEN();
|
|
|
|
|
|
|
|
|
|
token = PEEK_TOKEN();
|
|
|
|
|
if (token->type != TOKEN_WORD)
|
|
|
|
|
{
|
2026-01-27 16:05:11 +01:00
|
|
|
perror("Syntax error: expected a word after redirection");
|
|
|
|
|
// free(redir_op);
|
2026-01-24 16:13:16 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
char *target = strdup(token->data);
|
|
|
|
|
POP_TOKEN();
|
|
|
|
|
|
2026-01-27 16:17:40 +01:00
|
|
|
return ast_create_redir(io_number, redir_type, target);
|
2026-01-27 18:00:59 +01:00
|
|
|
*/
|
2026-01-24 15:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ast *parse_prefix(struct lexer_context *ctx)
|
|
|
|
|
{
|
|
|
|
|
return parse_redirection(ctx);
|
|
|
|
|
}
|