feat: finished the new firsts system and began supporting redirections
This commit is contained in:
parent
32f56beb6b
commit
3ee4a0b9ca
4 changed files with 134 additions and 44 deletions
|
|
@ -1,6 +1,8 @@
|
|||
#include "grammar_advanced.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "grammar_basic.h"
|
||||
|
||||
|
|
@ -10,6 +12,12 @@ struct ast *parse_redirection(struct lexer_context *ctx)
|
|||
if (token->type == TOKEN_IONUMBER)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
int io_number = -1;
|
||||
if (token->type == TOKEN_IONUMBER)
|
||||
{
|
||||
io_number = atoi(token->data);
|
||||
POP_TOKEN();
|
||||
token = PEEK_TOKEN();
|
||||
}
|
||||
|
|
@ -20,6 +28,20 @@ struct ast *parse_redirection(struct lexer_context *ctx)
|
|||
"else");
|
||||
return NULL;
|
||||
}
|
||||
char *redir_op = strdup(token->data);
|
||||
POP_TOKEN();
|
||||
|
||||
token = PEEK_TOKEN();
|
||||
if (token->type != TOKEN_WORD)
|
||||
{
|
||||
puts("Syntax error: expected a word after redirection");
|
||||
free(redir_op);
|
||||
return NULL;
|
||||
}
|
||||
char *target = strdup(token->data);
|
||||
POP_TOKEN();
|
||||
|
||||
return ast_create_redir(io_number, redir_op, target);
|
||||
}
|
||||
|
||||
struct ast *parse_prefix(struct lexer_context *ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue