Loading GRAMMAR +31 −30 Original line number Diff line number Diff line good_input: simple_list '\n' input: list '\n' list EOF | '\n' | EOF redirection: [NUMBER] '>' WORD | [NUMBER] '<' WORD | [NUMBER] '>>' WORD | [NUMBER] '<<' WORD | [NUMBER] '<<-' WORD | [NUMBER] '>&' WORD | [NUMBER] '<&' WORD | [NUMBER] '>|' WORD | [NUMBER] '<>' WORD element: WORD | redirection list: and_or ((';'|'&') and_or)* ['&'|';'] cmd_prefix: ASSIGMENT_WORD | redirection and_or: pipeline (('&&'|'||') ('\n')* pipeline)* simple_command: (cmp_prefix)* (element)+ pipeline: ['!'] command ('|' ('\n')* command)* command: simple_command | shell_command (redirection)* | function_def simple_list: and_or ((';'|'&') and_or)* ['&'|';'] | funcdec and_or: pipeline (('&&'|'||') ('\n')* pipeline)* pipeline: ['!'] command ('|' ('\n')* command)* simple_command: (cmp_prefix)* (element)+ shell_command: '{' compound_list '}' | '(' compound_list ')' Loading @@ -39,10 +23,25 @@ shell_command: '{' compound_list '}' | rule_case | rule_if rule_if: 'if' compound_list 'then' compound_list [else_clause] 'fi' funcdec: ['function'] WORD '(' ')' ('\n')* shell_command (redirection)* else_clause: 'else' compound_list | 'elif' compound_list 'then' compound_list [else_clause] redirection: [NUMBER] '>' WORD | [NUMBER] '<' WORD | [NUMBER] '>>' WORD | [NUMBER] '<<' WORD | [NUMBER] '<<-' WORD | [NUMBER] '>&' WORD | [NUMBER] '<&' WORD | [NUMBER] '>|' WORD | [NUMBER] '<>' WORD cmd_prefix: ASSIGMENT_WORD | redirection element: WORD | redirection compound_list: ('\n')* and_or ((';'|'&'|'\n') ('\n')* and_or)* [(('&'|';'|'\n') ('\n')*)] rule_for: 'for' WORD ('\n')* ['in' (WORD)+ (';'|'\n') ('\n')*] do_group Loading @@ -50,14 +49,16 @@ rule_while: 'while' compound_list do_group rule_until: 'until' compound_list do_group do_group: 'do' compound_list 'done' rule_case: 'case' WORD ('\n')* 'in' ('\n')* [case_clause] 'esac' compound_list: ('\n')* and_or ((';'|'&'|'\n') ('\n')* and_or)* [(('&'|';'|'\n') ('\n')*)] rule_if: 'if' compound_list 'then' compound_list [else_clause] 'fi' else_clause: 'else' compound_list | 'elif' compound_list 'then' compound_list [else_clause] case: 'case' WORD ('\n')* 'in' ('\n')* [case_clause] 'esac' do_group: 'do' compound_list 'done' case_clause: pattern (';;' (\n)* pattern)* [;;] pattern: ['('] WORD ('|' WORD)* ')' ( ('\n')* | compound_list ) function: ['function'] WORD '(' ')' ('\n')* shell_command (redirection)* src/Makefile.am +8 −2 Original line number Diff line number Diff line Loading @@ -5,17 +5,23 @@ bin_PROGRAMS=42sh 42sh_SOURCES= ast/ast.h \ ast/ast_destruct.c \ ast/ast_sep.c \ common/common.h \ common/macro.h \ common/mem.h \ common/strmerge.c \ common/strvmerge.c \ lexer/lexer.h \ common/strndup.c \ common/basename.c \ exec/exec.h \ exec/exec_ast.c \ opt/opt.h \ opt/opt.c \ opt/opt_init.c \ opt/opt_parser.c \ parser/parser.h \ parser/parser.c \ parser/lexer.c \ readline/readline.h \ readline/readline.c \ readline/getln.c \ Loading src/ast/ast.h +35 −34 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ ** Login <seblu@epita.fr> ** ** Started on Sun Jul 30 04:40:03 2006 Seblu ** Last update Wed Aug 2 17:54:14 2006 Seblu ** Last update Thu Aug 3 03:03:42 2006 Seblu */ #ifndef AST_H_ Loading @@ -16,13 +16,12 @@ # include <stdlib.h> # include <assert.h> struct s_ast; typedef struct s_ast ts_ast_node; /* ** If ast node */ typedef struct typedef struct s_if_node { ts_ast_node *cond; ts_ast_node *cond_true; Loading @@ -32,7 +31,7 @@ typedef struct /* ** For ast node */ typedef struct typedef struct s_for_node { char *name; ts_ast_node *values; Loading @@ -42,7 +41,7 @@ typedef struct /* ** Case ast node */ typedef struct typedef struct s_case_node { char *word; //FIXME Loading @@ -52,7 +51,7 @@ typedef struct /* ** While ast node */ typedef struct typedef struct s_while_node { ts_ast_node *cond; ts_ast_node *exec; Loading @@ -61,7 +60,7 @@ typedef struct /* ** Enumerate different type of redirection */ typedef enum typedef enum e_redir_type { R_LESS, /* < */ R_LESSAND, /* <& */ Loading @@ -77,7 +76,7 @@ typedef enum /* ** Redirection ast node */ typedef struct typedef struct s_redir_node { te_redir_type type; int fd; Loading @@ -87,7 +86,7 @@ typedef struct /* ** Command ast node */ typedef struct typedef struct s_cmd_node { char **argv; ts_redir_node **redirs; Loading @@ -100,16 +99,16 @@ typedef struct ** T_PIPE, T_SEP_* , T_AND, T_OR : binary operator ** T_BANG : unary operator but ts_bin_op with right pointer is always NULL */ typedef struct typedef struct s_bin_node { ts_ast_node *left; ts_ast_node *right; ts_ast_node *lhs; ts_ast_node *rhs; } ts_bin_node; /* ** Subshell ast node */ typedef struct typedef struct s_subshell_node { ts_ast_node *head; } ts_subshell_node; Loading @@ -117,7 +116,7 @@ typedef struct /* ** Funcdec node */ typedef struct typedef struct s_funcdec_node { char *name; ts_ast_node *body; Loading @@ -126,7 +125,7 @@ typedef struct /* ** Enumerate all node type */ typedef enum typedef enum e_node_type { T_IF, T_FOR, Loading @@ -140,7 +139,7 @@ typedef enum T_BANG, T_PIPE, T_SEP_AND, T_SEP_SEMICOMMA, T_SEP, T_CASE, T_CASE_LIST, Loading @@ -156,22 +155,22 @@ typedef enum /* ** This is a type for a node item */ typedef union typedef union u_node_item { ts_if_node node_if; ts_for_node node_for; ts_case_node node_case; ts_while_node node_while; ts_while_node node_until; ts_cmd_node node_cmd; ts_bin_node node_and; ts_bin_node node_or; ts_subshell_node node_subshell; ts_funcdec_node node_funcdec; ts_bin_node node_bang; ts_bin_node node_pipe; ts_bin_node node_sep_semicomma; ts_bin_node node_sep_and; ts_if_node child_if; ts_for_node child_for; ts_case_node child_case; ts_while_node child_while; ts_while_node child_until; ts_cmd_node child_cmd; ts_bin_node child_and; ts_bin_node child_or; ts_subshell_node child_subshell; ts_funcdec_node child_funcdec; ts_bin_node child_bang; ts_bin_node child_pipe; ts_bin_node child_sep; ts_bin_node child_sep_and; /* ts_case_item node_case_item; */ Loading @@ -185,12 +184,14 @@ typedef union struct s_ast { te_node_type type; tu_node_item node; tu_node_item body; }; void ast_destruct(ts_ast_node *ast); ts_ast_node *ast_create_sep(ts_ast_node *lhs, ts_ast_node *rhs); void ast_destruct_sep(ts_ast_node *node); /* /\** */ /* ** structure wordlist ex : for var in wordlist do */ Loading Loading @@ -310,7 +311,7 @@ struct s_ast /* ** create shell structure */ /* *\/ */ /* struct s_42sh *ast_create_ast(struct s_42sh *shell, */ /* struct s_ast *ast); */ /* struct s_ast *ast; */ /* struct s_ast *ast_create_patterns(char *word, struct s_ast *case_item); */ /* struct s_ast *ast_create_case_list(struct s_ast *item, */ Loading src/ast/ast_destruct.c 0 → 100644 +18 −0 Original line number Diff line number Diff line /* ** ast_destruct.c for 42sh ** ** Made by Seblu ** Login <seblu@epita.fr> ** ** Started on Sat Mar 25 23:11:01 2006 Seblu ** Last update Thu Aug 3 07:00:17 2006 Seblu */ #include "ast.h" void ast_destruct(ts_ast_node *ast) { if (ast == NULL) return; //fixme } src/ast/ast_sep.c 0 → 100644 +48 −0 Original line number Diff line number Diff line /* ** ast_sep.c for 42sh ** ** Made by Seblu ** Login <luttri_s@epita.fr> ** ** Started on Thu Aug 3 02:41:37 2006 Seblu ** Last update Thu Aug 3 03:03:31 2006 Seblu */ #include "../common/mem.h" #include "ast.h" /*! ** Create a separtor ast node ** ** @param lhs left child ** @param rhs right child ** ** @return the node */ ts_ast_node *ast_create_sep(ts_ast_node *lhs, ts_ast_node *rhs) { ts_ast_node *node; secmalloc(node, sizeof (ts_ast_node)); node->type = T_SEP; node->body.child_sep.lhs = lhs; node->body.child_sep.rhs = rhs; return node; } /*! ** Destruct and separator node ** ** @param node node to destroy */ void ast_destruct_sep(ts_ast_node *node) { if (node->type != T_SEP) { ast_destruct(node); return; } ast_destruct(node->body.child_sep.lhs); ast_destruct(node->body.child_sep.rhs); free(node); } Loading
GRAMMAR +31 −30 Original line number Diff line number Diff line good_input: simple_list '\n' input: list '\n' list EOF | '\n' | EOF redirection: [NUMBER] '>' WORD | [NUMBER] '<' WORD | [NUMBER] '>>' WORD | [NUMBER] '<<' WORD | [NUMBER] '<<-' WORD | [NUMBER] '>&' WORD | [NUMBER] '<&' WORD | [NUMBER] '>|' WORD | [NUMBER] '<>' WORD element: WORD | redirection list: and_or ((';'|'&') and_or)* ['&'|';'] cmd_prefix: ASSIGMENT_WORD | redirection and_or: pipeline (('&&'|'||') ('\n')* pipeline)* simple_command: (cmp_prefix)* (element)+ pipeline: ['!'] command ('|' ('\n')* command)* command: simple_command | shell_command (redirection)* | function_def simple_list: and_or ((';'|'&') and_or)* ['&'|';'] | funcdec and_or: pipeline (('&&'|'||') ('\n')* pipeline)* pipeline: ['!'] command ('|' ('\n')* command)* simple_command: (cmp_prefix)* (element)+ shell_command: '{' compound_list '}' | '(' compound_list ')' Loading @@ -39,10 +23,25 @@ shell_command: '{' compound_list '}' | rule_case | rule_if rule_if: 'if' compound_list 'then' compound_list [else_clause] 'fi' funcdec: ['function'] WORD '(' ')' ('\n')* shell_command (redirection)* else_clause: 'else' compound_list | 'elif' compound_list 'then' compound_list [else_clause] redirection: [NUMBER] '>' WORD | [NUMBER] '<' WORD | [NUMBER] '>>' WORD | [NUMBER] '<<' WORD | [NUMBER] '<<-' WORD | [NUMBER] '>&' WORD | [NUMBER] '<&' WORD | [NUMBER] '>|' WORD | [NUMBER] '<>' WORD cmd_prefix: ASSIGMENT_WORD | redirection element: WORD | redirection compound_list: ('\n')* and_or ((';'|'&'|'\n') ('\n')* and_or)* [(('&'|';'|'\n') ('\n')*)] rule_for: 'for' WORD ('\n')* ['in' (WORD)+ (';'|'\n') ('\n')*] do_group Loading @@ -50,14 +49,16 @@ rule_while: 'while' compound_list do_group rule_until: 'until' compound_list do_group do_group: 'do' compound_list 'done' rule_case: 'case' WORD ('\n')* 'in' ('\n')* [case_clause] 'esac' compound_list: ('\n')* and_or ((';'|'&'|'\n') ('\n')* and_or)* [(('&'|';'|'\n') ('\n')*)] rule_if: 'if' compound_list 'then' compound_list [else_clause] 'fi' else_clause: 'else' compound_list | 'elif' compound_list 'then' compound_list [else_clause] case: 'case' WORD ('\n')* 'in' ('\n')* [case_clause] 'esac' do_group: 'do' compound_list 'done' case_clause: pattern (';;' (\n)* pattern)* [;;] pattern: ['('] WORD ('|' WORD)* ')' ( ('\n')* | compound_list ) function: ['function'] WORD '(' ')' ('\n')* shell_command (redirection)*
src/Makefile.am +8 −2 Original line number Diff line number Diff line Loading @@ -5,17 +5,23 @@ bin_PROGRAMS=42sh 42sh_SOURCES= ast/ast.h \ ast/ast_destruct.c \ ast/ast_sep.c \ common/common.h \ common/macro.h \ common/mem.h \ common/strmerge.c \ common/strvmerge.c \ lexer/lexer.h \ common/strndup.c \ common/basename.c \ exec/exec.h \ exec/exec_ast.c \ opt/opt.h \ opt/opt.c \ opt/opt_init.c \ opt/opt_parser.c \ parser/parser.h \ parser/parser.c \ parser/lexer.c \ readline/readline.h \ readline/readline.c \ readline/getln.c \ Loading
src/ast/ast.h +35 −34 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ ** Login <seblu@epita.fr> ** ** Started on Sun Jul 30 04:40:03 2006 Seblu ** Last update Wed Aug 2 17:54:14 2006 Seblu ** Last update Thu Aug 3 03:03:42 2006 Seblu */ #ifndef AST_H_ Loading @@ -16,13 +16,12 @@ # include <stdlib.h> # include <assert.h> struct s_ast; typedef struct s_ast ts_ast_node; /* ** If ast node */ typedef struct typedef struct s_if_node { ts_ast_node *cond; ts_ast_node *cond_true; Loading @@ -32,7 +31,7 @@ typedef struct /* ** For ast node */ typedef struct typedef struct s_for_node { char *name; ts_ast_node *values; Loading @@ -42,7 +41,7 @@ typedef struct /* ** Case ast node */ typedef struct typedef struct s_case_node { char *word; //FIXME Loading @@ -52,7 +51,7 @@ typedef struct /* ** While ast node */ typedef struct typedef struct s_while_node { ts_ast_node *cond; ts_ast_node *exec; Loading @@ -61,7 +60,7 @@ typedef struct /* ** Enumerate different type of redirection */ typedef enum typedef enum e_redir_type { R_LESS, /* < */ R_LESSAND, /* <& */ Loading @@ -77,7 +76,7 @@ typedef enum /* ** Redirection ast node */ typedef struct typedef struct s_redir_node { te_redir_type type; int fd; Loading @@ -87,7 +86,7 @@ typedef struct /* ** Command ast node */ typedef struct typedef struct s_cmd_node { char **argv; ts_redir_node **redirs; Loading @@ -100,16 +99,16 @@ typedef struct ** T_PIPE, T_SEP_* , T_AND, T_OR : binary operator ** T_BANG : unary operator but ts_bin_op with right pointer is always NULL */ typedef struct typedef struct s_bin_node { ts_ast_node *left; ts_ast_node *right; ts_ast_node *lhs; ts_ast_node *rhs; } ts_bin_node; /* ** Subshell ast node */ typedef struct typedef struct s_subshell_node { ts_ast_node *head; } ts_subshell_node; Loading @@ -117,7 +116,7 @@ typedef struct /* ** Funcdec node */ typedef struct typedef struct s_funcdec_node { char *name; ts_ast_node *body; Loading @@ -126,7 +125,7 @@ typedef struct /* ** Enumerate all node type */ typedef enum typedef enum e_node_type { T_IF, T_FOR, Loading @@ -140,7 +139,7 @@ typedef enum T_BANG, T_PIPE, T_SEP_AND, T_SEP_SEMICOMMA, T_SEP, T_CASE, T_CASE_LIST, Loading @@ -156,22 +155,22 @@ typedef enum /* ** This is a type for a node item */ typedef union typedef union u_node_item { ts_if_node node_if; ts_for_node node_for; ts_case_node node_case; ts_while_node node_while; ts_while_node node_until; ts_cmd_node node_cmd; ts_bin_node node_and; ts_bin_node node_or; ts_subshell_node node_subshell; ts_funcdec_node node_funcdec; ts_bin_node node_bang; ts_bin_node node_pipe; ts_bin_node node_sep_semicomma; ts_bin_node node_sep_and; ts_if_node child_if; ts_for_node child_for; ts_case_node child_case; ts_while_node child_while; ts_while_node child_until; ts_cmd_node child_cmd; ts_bin_node child_and; ts_bin_node child_or; ts_subshell_node child_subshell; ts_funcdec_node child_funcdec; ts_bin_node child_bang; ts_bin_node child_pipe; ts_bin_node child_sep; ts_bin_node child_sep_and; /* ts_case_item node_case_item; */ Loading @@ -185,12 +184,14 @@ typedef union struct s_ast { te_node_type type; tu_node_item node; tu_node_item body; }; void ast_destruct(ts_ast_node *ast); ts_ast_node *ast_create_sep(ts_ast_node *lhs, ts_ast_node *rhs); void ast_destruct_sep(ts_ast_node *node); /* /\** */ /* ** structure wordlist ex : for var in wordlist do */ Loading Loading @@ -310,7 +311,7 @@ struct s_ast /* ** create shell structure */ /* *\/ */ /* struct s_42sh *ast_create_ast(struct s_42sh *shell, */ /* struct s_ast *ast); */ /* struct s_ast *ast; */ /* struct s_ast *ast_create_patterns(char *word, struct s_ast *case_item); */ /* struct s_ast *ast_create_case_list(struct s_ast *item, */ Loading
src/ast/ast_destruct.c 0 → 100644 +18 −0 Original line number Diff line number Diff line /* ** ast_destruct.c for 42sh ** ** Made by Seblu ** Login <seblu@epita.fr> ** ** Started on Sat Mar 25 23:11:01 2006 Seblu ** Last update Thu Aug 3 07:00:17 2006 Seblu */ #include "ast.h" void ast_destruct(ts_ast_node *ast) { if (ast == NULL) return; //fixme }
src/ast/ast_sep.c 0 → 100644 +48 −0 Original line number Diff line number Diff line /* ** ast_sep.c for 42sh ** ** Made by Seblu ** Login <luttri_s@epita.fr> ** ** Started on Thu Aug 3 02:41:37 2006 Seblu ** Last update Thu Aug 3 03:03:31 2006 Seblu */ #include "../common/mem.h" #include "ast.h" /*! ** Create a separtor ast node ** ** @param lhs left child ** @param rhs right child ** ** @return the node */ ts_ast_node *ast_create_sep(ts_ast_node *lhs, ts_ast_node *rhs) { ts_ast_node *node; secmalloc(node, sizeof (ts_ast_node)); node->type = T_SEP; node->body.child_sep.lhs = lhs; node->body.child_sep.rhs = rhs; return node; } /*! ** Destruct and separator node ** ** @param node node to destroy */ void ast_destruct_sep(ts_ast_node *node) { if (node->type != T_SEP) { ast_destruct(node); return; } ast_destruct(node->body.child_sep.lhs); ast_destruct(node->body.child_sep.rhs); free(node); }