📄 parse.y
字号:
$$ = make_redirection (source, r_output_force, redir, 0); } | NUMBER GREATER_BAR WORD { source.dest = $1; redir.filename = $3; $$ = make_redirection (source, r_output_force, redir, 0); } | REDIR_WORD GREATER_BAR WORD { source.filename = $1; redir.filename = $3; $$ = make_redirection (source, r_output_force, redir, REDIR_VARASSIGN); } | LESS_GREATER WORD { source.dest = 0; redir.filename = $2; $$ = make_redirection (source, r_input_output, redir, 0); } | NUMBER LESS_GREATER WORD { source.dest = $1; redir.filename = $3; $$ = make_redirection (source, r_input_output, redir, 0); } | REDIR_WORD LESS_GREATER WORD { source.filename = $1; redir.filename = $3; $$ = make_redirection (source, r_input_output, redir, REDIR_VARASSIGN); } | LESS_LESS WORD { source.dest = 0; redir.filename = $2; $$ = make_redirection (source, r_reading_until, redir, 0); redir_stack[need_here_doc++] = $$; } | NUMBER LESS_LESS WORD { source.dest = $1; redir.filename = $3; $$ = make_redirection (source, r_reading_until, redir, 0); redir_stack[need_here_doc++] = $$; } | REDIR_WORD LESS_LESS WORD { source.filename = $1; redir.filename = $3; $$ = make_redirection (source, r_reading_until, redir, REDIR_VARASSIGN); redir_stack[need_here_doc++] = $$; } | LESS_LESS_MINUS WORD { source.dest = 0; redir.filename = $2; $$ = make_redirection (source, r_deblank_reading_until, redir, 0); redir_stack[need_here_doc++] = $$; } | NUMBER LESS_LESS_MINUS WORD { source.dest = $1; redir.filename = $3; $$ = make_redirection (source, r_deblank_reading_until, redir, 0); redir_stack[need_here_doc++] = $$; } | REDIR_WORD LESS_LESS_MINUS WORD { source.filename = $1; redir.filename = $3; $$ = make_redirection (source, r_deblank_reading_until, redir, REDIR_VARASSIGN); redir_stack[need_here_doc++] = $$; } | LESS_LESS_LESS WORD { source.dest = 0; redir.filename = $2; $$ = make_redirection (source, r_reading_string, redir, 0); } | NUMBER LESS_LESS_LESS WORD { source.dest = $1; redir.filename = $3; $$ = make_redirection (source, r_reading_string, redir, 0); } | REDIR_WORD LESS_LESS_LESS WORD { source.filename = $1; redir.filename = $3; $$ = make_redirection (source, r_reading_string, redir, REDIR_VARASSIGN); } | LESS_AND NUMBER { source.dest = 0; redir.dest = $2; $$ = make_redirection (source, r_duplicating_input, redir, 0); } | NUMBER LESS_AND NUMBER { source.dest = $1; redir.dest = $3; $$ = make_redirection (source, r_duplicating_input, redir, 0); } | REDIR_WORD LESS_AND NUMBER { source.filename = $1; redir.dest = $3; $$ = make_redirection (source, r_duplicating_input, redir, REDIR_VARASSIGN); } | GREATER_AND NUMBER { source.dest = 1; redir.dest = $2; $$ = make_redirection (source, r_duplicating_output, redir, 0); } | NUMBER GREATER_AND NUMBER { source.dest = $1; redir.dest = $3; $$ = make_redirection (source, r_duplicating_output, redir, 0); } | REDIR_WORD GREATER_AND NUMBER { source.filename = $1; redir.dest = $3; $$ = make_redirection (source, r_duplicating_output, redir, REDIR_VARASSIGN); } | LESS_AND WORD { source.dest = 0; redir.filename = $2; $$ = make_redirection (source, r_duplicating_input_word, redir, 0); } | NUMBER LESS_AND WORD { source.dest = $1; redir.filename = $3; $$ = make_redirection (source, r_duplicating_input_word, redir, 0); } | REDIR_WORD LESS_AND WORD { source.filename = $1; redir.filename = $3; $$ = make_redirection (source, r_duplicating_input_word, redir, REDIR_VARASSIGN); } | GREATER_AND WORD { source.dest = 1; redir.filename = $2; $$ = make_redirection (source, r_duplicating_output_word, redir, 0); } | NUMBER GREATER_AND WORD { source.dest = $1; redir.filename = $3; $$ = make_redirection (source, r_duplicating_output_word, redir, 0); } | REDIR_WORD GREATER_AND WORD { source.filename = $1; redir.filename = $3; $$ = make_redirection (source, r_duplicating_output_word, redir, REDIR_VARASSIGN); } | GREATER_AND '-' { source.dest = 1; redir.dest = 0; $$ = make_redirection (source, r_close_this, redir, 0); } | NUMBER GREATER_AND '-' { source.dest = $1; redir.dest = 0; $$ = make_redirection (source, r_close_this, redir, 0); } | REDIR_WORD GREATER_AND '-' { source.filename = $1; redir.dest = 0; $$ = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); } | LESS_AND '-' { source.dest = 0; redir.dest = 0; $$ = make_redirection (source, r_close_this, redir, 0); } | NUMBER LESS_AND '-' { source.dest = $1; redir.dest = 0; $$ = make_redirection (source, r_close_this, redir, 0); } | REDIR_WORD LESS_AND '-' { source.filename = $1; redir.dest = 0; $$ = make_redirection (source, r_close_this, redir, REDIR_VARASSIGN); } | AND_GREATER WORD { source.dest = 1; redir.filename = $2; $$ = make_redirection (source, r_err_and_out, redir, 0); } | AND_GREATER_GREATER WORD { source.dest = 1; redir.filename = $2; $$ = make_redirection (source, r_append_err_and_out, redir, 0); } ;simple_command_element: WORD { $$.word = $1; $$.redirect = 0; } | ASSIGNMENT_WORD { $$.word = $1; $$.redirect = 0; } | redirection { $$.redirect = $1; $$.word = 0; } ;redirection_list: redirection { $$ = $1; } | redirection_list redirection { register REDIRECT *t; for (t = $1; t->next; t = t->next) ; t->next = $2; $$ = $1; } ;simple_command: simple_command_element { $$ = make_simple_command ($1, (COMMAND *)NULL); } | simple_command simple_command_element { $$ = make_simple_command ($2, $1); } ;command: simple_command { $$ = clean_simple_command ($1); } | shell_command { $$ = $1; } | shell_command redirection_list { COMMAND *tc; tc = $1; if (tc->redirects) { register REDIRECT *t; for (t = tc->redirects; t->next; t = t->next) ; t->next = $2; } else tc->redirects = $2; $$ = $1; } | function_def { $$ = $1; } | coproc { $$ = $1; } ;shell_command: for_command { $$ = $1; } | case_command { $$ = $1; } | WHILE compound_list DO compound_list DONE { $$ = make_while_command ($2, $4); } | UNTIL compound_list DO compound_list DONE { $$ = make_until_command ($2, $4); } | select_command { $$ = $1; } | if_command { $$ = $1; } | subshell { $$ = $1; } | group_command { $$ = $1; } | arith_command { $$ = $1; } | cond_command { $$ = $1; } | arith_for_command { $$ = $1; } ;for_command: FOR WORD newline_list DO compound_list DONE { $$ = make_for_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $5, word_lineno[word_top]); if (word_top > 0) word_top--; } | FOR WORD newline_list '{' compound_list '}' { $$ = make_for_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $5, word_lineno[word_top]); if (word_top > 0) word_top--; } | FOR WORD ';' newline_list DO compound_list DONE { $$ = make_for_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $6, word_lineno[word_top]); if (word_top > 0) word_top--; } | FOR WORD ';' newline_list '{' compound_list '}' { $$ = make_for_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $6, word_lineno[word_top]); if (word_top > 0) word_top--; } | FOR WORD newline_list IN word_list list_terminator newline_list DO compound_list DONE { $$ = make_for_command ($2, REVERSE_LIST ($5, WORD_LIST *), $9, word_lineno[word_top]); if (word_top > 0) word_top--; } | FOR WORD newline_list IN word_list list_terminator newline_list '{' compound_list '}' { $$ = make_for_command ($2, REVERSE_LIST ($5, WORD_LIST *), $9, word_lineno[word_top]); if (word_top > 0) word_top--; } | FOR WORD newline_list IN list_terminator newline_list DO compound_list DONE { $$ = make_for_command ($2, (WORD_LIST *)NULL, $8, word_lineno[word_top]); if (word_top > 0) word_top--; } | FOR WORD newline_list IN list_terminator newline_list '{' compound_list '}' { $$ = make_for_command ($2, (WORD_LIST *)NULL, $8, word_lineno[word_top]); if (word_top > 0) word_top--; } ;arith_for_command: FOR ARITH_FOR_EXPRS list_terminator newline_list DO compound_list DONE { $$ = make_arith_for_command ($2, $6, arith_for_lineno); if (word_top > 0) word_top--; } | FOR ARITH_FOR_EXPRS list_terminator newline_list '{' compound_list '}' { $$ = make_arith_for_command ($2, $6, arith_for_lineno); if (word_top > 0) word_top--; } | FOR ARITH_FOR_EXPRS DO compound_list DONE { $$ = make_arith_for_command ($2, $4, arith_for_lineno); if (word_top > 0) word_top--; } | FOR ARITH_FOR_EXPRS '{' compound_list '}' { $$ = make_arith_for_command ($2, $4, arith_for_lineno); if (word_top > 0) word_top--; } ;select_command: SELECT WORD newline_list DO list DONE { $$ = make_select_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $5, word_lineno[word_top]); if (word_top > 0) word_top--; } | SELECT WORD newline_list '{' list '}' { $$ = make_select_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $5, word_lineno[word_top]); if (word_top > 0) word_top--; } | SELECT WORD ';' newline_list DO list DONE { $$ = make_select_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $6, word_lineno[word_top]); if (word_top > 0) word_top--; } | SELECT WORD ';' newline_list '{' list '}' { $$ = make_select_command ($2, add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), $6, word_lineno[word_top]); if (word_top > 0) word_top--; } | SELECT WORD newline_list IN word_list list_terminator newline_list DO list DONE { $$ = make_select_command ($2, REVERSE_LIST ($5, WORD_LIST *), $9, word_lineno[word_top]); if (word_top > 0) word_top--; } | SELECT WORD newline_list IN word_list list_terminator newline_list '{' list '}' { $$ = make_select_command ($2, REVERSE_LIST ($5, WORD_LIST *), $9, word_lineno[word_top]); if (word_top > 0) word_top--; } ;case_command: CASE WORD newline_list IN newline_list ESAC { $$ = make_case_command ($2, (PATTERN_LIST *)NULL, word_lineno[word_top]); if (word_top > 0) word_top--; } | CASE WORD newline_list IN case_clause_sequence newline_list ESAC { $$ = make_case_command ($2, $5, word_lineno[word_top]); if (word_top > 0) word_top--; } | CASE WORD newline_list IN case_clause ESAC { $$ = make_case_command ($2, $5, word_lineno[word_top]); if (word_top > 0) word_top--; } ;function_def: WORD '(' ')' newline_list function_body { $$ = make_function_def ($1, $5, function_dstart, function_bstart); } | FUNCTION WORD '(' ')' newline_list function_body { $$ = make_function_def ($2, $6, function_dstart, function_bstart); } | FUNCTION WORD newline_list function_body { $$ = make_function_def ($2, $4, function_dstart, function_bstart); } ;function_body: shell_command { $$ = $1; } | shell_command redirection_list { COMMAND *tc; tc = $1; /* According to Posix.2 3.9.5, redirections specified after the body of a function should be attached to the function and performed when the function is executed, not as part of the function definition command. */ /* XXX - I don't think it matters, but we might want to change this in the future to avoid problems differentiating between a function definition with a redirection and a function definition containing a single command with a redirection. The two are semantically equivalent, though -- the only difference is in how the command printing code displays the redirections. */ if (tc->redirects) { register REDIRECT *t; for (t = tc->redirects; t->next; t = t->next) ; t->next = $2; } else tc->redirects = $2; $$ = $1; } ;subshell: '(' compound_list ')' { $$ = make_subshell_command ($2); $$->flags |= CMD_WANT_SUBSHELL; } ;coproc: COPROC shell_command { $$ = make_coproc_command ("COPROC", $2); $$->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; } | COPROC shell_command redirection_list { COMMAND *tc; tc = $2; if (tc->redirects) { register REDIRECT *t; for (t = tc->redirects; t->next; t = t->next) ; t->next = $3; } else tc->redirects = $3; $$ = make_coproc_command ("COPROC", $2); $$->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; } | COPROC WORD shell_command { $$ = make_coproc_command ($2->word, $3); $$->flags |= CMD_WANT_SUBSHELL|CMD_COPROC_SUBSHELL; } | COPROC WORD shell_command redirection_list
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -