Loading GRAMMAR +11 −10 Original line number Diff line number Diff line Loading @@ -13,7 +13,8 @@ command: simple_command | shell_command (redirection)* | funcdec simple_command: (prefix)* (element)+ simple_command: (prefix)+ | (prefix)* (element)+ shell_command: '{' compound_list '}' | '(' compound_list ')' Loading @@ -25,15 +26,15 @@ shell_command: '{' compound_list '}' funcdec: ['function'] WORD '(' ')' ('\n')* shell_command (redirection)* redirection: [NUMBER] '>' WORD | [NUMBER] '<' WORD | [NUMBER] '>>' WORD | [NUMBER] '<<' HEREDOC | [NUMBER] '<<-' HEREDOC | [NUMBER] '>&' WORD | [NUMBER] '<&' WORD | [NUMBER] '>|' WORD | [NUMBER] '<>' WORD redirection: [IONUMBER] '>' WORD | [IONUMBER] '<' WORD | [IONUMBER] '>>' WORD | [IONUMBER] '<<' HEREDOC | [IONUMBER] '<<-' HEREDOC | [IONUMBER] '>&' WORD | [IONUMBER] '<&' WORD | [IONUMBER] '>|' WORD | [IONUMBER] '<>' WORD prefix: ASSIGMENT_WORD | redirection Loading TODO +1 −1 Original line number Diff line number Diff line lexer: verifier si un EOF apparait si le dernier token est bien pris en compte No newline at end of file src/ast/ast_cmd.c +26 −6 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ ** Login <seblu@epita.fr> ** ** Started on Fri Aug 18 22:13:51 2006 Seblu ** Last update Fri Sep 1 00:44:22 2006 Seblu ** Last update Mon Sep 25 04:19:18 2006 Seblu */ #include "ast.h" Loading Loading @@ -83,7 +83,13 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) ++*node_id; fprintf(fs, "%u [label = \"", *node_id); for (int i = 0; prefix && prefix[i]; ++i) { fprintf(fs, "prefix[%d]=%s\\n", i, prefix[i]); fprintf(fs, "prefix[%d]:", i); size_t last = 0, p = 0; for (; prefix[i][p]; ++p) if (prefix[i][p] == '"') fprintf(fs, "%.*s\\", p - last, prefix[i] + last), last = p; fprintf(fs, "%*s", p - last, prefix[i] + last), last = p; fprintf(fs, "\\n"); } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); Loading @@ -93,8 +99,15 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) if (argv && argv[0]) { ++*node_id; fprintf(fs, "%u [label = \"", *node_id); for (int i = 0; argv && argv[i]; ++i) fprintf(fs, "argv[%d]=%s\\n", i, argv[i]); for (int i = 0; argv && argv[i]; ++i) { fprintf(fs, "argv[%d]:", i); size_t last = 0, p = 0; for (; argv[i][p]; ++p) if (argv[i][p] == '"') fprintf(fs, "%.*s\\", p - last, argv[i] + last), last = p; fprintf(fs, "%*s", p - last, argv[i] + last), last = p; fprintf(fs, "\\n"); } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); } Loading @@ -103,8 +116,15 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) 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=%s\\n", i, this->fd, this->type, this->word); 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); size_t last = 0, p = 0; for (; this->word[p]; ++p) if (this->word[p] == '"') fprintf(fs, "%.*s\\", p - last, this->word + last), last = p; fprintf(fs, "%*s", p - last, this->word + last), last = p; fprintf(fs, "\\n"); } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); } Loading src/last-ast.sh +4 −2 Original line number Diff line number Diff line #!/bin/sh shopt -s nullglob for i in /tmp/42sh-ast-*.dot; do last="$i" done echo "$last to echo x${last%*.dot}" test "$last" || exit 1 echo "[$last] to [${last%*.dot}.png]" dot -Tpng $last -o ${last%*.dot}.png ln -sf ${last%*.dot}.png ast.png src/parser/lexer.c +6 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ ** Login <seblu@epita.fr> ** ** Started on Sun Jul 30 04:36:53 2006 Seblu ** Last update Tue Aug 29 21:54:23 2006 Seblu ** Last update Fri Sep 1 02:04:21 2006 Seblu */ #include <stdio.h> Loading Loading @@ -282,6 +282,7 @@ static int lexer_eatline(s_lexer *lexer) static int lexer_cut(s_lexer *lexer) { const char *buf = lexer->buf; char *tokstr; size_t *buf_pos = &lexer->buf_pos, token_start, token_pos; int end_found = 0; char backed = 0, quoted = 0; Loading Loading @@ -321,8 +322,9 @@ static int lexer_cut(s_lexer *lexer) if (end_found) break; } lexer->buf_pos = token_pos; //update real lexer position buffer token_set(&lexer->token, TOK_WORD, strndup(buf + token_start, token_pos - token_start)); tokstr = strndup(buf + token_start, token_pos - token_start); token_set(&lexer->token, ((buf[token_pos] == '>' || buf[token_pos] == '<') && isdigitstr(tokstr)) ? TOK_IONUMBER : TOK_WORD, tokstr); return 1; } Loading Loading
GRAMMAR +11 −10 Original line number Diff line number Diff line Loading @@ -13,7 +13,8 @@ command: simple_command | shell_command (redirection)* | funcdec simple_command: (prefix)* (element)+ simple_command: (prefix)+ | (prefix)* (element)+ shell_command: '{' compound_list '}' | '(' compound_list ')' Loading @@ -25,15 +26,15 @@ shell_command: '{' compound_list '}' funcdec: ['function'] WORD '(' ')' ('\n')* shell_command (redirection)* redirection: [NUMBER] '>' WORD | [NUMBER] '<' WORD | [NUMBER] '>>' WORD | [NUMBER] '<<' HEREDOC | [NUMBER] '<<-' HEREDOC | [NUMBER] '>&' WORD | [NUMBER] '<&' WORD | [NUMBER] '>|' WORD | [NUMBER] '<>' WORD redirection: [IONUMBER] '>' WORD | [IONUMBER] '<' WORD | [IONUMBER] '>>' WORD | [IONUMBER] '<<' HEREDOC | [IONUMBER] '<<-' HEREDOC | [IONUMBER] '>&' WORD | [IONUMBER] '<&' WORD | [IONUMBER] '>|' WORD | [IONUMBER] '<>' WORD prefix: ASSIGMENT_WORD | redirection Loading
TODO +1 −1 Original line number Diff line number Diff line lexer: verifier si un EOF apparait si le dernier token est bien pris en compte No newline at end of file
src/ast/ast_cmd.c +26 −6 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ ** Login <seblu@epita.fr> ** ** Started on Fri Aug 18 22:13:51 2006 Seblu ** Last update Fri Sep 1 00:44:22 2006 Seblu ** Last update Mon Sep 25 04:19:18 2006 Seblu */ #include "ast.h" Loading Loading @@ -83,7 +83,13 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) ++*node_id; fprintf(fs, "%u [label = \"", *node_id); for (int i = 0; prefix && prefix[i]; ++i) { fprintf(fs, "prefix[%d]=%s\\n", i, prefix[i]); fprintf(fs, "prefix[%d]:", i); size_t last = 0, p = 0; for (; prefix[i][p]; ++p) if (prefix[i][p] == '"') fprintf(fs, "%.*s\\", p - last, prefix[i] + last), last = p; fprintf(fs, "%*s", p - last, prefix[i] + last), last = p; fprintf(fs, "\\n"); } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); Loading @@ -93,8 +99,15 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) if (argv && argv[0]) { ++*node_id; fprintf(fs, "%u [label = \"", *node_id); for (int i = 0; argv && argv[i]; ++i) fprintf(fs, "argv[%d]=%s\\n", i, argv[i]); for (int i = 0; argv && argv[i]; ++i) { fprintf(fs, "argv[%d]:", i); size_t last = 0, p = 0; for (; argv[i][p]; ++p) if (argv[i][p] == '"') fprintf(fs, "%.*s\\", p - last, argv[i] + last), last = p; fprintf(fs, "%*s", p - last, argv[i] + last), last = p; fprintf(fs, "\\n"); } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); } Loading @@ -103,8 +116,15 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id) 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=%s\\n", i, this->fd, this->type, this->word); 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); size_t last = 0, p = 0; for (; this->word[p]; ++p) if (this->word[p] == '"') fprintf(fs, "%.*s\\", p - last, this->word + last), last = p; fprintf(fs, "%*s", p - last, this->word + last), last = p; fprintf(fs, "\\n"); } fprintf(fs, "\"];\n"); fprintf(fs, "%u -> %u\n", cur_id, *node_id); } Loading
src/last-ast.sh +4 −2 Original line number Diff line number Diff line #!/bin/sh shopt -s nullglob for i in /tmp/42sh-ast-*.dot; do last="$i" done echo "$last to echo x${last%*.dot}" test "$last" || exit 1 echo "[$last] to [${last%*.dot}.png]" dot -Tpng $last -o ${last%*.dot}.png ln -sf ${last%*.dot}.png ast.png
src/parser/lexer.c +6 −4 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ ** Login <seblu@epita.fr> ** ** Started on Sun Jul 30 04:36:53 2006 Seblu ** Last update Tue Aug 29 21:54:23 2006 Seblu ** Last update Fri Sep 1 02:04:21 2006 Seblu */ #include <stdio.h> Loading Loading @@ -282,6 +282,7 @@ static int lexer_eatline(s_lexer *lexer) static int lexer_cut(s_lexer *lexer) { const char *buf = lexer->buf; char *tokstr; size_t *buf_pos = &lexer->buf_pos, token_start, token_pos; int end_found = 0; char backed = 0, quoted = 0; Loading Loading @@ -321,8 +322,9 @@ static int lexer_cut(s_lexer *lexer) if (end_found) break; } lexer->buf_pos = token_pos; //update real lexer position buffer token_set(&lexer->token, TOK_WORD, strndup(buf + token_start, token_pos - token_start)); tokstr = strndup(buf + token_start, token_pos - token_start); token_set(&lexer->token, ((buf[token_pos] == '>' || buf[token_pos] == '<') && isdigitstr(tokstr)) ? TOK_IONUMBER : TOK_WORD, tokstr); return 1; } Loading