diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lexer/lexer_utils.c | 11 | ||||
| -rw-r--r-- | src/main.c | 10 | ||||
| -rwxr-xr-x | src/parse/cmd_parse.c | 1 | ||||
| -rwxr-xr-x | src/parse/parse.c | 29 |
4 files changed, 40 insertions, 11 deletions
diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c index 616c0d3..3ee41ff 100644 --- a/src/lexer/lexer_utils.c +++ b/src/lexer/lexer_utils.c @@ -1,5 +1,6 @@ #include "lexer.h" +// check for append tag enum e_token_tag ret_token_sep_redir_append(char *input, int i) { if (input[i + 1] == '>') @@ -8,13 +9,14 @@ enum e_token_tag ret_token_sep_redir_append(char *input, int i) } +// return token tag corresponding to string id enum e_token_tag ret_token(char *input, int i) { if (input[i] == ';') - return(TAG_AND); - if (input[i] == '&') return(TAG_END); - if (input[i] == '|' && input[i + 1] == '|') + if (input[i] == '&') + return(TAG_AND); + if (input[i] == '|' && input[i + 1] == '|') return(TAG_OR); if(input[i] == '|') return(TAG_PIPE); @@ -30,6 +32,8 @@ enum e_token_tag ret_token(char *input, int i) } +// check is char is separator +// ft_strchr(";&|><()", input) int lexer_sep(char input) { char *sep; @@ -46,6 +50,7 @@ int lexer_sep(char input) return (0); } +// skip spaces int lexe_space(char *input) { int i; @@ -6,7 +6,7 @@ /* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/06/17 20:46:39 by charles ### ########.fr */ +/* Updated: 2020/06/17 22:11:31 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,7 +48,9 @@ void ast_print(int level, t_ast *ast) if (ast->tag == AST_CMD) { print_level(level); + printf("[ "); ft_lstiter(ast->cmd_argv, token_put); + printf(" ]"); } else { @@ -80,7 +82,7 @@ int main(int argc, char **argv, char **envp) //printf("%s\n", argv[2]); t_ftlst *lex_out = lexer(ft_strdup(argv[2])); - //ft_lstiter(lex_out, token_debug); + ft_lstiter(lex_out, token_debug); t_ret *parser_out = parse(lex_out); ast_print(0, parser_out->ast); @@ -90,8 +92,8 @@ int main(int argc, char **argv, char **envp) /* printf("===redirs===\n"); */ /* ft_lstiter(parser_out->ast->redirs, token_debug); */ - //int eval_out = eval_cmd(env, path, parser_out->ast); - //(void)eval_out; + /* int eval_out = eval_cmd(env, path, parser_out->ast); */ + /* (void)eval_out; */ } ft_htdestroy(path, free); diff --git a/src/parse/cmd_parse.c b/src/parse/cmd_parse.c index 15a5054..25802c1 100755 --- a/src/parse/cmd_parse.c +++ b/src/parse/cmd_parse.c @@ -2,7 +2,6 @@ #include "parser.h" - int parse_cmd_str_true_false(enum e_token_tag tag) { if (tag & TAG_STR || tag & TAG_STR_DOUBLE || tag & TAG_STR_SINGLE) diff --git a/src/parse/parse.c b/src/parse/parse.c index 6a80e37..7217fdb 100755 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -6,7 +6,7 @@ /* By: nahaddac <nahaddac@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ -/* Updated: 2020/06/17 20:39:25 by charles ### ########.fr */ +/* Updated: 2020/06/17 23:00:29 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,7 +88,7 @@ t_ret *parse_op(t_ftlst *input) left_ret = parse_cmd(input); input = left_ret->rest; - if (input == NULL)//((t_token*)input->data)->tag & TAG_IS_SEP) + if (input == NULL) //((t_token*)input->data)->tag & TAG_IS_SEP) return ret_wrap_ast(left_ret->ast, input); sep_tag = ((t_token*)input->data)->tag; @@ -103,6 +103,29 @@ t_ret *parse_op(t_ftlst *input) return ret_wrap_ast(ast, right_ret->rest); } +t_ret *parse_expr(t_ftlst *input) +{ + t_ret *tmp; + enum e_token_tag tag; + + tag = input->data->tag; + if (tag == TAG_PARENT_OPEN) + { + tmp = parse_expr(input->next); + input = tmp->rest; + tag = input->data->tag; + if (tag != TAG_PARENT_CLOSE) + return (NULL); + input = input->next; + tmp->rest = input; + return tmp; + } + tmp = parse_op(input); + if (tmp->unexpected != NULL) + return tmp; + return parse_cmd(input); +} + t_ret *parse(t_ftlst *input) { return parse_op(input); @@ -143,7 +166,7 @@ t_ret *parse(t_ftlst *input) /* } */ /* return ast; */ /* } */ -/* */ + /* t_ret *parse(t_ftlst *input) */ /* { */ /* t_ret *ret; */ |
