diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-03-30 22:27:16 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-03-30 22:27:16 +0200 |
| commit | 941099778b59da6b904c284e8a82affe4766124b (patch) | |
| tree | 4457787a1b09408fcd1a5607109cc1c902c80af8 /src/parse | |
| parent | 74787eefa2ac85d85b484d0ca5dffc6a2a13331d (diff) | |
| download | minishell-941099778b59da6b904c284e8a82affe4766124b.tar.gz minishell-941099778b59da6b904c284e8a82affe4766124b.tar.bz2 minishell-941099778b59da6b904c284e8a82affe4766124b.zip | |
Added doc
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/ast.c | 63 | ||||
| -rw-r--r-- | src/parse/lexer.c | 5 | ||||
| -rw-r--r-- | src/parse/parse.c | 5 |
3 files changed, 73 insertions, 0 deletions
diff --git a/src/parse/ast.c b/src/parse/ast.c new file mode 100644 index 0000000..f566832 --- /dev/null +++ b/src/parse/ast.c @@ -0,0 +1,63 @@ +/** +** \file ast.c +** \brief AST manipulation +*/ + +#include "ms_parse.h" + +/** +** \brief Create a new AST node with default values +** \param tag Tag of the node +** \return The allocated node +*/ + +t_ast *ms_ast_new(t_tag tag) +{ + t_ast *ast; + + if ((ast = (t_ast*)malloc(sizeof(t_ast))) == NULL) + return (NULL); + ast->tag = tag; + ast->content = NULL; + ast->children_num = 0; + ast->children = NULL; + return (ast); +} + +/** +** \brief Destroy an allocated AST +** \warning Assumes that `content`, `children` and the node itself have been malloc'd +** \param ast AST to destroy +*/ + +void ms_ast_destroy(t_ast *ast) +{ + int i; + + if (ast == NULL) + return ; + i = -1; + while (++i < ast->children_num) + ms_ast_destroy(ast->children[i]); + free(ast->children); + free(ast->content); + free(ast); +} + +/** +** \brief Iterate over an AST node's childs +** \param f Function applied to each child, take `arg` has his first argument. +** \param arg Pointer that will be passed to `f`, to keep information between iterations +*/ + +void ms_ast_iter( + t_ast *ast, + void (*f)(void *f_arg, t_ast *children), + void *arg) +{ + int i; + + i = -1; + while (++i < ast->children_num) + f(arg, ast->children[i]); +} diff --git a/src/parse/lexer.c b/src/parse/lexer.c index b5caba2..d8f1254 100644 --- a/src/parse/lexer.c +++ b/src/parse/lexer.c @@ -1,3 +1,8 @@ +/** +** \file lexer.c +** \brief Lexer +*/ + #include "minishell.h" char **ms_lexer(char *input) diff --git a/src/parse/parse.c b/src/parse/parse.c index bdd0144..41b82c2 100644 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -1,3 +1,8 @@ +/** +** \file parse.c +** \brief Parser +*/ + #include "minishell.h" t_ast *ms_parse(char *input) |
