diff --git a/src/ast/ast.h b/src/ast/ast.h index 291d33e0682aa473577f8855dbf8f2b0c0163bc9..24bba7c69b2bf12f6be60686935402385a6f6c7f 100644 --- a/src/ast/ast.h +++ b/src/ast/ast.h @@ -5,7 +5,7 @@ ** Login ** ** Started on Sun Jul 30 04:40:03 2006 Seblu -** Last update Fri Sep 1 00:30:34 2006 Seblu +** Last update Tue Sep 26 17:49:18 2006 Seblu */ #ifndef AST_H_ @@ -189,6 +189,7 @@ void ast_print(s_ast_node *ast, const char *filename); ** ** @param ast ast node to add to file ** @param fs file stream where print ast +** @param node_id first free node id */ void ast_print_node(s_ast_node *ast, FILE *fs, unsigned int *node_id); @@ -279,6 +280,15 @@ void ast_case_destruct(s_ast_node *node); */ s_ast_node *ast_while_create(s_ast_node *cond, s_ast_node *exec); +/*! +** Print an ast while (while) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_while_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct a while ast node ** @@ -296,6 +306,15 @@ void ast_while_destruct(s_ast_node *node); */ s_ast_node *ast_until_create(s_ast_node *cond, s_ast_node *exec); +/*! +** Print an ast until (until) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_until_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct a until ast node ** @@ -339,7 +358,13 @@ void ast_cmd_add_argv(s_ast_node *node, char *argv); */ void ast_cmd_add_prefix(s_ast_node *node, char *assignment_word); - +/*! +** Print an ast cmd node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id); /*! @@ -359,6 +384,15 @@ void ast_cmd_destruct(s_ast_node *node); */ s_ast_node *ast_and_create(s_ast_node *lhs, s_ast_node *rhs); +/*! +** Print an ast and (&&) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_and_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct an and (&&) node ** @@ -376,6 +410,15 @@ void ast_and_destruct(s_ast_node *node); */ s_ast_node *ast_or_create(s_ast_node *lhs, s_ast_node *rhs); +/*! +** Print an ast or (||) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_or_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct an or (||) node ** @@ -384,7 +427,7 @@ s_ast_node *ast_or_create(s_ast_node *lhs, s_ast_node *rhs); void ast_or_destruct(s_ast_node *node); /*! -** Create a subshell ($()) ast node +** Create a subshell (()) ast node ** ** @param child subshell tree ** @@ -393,7 +436,16 @@ void ast_or_destruct(s_ast_node *node); s_ast_node *ast_subshell_create(s_ast_node *child); /*! -** Destruct a subshell ($()) node +** Print an ast subshell (()) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_subshell_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + +/*! +** Destruct a subshell (()) node ** ** @param node node to destroy */ @@ -425,6 +477,15 @@ void ast_funcdec_destruct(s_ast_node *node); */ s_ast_node *ast_bang_create(s_ast_node *child); +/*! +** Print an ast bang (!) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_bang_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct a bang (!) node ** @@ -442,6 +503,15 @@ void ast_bang_destruct(s_ast_node *node); */ s_ast_node *ast_pipe_create(s_ast_node *lhs, s_ast_node *rhs); +/*! +** Print an ast pipe (|) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_pipe_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct a pipe (|) node ** @@ -459,6 +529,15 @@ void ast_pipe_destruct(s_ast_node *node); */ s_ast_node *ast_sep_create(s_ast_node *lhs, s_ast_node *rhs); +/*! +** Print an ast sep (;) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_sep_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct a sep (;) node ** @@ -476,6 +555,15 @@ void ast_sep_destruct(s_ast_node *node); */ s_ast_node *ast_sepand_create(s_ast_node *lhs, s_ast_node *rhs); +/*! +** Print an ast sepand (&) node +** +** @param ast ast node to add to file +** @param fs file stream where print ast +** @param node_id first free node id +*/ +void ast_sepand_print(s_ast_node *node, FILE *fs, unsigned int *node_id); + /*! ** Destruct a sepand (&) node ** diff --git a/src/ast/ast_and.c b/src/ast/ast_and.c index c9c33c7043f4c9fa8dcde9fe7a79537a7c95c7a2..02c5d7d994cd5c8e53cd500b0617f8c79cbd560f 100644 --- a/src/ast/ast_and.c +++ b/src/ast/ast_and.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Mon Aug 28 23:57:05 2006 Seblu +** Last update Tue Sep 26 17:45:16 2006 Seblu */ #include "ast.h" @@ -21,6 +21,21 @@ s_ast_node *ast_and_create(s_ast_node *lhs, s_ast_node *rhs) return node; } +void ast_and_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, rhs_id, cur_id; + + if (node->type != T_AND) + return; + fprintf(fs, "%u [label = \"&&\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_and.lhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); + rhs_id = *node_id; + ast_print_node(node->body.child_and.rhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, rhs_id); +} + void ast_and_destruct(s_ast_node *node) { if (node->type != T_AND) diff --git a/src/ast/ast_bang.c b/src/ast/ast_bang.c index 45901dc31b83a6d4d472a774ed77882a63bbfbbf..50df098c9325248ed1c68931e7711f500247aedd 100644 --- a/src/ast/ast_bang.c +++ b/src/ast/ast_bang.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Mon Aug 28 23:57:20 2006 Seblu +** Last update Tue Sep 26 17:45:45 2006 Seblu */ #include "ast.h" @@ -21,6 +21,18 @@ s_ast_node *ast_bang_create(s_ast_node *child) return node; } +void ast_bang_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, cur_id; + + if (node->type != T_BANG) + return; + fprintf(fs, "%u [label = \"!\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_bang.lhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); +} + void ast_bang_destruct(s_ast_node *node) { if (node->type != T_BANG) diff --git a/src/ast/ast_cmd.c b/src/ast/ast_cmd.c index 670e6155ab34b978585b0b8b2e3f50553009760c..76bdb1c33eed39686e61838d6842cc682ab58491 100644 --- a/src/ast/ast_cmd.c +++ b/src/ast/ast_cmd.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Fri Aug 18 22:13:51 2006 Seblu -** Last update Mon Sep 25 04:19:18 2006 Seblu +** Last update Tue Sep 26 17:25:05 2006 Seblu */ #include "ast.h" @@ -37,7 +37,7 @@ void ast_cmd_add_redir(s_ast_node *node, red->fd = fd; red->word = word; red->next = NULL; - for (this = &node->body.child_cmd.redirs; *this; *this = (*this)->next) + for (this = &node->body.child_cmd.redirs; (*this) != NULL; this = &(*this)->next) ; //do nothing *this = red; } @@ -77,10 +77,10 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) if (node->type != T_CMD) return; fprintf(fs, "%u [label = \"Command\"];\n", *node_id); + ++*node_id; //prefix char **prefix = node->body.child_cmd.prefix; if (prefix && prefix[0]) { - ++*node_id; fprintf(fs, "%u [label = \"", *node_id); for (int i = 0; prefix && prefix[i]; ++i) { fprintf(fs, "prefix[%d]:", i); @@ -93,11 +93,11 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); + ++*node_id; } //arguments char **argv = node->body.child_cmd.argv; if (argv && argv[0]) { - ++*node_id; fprintf(fs, "%u [label = \"", *node_id); for (int i = 0; argv && argv[i]; ++i) { fprintf(fs, "argv[%d]:", i); @@ -110,11 +110,11 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); + ++*node_id; } //redirs if (node->body.child_cmd.redirs) { int i = 0; - ++*node_id; fprintf(fs, "%u [label = \"", *node_id); for (s_redir *this = node->body.child_cmd.redirs; this; this = this->next, ++i) { fprintf(fs, "redirs[%d]: fd=%d, type=%d, word=", i, this->fd, this->type); @@ -124,6 +124,7 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) fprintf(fs, "%.*s\\", p - last, this->word + last), last = p; fprintf(fs, "%*s", p - last, this->word + last), last = p; fprintf(fs, "\\n"); + ++*node_id; } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); diff --git a/src/ast/ast_or.c b/src/ast/ast_or.c index bffab815375ba2306fe3633c3e54ffe233d97c3d..2110f69b08a772dd4f3f4f83083df1edb74c6b9e 100644 --- a/src/ast/ast_or.c +++ b/src/ast/ast_or.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Mon Aug 28 23:59:55 2006 Seblu +** Last update Tue Sep 26 17:45:54 2006 Seblu */ #include "ast.h" @@ -21,6 +21,21 @@ s_ast_node *ast_or_create(s_ast_node *lhs, s_ast_node *rhs) return node; } +void ast_or_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, rhs_id, cur_id; + + if (node->type != T_OR) + return; + fprintf(fs, "%u [label = \"||\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_or.lhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); + rhs_id = *node_id; + ast_print_node(node->body.child_or.rhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, rhs_id); +} + void ast_or_destruct(s_ast_node *node) { if (node->type != T_OR) diff --git a/src/ast/ast_pipe.c b/src/ast/ast_pipe.c index d29a722b723dfad511e8d185452a2125d7f18004..826c1bf69fe028bd448628a7784662613111a190 100644 --- a/src/ast/ast_pipe.c +++ b/src/ast/ast_pipe.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Tue Aug 29 00:00:31 2006 Seblu +** Last update Tue Sep 26 17:45:33 2006 Seblu */ #include "ast.h" @@ -21,6 +21,21 @@ s_ast_node *ast_pipe_create(s_ast_node *lhs, s_ast_node *rhs) return node; } +void ast_pipe_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, rhs_id, cur_id; + + if (node->type != T_PIPE) + return; + fprintf(fs, "%u [label = \"|\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_pipe.lhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); + rhs_id = *node_id; + ast_print_node(node->body.child_pipe.rhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, rhs_id); +} + void ast_pipe_destruct(s_ast_node *node) { if (node->type != T_PIPE) diff --git a/src/ast/ast_print.c b/src/ast/ast_print.c index 01a281984b910fa8bb0a0310cc5f1b630a9cfc57..30ee0d168bfa00f8e1aa2ffb0897408e665139c9 100644 --- a/src/ast/ast_print.c +++ b/src/ast/ast_print.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Sat Mar 25 23:11:01 2006 Seblu -** Last update Fri Sep 1 00:31:28 2006 Seblu +** Last update Tue Sep 26 17:47:33 2006 Seblu */ #include @@ -17,31 +17,31 @@ #include #include "ast.h" -#define NODE_TYPE_COUNT 14 +enum { NODE_TYPE_COUNT = 14 }; -typedef void (*print_fct)(s_ast_node *, FILE *, unsigned int *); +typedef void (*f_print)(s_ast_node *, FILE *, unsigned int *); struct ast_print_switch { e_node_type type; - print_fct fct; + f_print fct; }; struct ast_print_switch print_table[NODE_TYPE_COUNT] = { {T_IF, NULL}, // ast_if_print}, {T_FOR, NULL}, //ast_for_print}, - {T_WHILE, NULL}, //ast_while_print}, - {T_UNTIL, NULL}, //ast_until_print}, + {T_WHILE, ast_while_print}, + {T_UNTIL, ast_until_print}, {T_CMD, ast_cmd_print}, - {T_AND, NULL}, //ast_and_print}, - {T_OR, NULL}, //ast_or_print}, - {T_SUBSHELL, NULL}, //ast_subshell_print}, + {T_AND, ast_and_print}, + {T_OR, ast_or_print}, + {T_SUBSHELL, ast_subshell_print}, {T_FUNCDEC, NULL}, //ast_funcdec_print}, - {T_BANG, NULL}, //ast_bang_print}, - {T_PIPE, NULL}, //ast_pipe_print}, - {T_SEPAND, NULL}, //ast_sepand_print}, - {T_SEP, NULL}, //ast_sep_print}, + {T_BANG, ast_bang_print}, + {T_PIPE, ast_pipe_print}, + {T_SEPAND, ast_sepand_print}, + {T_SEP, ast_sep_print}, {T_CASE, NULL} //ast_sepand_print} }; diff --git a/src/ast/ast_sep.c b/src/ast/ast_sep.c index b9d92adba4c78d65dc648b2d9bd701cf88125fb0..3eb72f3e87db7e8f4fc4003d655c6ddd1ffb1067 100644 --- a/src/ast/ast_sep.c +++ b/src/ast/ast_sep.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Wed Aug 30 00:36:03 2006 Seblu +** Last update Tue Sep 26 17:10:01 2006 Seblu */ #include "ast.h" @@ -21,6 +21,21 @@ s_ast_node *ast_sep_create(s_ast_node *lhs, s_ast_node *rhs) return node; } +void ast_sep_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, rhs_id, cur_id; + + if (node->type != T_SEP) + return; + fprintf(fs, "%u [label = \";\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_sep.lhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); + rhs_id = *node_id; + ast_print_node(node->body.child_sep.rhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, rhs_id); +} + void ast_sep_destruct(s_ast_node *node) { if (node->type != T_SEP) diff --git a/src/ast/ast_sepand.c b/src/ast/ast_sepand.c index 27815a2911226b05412fabc32ec2dd35e82da935..ee4cd55f4c20166d1ee7a6580553c99c8ef98bb6 100644 --- a/src/ast/ast_sepand.c +++ b/src/ast/ast_sepand.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Tue Aug 29 00:00:49 2006 Seblu +** Last update Tue Sep 26 17:43:20 2006 Seblu */ #include "ast.h" @@ -21,6 +21,21 @@ s_ast_node *ast_sepand_create(s_ast_node *lhs, s_ast_node *rhs) return node; } +void ast_sepand_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, rhs_id, cur_id; + + if (node->type != T_SEPAND) + return; + fprintf(fs, "%u [label = \"&\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_sepand.lhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); + rhs_id = *node_id; + ast_print_node(node->body.child_sepand.rhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, rhs_id); +} + void ast_sepand_destruct(s_ast_node *node) { if (node->type != T_SEPAND) diff --git a/src/ast/ast_subshell.c b/src/ast/ast_subshell.c index 81340676d6d8052e6c3e357b17c38cc117eb43d0..e8bfe8d36e8839cf253103f1a6ae0cf2e32b0581 100644 --- a/src/ast/ast_subshell.c +++ b/src/ast/ast_subshell.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Tue Aug 29 00:07:12 2006 Seblu +** Last update Tue Sep 26 17:43:33 2006 Seblu */ #include "ast.h" @@ -21,6 +21,18 @@ s_ast_node *ast_subshell_create(s_ast_node *child) return node; } +void ast_subshell_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, cur_id; + + if (node->type != T_SUBSHELL) + return; + fprintf(fs, "%u [label = \"()\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_subshell.lhs, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); +} + void ast_subshell_destruct(s_ast_node *node) { if (node->type != T_SUBSHELL) diff --git a/src/ast/ast_until.c b/src/ast/ast_until.c index c1ef1fa60e741b610ee8eede7b0df2964d0ad838..6ae9af5fe599cff880ec027d854b8189a016365e 100644 --- a/src/ast/ast_until.c +++ b/src/ast/ast_until.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Tue Aug 29 00:01:11 2006 Seblu +** Last update Tue Sep 26 17:44:32 2006 Seblu */ #include "ast.h" @@ -21,6 +21,21 @@ s_ast_node *ast_until_create(s_ast_node *cond, s_ast_node *exec) return node; } +void ast_until_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, rhs_id, cur_id; + + if (node->type != T_UNTIL) + return; + fprintf(fs, "%u [label = \"until\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_until.cond, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); + rhs_id = *node_id; + ast_print_node(node->body.child_until.exec, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, rhs_id); +} + void ast_until_destruct(s_ast_node *node) { if (node->type != T_UNTIL) diff --git a/src/ast/ast_while.c b/src/ast/ast_while.c index e86ccd1101af1ec6fc752de12f1191b2995b1e7f..a62b2081490dac4e72746b36d967fd8f1eb59802 100644 --- a/src/ast/ast_while.c +++ b/src/ast/ast_while.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Thu Aug 3 02:41:37 2006 Seblu -** Last update Tue Aug 29 00:01:57 2006 Seblu +** Last update Tue Sep 26 17:44:08 2006 Seblu */ #include "ast.h" @@ -21,6 +21,21 @@ s_ast_node *ast_while_create(s_ast_node *cond, s_ast_node *exec) return node; } +void ast_while_print(s_ast_node *node, FILE *fs, unsigned int *node_id) +{ + unsigned int lhs_id, rhs_id, cur_id; + + if (node->type != T_WHILE) + return; + fprintf(fs, "%u [label = \"while\"];\n", cur_id = *node_id); + lhs_id = ++*node_id; + ast_print_node(node->body.child_while.cond, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, lhs_id); + rhs_id = *node_id; + ast_print_node(node->body.child_while.exec, fs, node_id); + fprintf(fs, "%u -> %u\n", cur_id, rhs_id); +} + void ast_while_destruct(s_ast_node *node) { if (node->type != T_WHILE) diff --git a/src/parser/parser.c b/src/parser/parser.c index 65decb0f55f05990b4558a090981c04af941af8e..91c93d64955af4edbdc74e60de164fdce95bbc80 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -5,7 +5,7 @@ ** Login ** ** Started on Wed Aug 2 00:56:07 2006 Seblu -** Last update Mon Sep 25 04:44:08 2006 Seblu +** Last update Tue Sep 26 17:59:36 2006 Seblu */ #include @@ -82,6 +82,7 @@ static s_ast_node *parse_rulewhile(s_parser *parser); static s_ast_node *parse_ruleuntil(s_parser *parser); static s_ast_node *parse_ruleif(s_parser *parser); static s_ast_node *parse_rulecase(s_parser *parser); +static s_ast_node *parse_compound_list(s_parser *parser); /*! ** Notify a parse error @@ -131,7 +132,6 @@ static s_ast_node *regnode(s_parser *parser, s_ast_node *node) static void parse_error(s_parser *parser, s_token t) { - debugmsg("parse_error"); fprintf(stderr, "%s: syntax error near unexpected token `%s'\n", shell->name, t.str); parser->error = 1; @@ -268,6 +268,14 @@ static s_ast_node *parse_pipeline(s_parser *parser) banged = 1; } lhs = parse_command(parser); +/* if ((token = lexer_lookahead(parser->lexer)) == TOK_PIPE) { */ +/* lexer_gettoken(parser->lexer); */ +/* while (lexer_lookahead(parser->lexer) == TOK_NEWLINE) */ +/* lexer_gettoken(parser->lexer); */ +/* parse_pipeline( */ +/* } */ + if (banged) + return regnode(parser, ast_bang_create(lhs)); return lhs; } @@ -279,11 +287,11 @@ static s_ast_node *parse_command(s_parser *parser) token = lexer_lookahead(parser->lexer); recon(&token); if (token.id == TOK_FOR || token.id == TOK_WHILE || token.id == TOK_UNTIL || - token.id == TOK_CASE || token.id == TOK_IF || - !strcmp(token.str, "{") || !strcmp(token.str, "(")) + token.id == TOK_CASE || token.id == TOK_IF || token.id == TOK_LBRACE || + !strcmp(token.str, "(")) return parse_shellcommand(parser); // probleme de choix avec function pour l'instant ya pas defonction ! - else if (token.id == TOK_WORD) { + else if (token.id >= TOK_DLESSDASH && token.id <= TOK_WORD) { return parse_simplecommand(parser); } else @@ -355,20 +363,20 @@ static s_ast_node *parse_shellcommand(s_parser *parser) debugmsg("parse_shellcommand"); token = lexer_lookahead(parser->lexer); + recon(&token); switch (token.id) { - case TOK_IF: parse_ruleif(parser); break; - case TOK_FOR: parse_rulefor(parser); break; - case TOK_WHILE: parse_rulewhile(parser); break; - case TOK_UNTIL: parse_ruleuntil(parser); break; - case TOK_CASE: parse_rulecase(parser); break; + case TOK_IF: return parse_ruleif(parser); + case TOK_FOR: return parse_rulefor(parser); + case TOK_WHILE: return parse_rulewhile(parser); + case TOK_UNTIL: return parse_ruleuntil(parser); + case TOK_CASE: return parse_rulecase(parser); + case TOK_LBRACE: assert(0); case TOK_WORD: - //gerer le cas de { et de ( - assert(0); - break; + if (!strcmp(token.str, "(")) + return regnode(parser, ast_subshell_create(parse_compound_list(parser))); default: parse_error(parser, token); } - return NULL; } @@ -381,7 +389,7 @@ static s_ast_node *parse_shellcommand(s_parser *parser) static void parse_redirection(s_parser *parser, s_ast_node *cmd) { s_token token; - long int fd; + long int fd = -1; e_redir_type redtype; debugmsg("parse_redirection"); @@ -396,15 +404,15 @@ static void parse_redirection(s_parser *parser, s_ast_node *cmd) //retrieve redirection type token = lexer_gettoken(parser->lexer); switch (token.id) { - case TOK_GREAT: redtype = R_GREAT; break; - case TOK_DGREAT: redtype = R_DLESS; break; - case TOK_DLESSDASH: redtype = R_DLESSDASH; break; - case TOK_DLESS: redtype = R_DLESS; break; - case TOK_LESSGREAT: redtype = R_LESSGREAT; break; - case TOK_LESSAND: redtype = R_LESSAND; break; - case TOK_LESS: redtype = R_LESS; break; - case TOK_CLOBBER: redtype = R_CLOBBER; break; - case TOK_GREATAND: redtype = R_GREATAND; break; + case TOK_GREAT: redtype = R_GREAT; if (fd == -1) fd = 1; break; + case TOK_DGREAT: redtype = R_DLESS; if (fd == -1) fd = 1; break; + case TOK_DLESSDASH: redtype = R_DLESSDASH; if (fd == -1) fd = 0; break; + case TOK_DLESS: redtype = R_DLESS; if (fd == -1) fd = 0; break; + case TOK_LESSGREAT: redtype = R_LESSGREAT; if (fd == -1) fd = 0; break; + case TOK_LESSAND: redtype = R_LESSAND; if (fd == -1) fd = 0; break; + case TOK_LESS: redtype = R_LESS; if (fd == -1) fd = 0; break; + case TOK_CLOBBER: redtype = R_CLOBBER; if (fd == -1) fd = 1; break; + case TOK_GREATAND: redtype = R_GREATAND; if (fd == -1) fd = 1; break; default: parse_error(parser, token); } @@ -416,11 +424,11 @@ static void parse_redirection(s_parser *parser, s_ast_node *cmd) parse_error(parser, token); } -/* static s_ast_node *parse_compound_list(s_parser *parser) */ -/* { */ -/* parser=parser; */ -/* return NULL; */ -/* } */ +static s_ast_node *parse_compound_list(s_parser *parser) +{ + parser=parser; + return NULL; +} static s_ast_node *parse_rulefor(s_parser *parser) { diff --git a/src/parser/parser.h b/src/parser/parser.h index ac44e22c40dc11fbadea0e6900afc4ee56c8f75f..64711e00240de2c2f5e7a79f86c0dbd132eeb7ae 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -5,7 +5,7 @@ ** Login ** ** Started on Wed Aug 2 00:49:50 2006 Seblu -** Last update Mon Sep 25 03:41:31 2006 Seblu +** Last update Mon Sep 25 05:20:21 2006 Seblu */ #include @@ -43,25 +43,24 @@ typedef enum tokenid TOK_GREAT, // > TOK_IONUMBER, // number juste before '>' or '<' TOK_WORD, // all others + //token context-sensitive recognition (parser time) - TOK_IF, - TOK_THEN, - TOK_ELSE, - TOK_FI, - TOK_ELIF, - TOK_DO, - TOK_DONE, - TOK_CASE, - TOK_ESAC, - TOK_WHILE, - TOK_UNTIL, - TOK_FOR, - TOK_IN, - TOK_LBRACE, - TOK_RBRACE, - TOK_NUMBER, - TOK_ASSIGNMENT, - TOK_BANG + TOK_IF, // if + TOK_THEN, // then + TOK_ELSE, // else + TOK_FI, // fi + TOK_ELIF, // elif + TOK_DO, // do + TOK_DONE, // done + TOK_CASE, // case + TOK_ESAC, // esac + TOK_WHILE, // while + TOK_UNTIL, // until + TOK_FOR, // for + TOK_IN, // in + TOK_LBRACE, // { + TOK_RBRACE, // } + TOK_BANG // ! } e_tokenid; typedef struct token