From 941099778b59da6b904c284e8a82affe4766124b Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 30 Mar 2020 22:27:16 +0200 Subject: Added doc --- include/minishell.h | 15 +++++++++- include/ms_eval.h | 67 ++++++++++++++++++++++++++++-------------- include/ms_parse.h | 83 +++++++++++++++++++++++++---------------------------- 3 files changed, 99 insertions(+), 66 deletions(-) (limited to 'include') diff --git a/include/minishell.h b/include/minishell.h index 04ab243..9931b15 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -14,6 +14,11 @@ #ifndef MINISHELL_H # define MINISHELL_H +/** +** \file minishell.h +** \brief Common header +*/ + # include # include # include @@ -31,8 +36,16 @@ # include "ms_parse.h" -# define MS_PATH_KEY "PATH" +/** +** \brief Pipe write index +*/ + # define MS_PIPE_WRITE 1 + +/** +** \brief Pipe read index +*/ + # define MS_PIPE_READ 0 typedef t_ftht* t_path; diff --git a/include/ms_eval.h b/include/ms_eval.h index 35e7355..12c2b7e 100644 --- a/include/ms_eval.h +++ b/include/ms_eval.h @@ -1,6 +1,11 @@ #ifndef MS_EVAL_H # define MS_EVAL_H +/** +** \file ms_eval.h +** \brief Evaluation module +*/ + /* ** arg: ** type ARG @@ -19,33 +24,53 @@ ** value fd */ -read state - if redir: - open file keep fd +/** +** \enum t_val_type +** \brief A type for an evaluation node +** +** \param VAL_ERR error +** \param VAL_ERR argument +** \param VAL_REDIR redirection +** \param VAL_SEXPR S-expression +*/ +typedef enum +{ + VAL_ERR, + VAL_ARG, + VAL_EXEC, + VAL_REDIR_IN, + VAL_REDIR_OUT, + VAL_REDIR_APPEND, + VAL_CMD, + VAL_SEXPR, +} t_val_type; + +/** +** \brief An evaluation node struct +** \param type type of node +** \param data union of possible data +** \param data::fd file descriptor for redirection node +** \param data::str string for error, arguments, command +*/ typedef struct { - t_status_type type; + t_val_type type; union { - char *str; - int code; - int fd; - } data; -} t_val; - - + char *str; + int code; + int fd; + } data; +} t_val; -typedef enum -{ - STYPE_ERROR, - STYPE_ARG, - STYPE_FILE, - STYPE_SEXPR, - // ... -} t_status_type; - -int ms_eval(t_path path, t_env env, t_ast *ast); +/** +** \brief evaluate an AST +** \param path path to commands executable +** \param env environment variables +** \param ast Abstract syntax tree to evaluate +*/ +int ms_eval(t_path path, t_env env, t_ast *ast); #endif diff --git a/include/ms_parse.h b/include/ms_parse.h index 74604e5..0810ec2 100644 --- a/include/ms_parse.h +++ b/include/ms_parse.h @@ -15,67 +15,49 @@ # include "minishell.h" -/* -** Context free grammar: +/** +** \file ms_parse.h +** \brief Input parsing and AST manipulation ** +** Context free grammar: +** ``` ** redir_in ::= '<' ** redir_out ::= '>' ** redir_append ::= '>>' ** string ::= '\'' .+ '\'' | '"' .+ '"' | [^ ]+ ** sep ::= '&&' | '||' | '|' | ';' ** expr ::= | | | -** sexpr ::= + -** line ::= | +** cmd ::= + +** line ::= | +** ``` */ -/* -** TAG_CMD: command name -** TAG_ARG: command argument -** TAG_ENDCMD: `;` -** TAG_PIPE: `|` -** TAG_AND: `&&` -** TAG_OR: `||` -** TAG_REDIR_OUT: `>` -** TAG_REDIR_IN: `<` -** TAG_REDIR_APPEND: `>>` +/** +** \brief AST node tag +** \param TAG_STRING string +** \param TAG_SEP `;` | `|` | `&&` | `||` +** \param TAG_REDIR_OUT `>` +** \param TAG_REDIR_IN `<` +** \param TAG_REDIR_APPEND `>>` */ typedef enum { - TAG_CMD, - TAG_ARG, - TAG_ENDCMD, - TAG_PIPE, - TAG_AND, - TAG_OR, + TAG_STRING, + TAG_SEP, TAG_REDIR_OUT, TAG_REDIR_IN, - TAG_REDIR_APPEND + TAG_REDIR_APPEND, + TAG_CMD, + TAG_LINE, } t_tag; -/* -** AST (Abstract Syntax Tree) -** A node of the ast is represented by a tag (his type) and a content associated with it. -** (i.e a TAG_CMD would be paired with the command executable name) -** Each node also has children node which must be evaluated before him -** -** examle: "echo foo bar && ls" -** -** tags: -** TAG_AND -** / \ -** / \ -** TAG_CMD TAG_CMD -** / \ -** TAG_ARG TAG_ARG -** -** content: -** && -** / \ -** / \ -** echo ls -** / \ -** foo bar +/** +** \brief AST (Abstract Syntax Tree) +** \param tag tag (type) of node +** \param content substring of the parsed string which corespond to tag +** \param children_num number of children +** \param children children nodes */ typedef struct s_ast @@ -86,6 +68,11 @@ typedef struct s_ast struct s_ast** children; } t_ast; + +/* +** lexer.c +*/ + char **ms_lexer(char *input); /* @@ -94,4 +81,12 @@ char **ms_lexer(char *input); t_ast *ms_parse(char *input); +/* +** ast.c +*/ + +t_ast *ms_ast_new(t_tag tag); +void ms_ast_destroy(t_ast *ast); +void ms_ast_iter(t_ast *ast, void (*f)(void *f_arg, t_ast *children), void *arg); + #endif -- cgit