This commit is contained in:
Loic Deridder
2025-02-12 13:48:54 +01:00
parent 256724e601
commit 3ac1625f5a
12 changed files with 89 additions and 61 deletions

View File

@@ -13,6 +13,8 @@
#ifndef AST_H
# define AST_H
# include <unistd.h>
typedef struct s_node t_node;
typedef struct s_msh t_msh;
@@ -50,7 +52,7 @@ typedef struct s_ast_n
int _stdin;
int save_stdo;
int save_stdi;
t_redir *redir;
t_redir *redir;
char *input;
char **files;
bool sh;
@@ -58,16 +60,16 @@ typedef struct s_ast_n
typedef struct s_nodell
{
t_node *node;
t_node *node;
struct s_nodell *next;
} t_nodell;
t_ast_n *get_ast(t_msh *msh, t_node *lst);
t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter);
t_node *get_top_token(t_node *lst, t_state *state);
t_node *get_top_token(t_node *lst, t_state *state);
// recurce
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh);
t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh);
// redir
t_redir get_redir(t_node *node);
void create_redir(t_node *cpy, t_ast_n *self);
@@ -75,14 +77,15 @@ void create_redir_subsh(t_node *head, t_ast_n *self);
// cmd
void create_cmd(t_ast_n *self, t_node *lst);
// subsh
void create_subsh(t_ast_n *parent, t_node *lst, t_msh *msh);
void create_subsh(t_ast_n *parent, t_node *lst, t_msh *msh);
// pipeline
void create_pline(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh);
// and_or
void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token, t_msh *msh);
void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token,
t_msh *msh);
// free
void free_ast(t_ast_n *node);
void free_lltab(t_nodell *nodell);
void free_lltab(t_nodell *nodell);
#endif

View File

@@ -33,12 +33,13 @@ typedef struct s_elems
} t_elems;
// internal
char *replace_ampercent(char *src);
char *replace_left_red(char *src);
char *replace_ampercent(char *src);
char *replace_left_red(char *src);
t_dio_node get_cmd_txt(t_ast_n *node);
int print_ast(t_ast_n *node, t_elems *e, int fd);
int print_ast(t_ast_n *node, t_elems *e, int fd);
// external
void gen_dio_linked_list(t_node *head, int fd);
void gen_dio_ast(t_ast_n *head, int fd);
void gen_dio_linked_list(t_node *head, int fd);
void gen_dio_ast(t_ast_n *head, int fd);
#endif

View File

@@ -13,7 +13,6 @@
#ifndef HEREDOC_H
# define HEREDOC_H
typedef struct s_node t_node;
typedef struct s_msh t_msh;

View File

@@ -17,10 +17,12 @@ typedef struct s_node t_node;
typedef struct s_ast_n t_ast_n;
typedef struct s_msh t_msh;
t_ast_n *parser(char *input, t_msh *msh);
t_ast_n *parser(char *input, t_msh *msh);
int unexpected_token(t_node *node);
int is_aop_operator(t_node *node);
void interpret_cmd(char **input, t_msh *msh);
void end_heredoc(char *buf, t_msh *msh, t_node *lst);
void exit_heredoc(char *limiter, t_msh *msh, t_node *lst);
#endif

View File

@@ -46,23 +46,25 @@ typedef struct s_node
enum e_pres pressision;
} t_node;
t_node *tokenize(char *str);
t_node *create_node(char *val, t_token token);
int add_node_back(t_node **head, char *val, t_token token, t_pres pres);
int merge_with_next_node(t_node *node);
void free_linked_list(t_node *stack);
t_token get_token(char *str);
t_pres get_pressision(char *s, t_token token, t_token last_token, t_pres last_pres);
int create_node_after(t_node *elem, char *val);
int is_meta(char c);
int is_sticked(char *val);
int trim_nodes(t_node *head);
void debug_linked_list(t_node *head, char *msg);
int find_quote_node(t_node *head, char q);
int syntax_error(t_node *head);
char *copy_meta(char *val, int *copied);
char *copy_unmeta(char *val, int *copied);
void debug_token_list(t_node* lst, char *msg);
void set_token(t_node *head);
t_node *tokenize(char *str);
t_node *create_node(char *val, t_token token);
int add_node_back(t_node **head, char *val,
t_token token, t_pres pres);
int merge_with_next_node(t_node *node);
void free_linked_list(t_node *stack);
t_token get_token(char *str);
t_pres get_pressision(char *s, t_token token,
t_token last_token, t_pres last_pres);
int create_node_after(t_node *elem, char *val);
int is_meta(char c);
int is_sticked(char *val);
int trim_nodes(t_node *head);
void debug_linked_list(t_node *head, char *msg);
int find_quote_node(t_node *head, char q);
int syntax_error(t_node *head);
char *copy_meta(char *val, int *copied);
char *copy_unmeta(char *val, int *copied);
void debug_token_list(t_node *lst, char *msg);
void set_token(t_node *head);
#endif