1 /* A Bison parser, made by GNU Bison 3.8.2. */
3 /* Bison implementation for Yacc-like parsers in C
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
37 /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
38 especially those whose name start with YY_ or yy_. They are
39 private implementation details that can be changed or removed. */
41 /* All symbols defined below should begin with yy or YY, to avoid
42 infringing on user name space. This should be done even for local
43 variables, as they might otherwise be expanded by user macros.
44 There are some unavoidable exceptions within include files to
45 define necessary library symbols; they are noted "INFRINGES ON
46 USER NAME SPACE" below. */
48 /* Identify Bison output, and Bison version. */
51 /* Bison version string. */
52 #define YYBISON_VERSION "3.8.2"
55 #define YYSKELETON_NAME "yacc.c"
69 /* First part of user prologue. */
70 #line 21 "/usr/local/src/chet/src/bash/src/parse.y"
74 #include "bashtypes.h"
79 #if defined (HAVE_UNISTD_H)
83 #if defined (HAVE_LOCALE_H)
88 #include "chartypes.h"
95 #define NEED_STRFTIME_DECL /* used in externs.h */
98 #include "execute_cmd.h"
99 #include "typemax.h" /* SIZE_MAX if needed */
103 #include "mailcheck.h"
105 #include "builtins.h"
106 #include "builtins/common.h"
107 #include "builtins/builtext.h"
109 #include "shmbutil.h"
111 #if defined (READLINE)
112 # include "bashline.h"
113 # include <readline/readline.h>
114 #endif /* READLINE */
116 #if defined (HISTORY)
117 # include "bashhist.h"
118 # include <readline/history.h>
121 #if defined (JOB_CONTROL)
124 extern int cleanup_dead_jobs
PARAMS((void));
125 #endif /* JOB_CONTROL */
130 typedef void *alias_t
;
133 #if defined (PROMPT_STRING_DECODE)
135 # include <sys/param.h>
138 # if defined (TM_IN_SYS_TIME)
139 # include <sys/types.h>
140 # include <sys/time.h>
141 # endif /* TM_IN_SYS_TIME */
142 # include "maxpath.h"
143 #endif /* PROMPT_STRING_DECODE */
145 #define RE_READ_TOKEN -99
146 #define NO_EXPANSION -100
156 #if defined (HANDLE_MULTIBYTE)
157 # define last_shell_getc_is_singlebyte \
158 ((shell_input_line_index > 1) \
159 ? shell_input_line_property[shell_input_line_index - 1] \
161 # define MBTEST(x) ((x) && last_shell_getc_is_singlebyte)
163 # define last_shell_getc_is_singlebyte 1
164 # define MBTEST(x) ((x))
167 #define EXTEND_SHELL_INPUT_LINE_PROPERTY() \
169 if (shell_input_line_len + 2 > shell_input_line_propsize) \
171 shell_input_line_propsize = shell_input_line_len + 2; \
172 shell_input_line_property = (char *)xrealloc (shell_input_line_property, \
173 shell_input_line_propsize); \
177 #if defined (EXTENDED_GLOB)
178 extern int extended_glob
, extglob_flag
;
181 #if defined (TRANSLATABLE_STRINGS)
182 extern int dump_translatable_strings
, dump_po_strings
;
183 extern int singlequote_translations
;
184 #endif /* TRANSLATABLE_STRINGS */
190 /* **************************************************************** */
192 /* "Forward" declarations */
194 /* **************************************************************** */
197 static void debug_parser
PARAMS((int));
200 static int yy_getc
PARAMS((void));
201 static int yy_ungetc
PARAMS((int));
203 #if defined (READLINE)
204 static int yy_readline_get
PARAMS((void));
205 static int yy_readline_unget
PARAMS((int));
208 static int yy_string_get
PARAMS((void));
209 static int yy_string_unget
PARAMS((int));
210 static int yy_stream_get
PARAMS((void));
211 static int yy_stream_unget
PARAMS((int));
213 static int shell_getc
PARAMS((int));
214 static void shell_ungetc
PARAMS((int));
215 static void discard_until
PARAMS((int));
217 static void push_string
PARAMS((char *, int, alias_t
*));
218 static void pop_string
PARAMS((void));
219 static void free_string_list
PARAMS((void));
221 static char *read_a_line
PARAMS((int));
223 static int reserved_word_acceptable
PARAMS((int));
224 static int yylex
PARAMS((void));
226 static void push_heredoc
PARAMS((REDIRECT
*));
227 static char *mk_alexpansion
PARAMS((char *));
228 static int alias_expand_token
PARAMS((char *));
229 static int time_command_acceptable
PARAMS((void));
230 static int special_case_tokens
PARAMS((char *));
231 static int read_token
PARAMS((int));
232 static char *parse_matched_pair
PARAMS((int, int, int, int *, int));
233 static char *parse_comsub
PARAMS((int, int, int, int *, int));
234 #if defined (ARRAY_VARS)
235 static char *parse_compound_assignment
PARAMS((int *));
237 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
238 static int parse_dparen
PARAMS((int));
239 static int parse_arith_cmd
PARAMS((char **, int));
241 #if defined (COND_COMMAND)
242 static void cond_error
PARAMS((void));
243 static COND_COM
*cond_expr
PARAMS((void));
244 static COND_COM
*cond_or
PARAMS((void));
245 static COND_COM
*cond_and
PARAMS((void));
246 static COND_COM
*cond_term
PARAMS((void));
247 static int cond_skip_newlines
PARAMS((void));
248 static COMMAND
*parse_cond_command
PARAMS((void));
250 #if defined (ARRAY_VARS)
251 static int token_is_assignment
PARAMS((char *, int));
252 static int token_is_ident
PARAMS((char *, int));
254 static int read_token_word
PARAMS((int));
255 static void discard_parser_constructs
PARAMS((int));
257 static char *error_token_from_token
PARAMS((int));
258 static char *error_token_from_text
PARAMS((void));
259 static void print_offending_line
PARAMS((void));
260 static void report_syntax_error
PARAMS((char *));
262 static void handle_eof_input_unit
PARAMS((void));
263 static void prompt_again
PARAMS((int));
265 static void reset_readline_prompt
PARAMS((void));
267 static void print_prompt
PARAMS((void));
269 #if defined (HANDLE_MULTIBYTE)
270 static void set_line_mbstate
PARAMS((void));
271 static char *shell_input_line_property
= NULL
;
272 static size_t shell_input_line_propsize
= 0;
274 # define set_line_mbstate()
277 extern int yyerror
PARAMS((const char *));
283 /* Default prompt strings */
284 char *primary_prompt
= PPROMPT
;
285 char *secondary_prompt
= SPROMPT
;
287 /* PROMPT_STRING_POINTER points to one of these, never to an actual string. */
288 char *ps1_prompt
, *ps2_prompt
;
290 /* Displayed after reading a command but before executing it in an interactive shell */
293 /* Handle on the current prompt string. Indirectly points through
294 ps1_ or ps2_prompt. */
295 char **prompt_string_pointer
= (char **)NULL
;
296 char *current_prompt_string
;
298 /* Non-zero means we expand aliases in commands. */
299 int expand_aliases
= 0;
301 /* If non-zero, the decoded prompt string undergoes parameter and
302 variable substitution, command substitution, arithmetic substitution,
303 string expansion, process substitution, and quote removal in
304 decode_prompt_string. */
307 /* If non-zero, $'...' and $"..." are expanded when they appear within
308 a ${...} expansion, even when the expansion appears within double
310 int extended_quote
= 1;
312 /* The number of lines read from input while creating the current command. */
313 int current_command_line_count
;
315 /* The number of lines in a command saved while we run parse_and_execute */
316 int saved_command_line_count
;
318 /* The token that currently denotes the end of parse. */
321 /* The token currently being read. */
324 /* The current parser state. */
327 /* Variables to manage the task of reading here documents, because we need to
328 defer the reading until after a complete command has been collected. */
329 static REDIRECT
*redir_stack
[HEREDOC_MAX
];
332 /* Where shell input comes from. History expansion is performed on each
333 line when the shell is interactive. */
334 static char *shell_input_line
= (char *)NULL
;
335 static size_t shell_input_line_index
;
336 static size_t shell_input_line_size
; /* Amount allocated for shell_input_line. */
337 static size_t shell_input_line_len
; /* strlen (shell_input_line) */
339 /* Either zero or EOF. */
340 static int shell_input_line_terminator
;
342 /* The line number in a script on which a function definition starts. */
343 static int function_dstart
;
345 /* The line number in a script on which a function body starts. */
346 static int function_bstart
;
348 /* The line number in a script at which an arithmetic for command starts. */
349 static int arith_for_lineno
;
351 /* The decoded prompt string. Used if READLINE is not defined or if
352 editing is turned off. Analogous to current_readline_prompt. */
353 static char *current_decoded_prompt
;
355 /* The last read token, or NULL. read_token () uses this for context
357 static int last_read_token
;
359 /* The token read prior to last_read_token. */
360 static int token_before_that
;
362 /* The token read prior to token_before_that. */
363 static int two_tokens_ago
;
365 static int global_extglob
;
367 /* The line number in a script where the word in a `case WORD', `select WORD'
368 or `for WORD' begins. This is a nested command maximum, since the array
369 index is decremented after a case, select, or for command is parsed. */
370 #define MAX_CASE_NEST 128
371 static int word_lineno
[MAX_CASE_NEST
+1];
372 static int word_top
= -1;
374 /* If non-zero, it is the token that we want read_token to return
375 regardless of what text is (or isn't) present to be read. This
376 is reset by read_token. If token_to_read == WORD or
377 ASSIGNMENT_WORD, yylval.word should be set to word_desc_to_read. */
378 static int token_to_read
;
379 static WORD_DESC
*word_desc_to_read
;
381 static REDIRECTEE source
;
382 static REDIRECTEE redir
;
384 static FILE *yyoutstream
;
385 static FILE *yyerrstream
;
391 # define YY_CAST(Type, Val) static_cast<Type> (Val)
392 # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
394 # define YY_CAST(Type, Val) ((Type) (Val))
395 # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
399 # if defined __cplusplus
400 # if 201103L <= __cplusplus
401 # define YY_NULLPTR nullptr
403 # define YY_NULLPTR 0
406 # define YY_NULLPTR ((void*)0)
410 /* Use api.header.include to #include this header
411 instead of duplicating it here. */
412 #ifndef YY_YY_Y_TAB_H_INCLUDED
413 # define YY_YY_Y_TAB_H_INCLUDED
428 YYEOF
= 0, /* "end of file" */
429 YYerror
= 256, /* error */
430 YYUNDEF
= 257, /* "invalid token" */
432 THEN
= 259, /* THEN */
433 ELSE
= 260, /* ELSE */
434 ELIF
= 261, /* ELIF */
436 CASE
= 263, /* CASE */
437 ESAC
= 264, /* ESAC */
439 SELECT
= 266, /* SELECT */
440 WHILE
= 267, /* WHILE */
441 UNTIL
= 268, /* UNTIL */
443 DONE
= 270, /* DONE */
444 FUNCTION
= 271, /* FUNCTION */
445 COPROC
= 272, /* COPROC */
446 COND_START
= 273, /* COND_START */
447 COND_END
= 274, /* COND_END */
448 COND_ERROR
= 275, /* COND_ERROR */
450 BANG
= 277, /* BANG */
451 TIME
= 278, /* TIME */
452 TIMEOPT
= 279, /* TIMEOPT */
453 TIMEIGN
= 280, /* TIMEIGN */
454 WORD
= 281, /* WORD */
455 ASSIGNMENT_WORD
= 282, /* ASSIGNMENT_WORD */
456 REDIR_WORD
= 283, /* REDIR_WORD */
457 NUMBER
= 284, /* NUMBER */
458 ARITH_CMD
= 285, /* ARITH_CMD */
459 ARITH_FOR_EXPRS
= 286, /* ARITH_FOR_EXPRS */
460 COND_CMD
= 287, /* COND_CMD */
461 AND_AND
= 288, /* AND_AND */
462 OR_OR
= 289, /* OR_OR */
463 GREATER_GREATER
= 290, /* GREATER_GREATER */
464 LESS_LESS
= 291, /* LESS_LESS */
465 LESS_AND
= 292, /* LESS_AND */
466 LESS_LESS_LESS
= 293, /* LESS_LESS_LESS */
467 GREATER_AND
= 294, /* GREATER_AND */
468 SEMI_SEMI
= 295, /* SEMI_SEMI */
469 SEMI_AND
= 296, /* SEMI_AND */
470 SEMI_SEMI_AND
= 297, /* SEMI_SEMI_AND */
471 LESS_LESS_MINUS
= 298, /* LESS_LESS_MINUS */
472 AND_GREATER
= 299, /* AND_GREATER */
473 AND_GREATER_GREATER
= 300, /* AND_GREATER_GREATER */
474 LESS_GREATER
= 301, /* LESS_GREATER */
475 GREATER_BAR
= 302, /* GREATER_BAR */
476 BAR_AND
= 303, /* BAR_AND */
477 DOLPAREN
= 304, /* DOLPAREN */
478 yacc_EOF
= 305 /* yacc_EOF */
480 typedef enum yytokentype yytoken_kind_t
;
502 #define COND_START 273
504 #define COND_ERROR 275
511 #define ASSIGNMENT_WORD 282
512 #define REDIR_WORD 283
514 #define ARITH_CMD 285
515 #define ARITH_FOR_EXPRS 286
519 #define GREATER_GREATER 290
520 #define LESS_LESS 291
522 #define LESS_LESS_LESS 293
523 #define GREATER_AND 294
524 #define SEMI_SEMI 295
526 #define SEMI_SEMI_AND 297
527 #define LESS_LESS_MINUS 298
528 #define AND_GREATER 299
529 #define AND_GREATER_GREATER 300
530 #define LESS_GREATER 301
531 #define GREATER_BAR 302
537 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
540 #line 338 "/usr/local/src/chet/src/bash/src/parse.y"
542 WORD_DESC
*word
; /* the word that we read. */
543 int number
; /* the number that we read. */
544 WORD_LIST
*word_list
;
548 PATTERN_LIST
*pattern
;
553 typedef union YYSTYPE YYSTYPE
;
554 # define YYSTYPE_IS_TRIVIAL 1
555 # define YYSTYPE_IS_DECLARED 1
559 extern YYSTYPE yylval
;
565 #endif /* !YY_YY_Y_TAB_H_INCLUDED */
569 YYSYMBOL_YYEMPTY
= -2,
570 YYSYMBOL_YYEOF
= 0, /* "end of file" */
571 YYSYMBOL_YYerror
= 1, /* error */
572 YYSYMBOL_YYUNDEF
= 2, /* "invalid token" */
573 YYSYMBOL_IF
= 3, /* IF */
574 YYSYMBOL_THEN
= 4, /* THEN */
575 YYSYMBOL_ELSE
= 5, /* ELSE */
576 YYSYMBOL_ELIF
= 6, /* ELIF */
577 YYSYMBOL_FI
= 7, /* FI */
578 YYSYMBOL_CASE
= 8, /* CASE */
579 YYSYMBOL_ESAC
= 9, /* ESAC */
580 YYSYMBOL_FOR
= 10, /* FOR */
581 YYSYMBOL_SELECT
= 11, /* SELECT */
582 YYSYMBOL_WHILE
= 12, /* WHILE */
583 YYSYMBOL_UNTIL
= 13, /* UNTIL */
584 YYSYMBOL_DO
= 14, /* DO */
585 YYSYMBOL_DONE
= 15, /* DONE */
586 YYSYMBOL_FUNCTION
= 16, /* FUNCTION */
587 YYSYMBOL_COPROC
= 17, /* COPROC */
588 YYSYMBOL_COND_START
= 18, /* COND_START */
589 YYSYMBOL_COND_END
= 19, /* COND_END */
590 YYSYMBOL_COND_ERROR
= 20, /* COND_ERROR */
591 YYSYMBOL_IN
= 21, /* IN */
592 YYSYMBOL_BANG
= 22, /* BANG */
593 YYSYMBOL_TIME
= 23, /* TIME */
594 YYSYMBOL_TIMEOPT
= 24, /* TIMEOPT */
595 YYSYMBOL_TIMEIGN
= 25, /* TIMEIGN */
596 YYSYMBOL_WORD
= 26, /* WORD */
597 YYSYMBOL_ASSIGNMENT_WORD
= 27, /* ASSIGNMENT_WORD */
598 YYSYMBOL_REDIR_WORD
= 28, /* REDIR_WORD */
599 YYSYMBOL_NUMBER
= 29, /* NUMBER */
600 YYSYMBOL_ARITH_CMD
= 30, /* ARITH_CMD */
601 YYSYMBOL_ARITH_FOR_EXPRS
= 31, /* ARITH_FOR_EXPRS */
602 YYSYMBOL_COND_CMD
= 32, /* COND_CMD */
603 YYSYMBOL_AND_AND
= 33, /* AND_AND */
604 YYSYMBOL_OR_OR
= 34, /* OR_OR */
605 YYSYMBOL_GREATER_GREATER
= 35, /* GREATER_GREATER */
606 YYSYMBOL_LESS_LESS
= 36, /* LESS_LESS */
607 YYSYMBOL_LESS_AND
= 37, /* LESS_AND */
608 YYSYMBOL_LESS_LESS_LESS
= 38, /* LESS_LESS_LESS */
609 YYSYMBOL_GREATER_AND
= 39, /* GREATER_AND */
610 YYSYMBOL_SEMI_SEMI
= 40, /* SEMI_SEMI */
611 YYSYMBOL_SEMI_AND
= 41, /* SEMI_AND */
612 YYSYMBOL_SEMI_SEMI_AND
= 42, /* SEMI_SEMI_AND */
613 YYSYMBOL_LESS_LESS_MINUS
= 43, /* LESS_LESS_MINUS */
614 YYSYMBOL_AND_GREATER
= 44, /* AND_GREATER */
615 YYSYMBOL_AND_GREATER_GREATER
= 45, /* AND_GREATER_GREATER */
616 YYSYMBOL_LESS_GREATER
= 46, /* LESS_GREATER */
617 YYSYMBOL_GREATER_BAR
= 47, /* GREATER_BAR */
618 YYSYMBOL_BAR_AND
= 48, /* BAR_AND */
619 YYSYMBOL_DOLPAREN
= 49, /* DOLPAREN */
620 YYSYMBOL_50_
= 50, /* '&' */
621 YYSYMBOL_51_
= 51, /* ';' */
622 YYSYMBOL_52_n_
= 52, /* '\n' */
623 YYSYMBOL_yacc_EOF
= 53, /* yacc_EOF */
624 YYSYMBOL_54_
= 54, /* '|' */
625 YYSYMBOL_55_
= 55, /* '>' */
626 YYSYMBOL_56_
= 56, /* '<' */
627 YYSYMBOL_57_
= 57, /* '-' */
628 YYSYMBOL_58_
= 58, /* '{' */
629 YYSYMBOL_59_
= 59, /* '}' */
630 YYSYMBOL_60_
= 60, /* '(' */
631 YYSYMBOL_61_
= 61, /* ')' */
632 YYSYMBOL_YYACCEPT
= 62, /* $accept */
633 YYSYMBOL_inputunit
= 63, /* inputunit */
634 YYSYMBOL_word_list
= 64, /* word_list */
635 YYSYMBOL_redirection
= 65, /* redirection */
636 YYSYMBOL_simple_command_element
= 66, /* simple_command_element */
637 YYSYMBOL_redirection_list
= 67, /* redirection_list */
638 YYSYMBOL_simple_command
= 68, /* simple_command */
639 YYSYMBOL_command
= 69, /* command */
640 YYSYMBOL_shell_command
= 70, /* shell_command */
641 YYSYMBOL_for_command
= 71, /* for_command */
642 YYSYMBOL_arith_for_command
= 72, /* arith_for_command */
643 YYSYMBOL_select_command
= 73, /* select_command */
644 YYSYMBOL_case_command
= 74, /* case_command */
645 YYSYMBOL_function_def
= 75, /* function_def */
646 YYSYMBOL_function_body
= 76, /* function_body */
647 YYSYMBOL_subshell
= 77, /* subshell */
648 YYSYMBOL_comsub
= 78, /* comsub */
649 YYSYMBOL_coproc
= 79, /* coproc */
650 YYSYMBOL_if_command
= 80, /* if_command */
651 YYSYMBOL_group_command
= 81, /* group_command */
652 YYSYMBOL_arith_command
= 82, /* arith_command */
653 YYSYMBOL_cond_command
= 83, /* cond_command */
654 YYSYMBOL_elif_clause
= 84, /* elif_clause */
655 YYSYMBOL_case_clause
= 85, /* case_clause */
656 YYSYMBOL_pattern_list
= 86, /* pattern_list */
657 YYSYMBOL_case_clause_sequence
= 87, /* case_clause_sequence */
658 YYSYMBOL_pattern
= 88, /* pattern */
659 YYSYMBOL_compound_list
= 89, /* compound_list */
660 YYSYMBOL_list0
= 90, /* list0 */
661 YYSYMBOL_list1
= 91, /* list1 */
662 YYSYMBOL_simple_list_terminator
= 92, /* simple_list_terminator */
663 YYSYMBOL_list_terminator
= 93, /* list_terminator */
664 YYSYMBOL_newline_list
= 94, /* newline_list */
665 YYSYMBOL_simple_list
= 95, /* simple_list */
666 YYSYMBOL_simple_list1
= 96, /* simple_list1 */
667 YYSYMBOL_pipeline_command
= 97, /* pipeline_command */
668 YYSYMBOL_pipeline
= 98, /* pipeline */
669 YYSYMBOL_timespec
= 99 /* timespec */
671 typedef enum yysymbol_kind_t yysymbol_kind_t
;
680 /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
681 <limits.h> and (if available) <stdint.h> are included
682 so that the code can choose integer types of a good width. */
684 #ifndef __PTRDIFF_MAX__
685 # include <limits.h> /* INFRINGES ON USER NAME SPACE */
686 # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
687 # include <stdint.h> /* INFRINGES ON USER NAME SPACE */
692 /* Narrow types that promote to a signed type and that can represent a
693 signed or unsigned integer of at least N bits. In tables they can
694 save space and decrease cache pressure. Promoting to a signed type
695 helps avoid bugs in integer arithmetic. */
697 #ifdef __INT_LEAST8_MAX__
698 typedef __INT_LEAST8_TYPE__ yytype_int8
;
699 #elif defined YY_STDINT_H
700 typedef int_least8_t yytype_int8
;
702 typedef signed char yytype_int8
;
705 #ifdef __INT_LEAST16_MAX__
706 typedef __INT_LEAST16_TYPE__ yytype_int16
;
707 #elif defined YY_STDINT_H
708 typedef int_least16_t yytype_int16
;
710 typedef short yytype_int16
;
713 /* Work around bug in HP-UX 11.23, which defines these macros
714 incorrectly for preprocessor constants. This workaround can likely
715 be removed in 2023, as HPE has promised support for HP-UX 11.23
716 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
717 <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
719 # undef UINT_LEAST8_MAX
720 # undef UINT_LEAST16_MAX
721 # define UINT_LEAST8_MAX 255
722 # define UINT_LEAST16_MAX 65535
725 #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
726 typedef __UINT_LEAST8_TYPE__ yytype_uint8
;
727 #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
728 && UINT_LEAST8_MAX <= INT_MAX)
729 typedef uint_least8_t yytype_uint8
;
730 #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
731 typedef unsigned char yytype_uint8
;
733 typedef short yytype_uint8
;
736 #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
737 typedef __UINT_LEAST16_TYPE__ yytype_uint16
;
738 #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
739 && UINT_LEAST16_MAX <= INT_MAX)
740 typedef uint_least16_t yytype_uint16
;
741 #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
742 typedef unsigned short yytype_uint16
;
744 typedef int yytype_uint16
;
748 # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
749 # define YYPTRDIFF_T __PTRDIFF_TYPE__
750 # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
751 # elif defined PTRDIFF_MAX
753 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
755 # define YYPTRDIFF_T ptrdiff_t
756 # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
758 # define YYPTRDIFF_T long
759 # define YYPTRDIFF_MAXIMUM LONG_MAX
764 # ifdef __SIZE_TYPE__
765 # define YYSIZE_T __SIZE_TYPE__
766 # elif defined size_t
767 # define YYSIZE_T size_t
768 # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
769 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
770 # define YYSIZE_T size_t
772 # define YYSIZE_T unsigned
776 #define YYSIZE_MAXIMUM \
777 YY_CAST (YYPTRDIFF_T, \
778 (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
779 ? YYPTRDIFF_MAXIMUM \
780 : YY_CAST (YYSIZE_T, -1)))
782 #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
785 /* Stored state numbers (used for stacks). */
786 typedef yytype_int16 yy_state_t
;
788 /* State numbers in computations. */
789 typedef int yy_state_fast_t
;
792 # if defined YYENABLE_NLS && YYENABLE_NLS
794 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
795 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
799 # define YY_(Msgid) Msgid
804 #ifndef YY_ATTRIBUTE_PURE
805 # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
806 # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
808 # define YY_ATTRIBUTE_PURE
812 #ifndef YY_ATTRIBUTE_UNUSED
813 # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
814 # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
816 # define YY_ATTRIBUTE_UNUSED
820 /* Suppress unused-variable warnings by "using" E. */
821 #if ! defined lint || defined __GNUC__
822 # define YY_USE(E) ((void) (E))
824 # define YY_USE(E) /* empty */
827 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
828 #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
829 # if __GNUC__ * 100 + __GNUC_MINOR__ < 407
830 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
831 _Pragma ("GCC diagnostic push") \
832 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
834 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
835 _Pragma ("GCC diagnostic push") \
836 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
837 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
839 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
840 _Pragma ("GCC diagnostic pop")
842 # define YY_INITIAL_VALUE(Value) Value
844 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
845 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
846 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
848 #ifndef YY_INITIAL_VALUE
849 # define YY_INITIAL_VALUE(Value) /* Nothing. */
852 #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
853 # define YY_IGNORE_USELESS_CAST_BEGIN \
854 _Pragma ("GCC diagnostic push") \
855 _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
856 # define YY_IGNORE_USELESS_CAST_END \
857 _Pragma ("GCC diagnostic pop")
859 #ifndef YY_IGNORE_USELESS_CAST_BEGIN
860 # define YY_IGNORE_USELESS_CAST_BEGIN
861 # define YY_IGNORE_USELESS_CAST_END
865 #define YY_ASSERT(E) ((void) (0 && (E)))
867 #if !defined yyoverflow
869 /* The parser invokes alloca or malloc; define the necessary symbols. */
871 # ifdef YYSTACK_USE_ALLOCA
872 # if YYSTACK_USE_ALLOCA
874 # define YYSTACK_ALLOC __builtin_alloca
875 # elif defined __BUILTIN_VA_ARG_INCR
876 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
878 # define YYSTACK_ALLOC __alloca
879 # elif defined _MSC_VER
880 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
881 # define alloca _alloca
883 # define YYSTACK_ALLOC alloca
884 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
885 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
886 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
887 # ifndef EXIT_SUCCESS
888 # define EXIT_SUCCESS 0
895 # ifdef YYSTACK_ALLOC
896 /* Pacify GCC's 'empty if-body' warning. */
897 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
898 # ifndef YYSTACK_ALLOC_MAXIMUM
899 /* The OS might guarantee only one guard page at the bottom of the stack,
900 and a page size can be as small as 4096 bytes. So we cannot safely
901 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
902 to allow for a few compiler-allocated temporary stack slots. */
903 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
906 # define YYSTACK_ALLOC YYMALLOC
907 # define YYSTACK_FREE YYFREE
908 # ifndef YYSTACK_ALLOC_MAXIMUM
909 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
911 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
912 && ! ((defined YYMALLOC || defined malloc) \
913 && (defined YYFREE || defined free)))
914 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
915 # ifndef EXIT_SUCCESS
916 # define EXIT_SUCCESS 0
920 # define YYMALLOC malloc
921 # if ! defined malloc && ! defined EXIT_SUCCESS
922 void *malloc (YYSIZE_T
); /* INFRINGES ON USER NAME SPACE */
927 # if ! defined free && ! defined EXIT_SUCCESS
928 void free (void *); /* INFRINGES ON USER NAME SPACE */
932 #endif /* !defined yyoverflow */
934 #if (! defined yyoverflow \
935 && (! defined __cplusplus \
936 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
938 /* A type that is properly aligned for any stack member. */
941 yy_state_t yyss_alloc
;
945 /* The size of the maximum gap between one aligned stack and the next. */
946 # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
948 /* The size of an array large to enough to hold all stacks, each with
950 # define YYSTACK_BYTES(N) \
951 ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
952 + YYSTACK_GAP_MAXIMUM)
954 # define YYCOPY_NEEDED 1
956 /* Relocate STACK from its old location to the new one. The
957 local variables YYSIZE and YYSTACKSIZE give the old and new number of
958 elements in the stack, and YYPTR gives the new location of the
959 stack. Advance YYPTR to a properly aligned location for the next
961 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
964 YYPTRDIFF_T yynewbytes; \
965 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
966 Stack = &yyptr->Stack_alloc; \
967 yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
968 yyptr += yynewbytes / YYSIZEOF (*yyptr); \
974 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
975 /* Copy COUNT objects from SRC to DST. The source and destination do
978 # if defined __GNUC__ && 1 < __GNUC__
979 # define YYCOPY(Dst, Src, Count) \
980 __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
982 # define YYCOPY(Dst, Src, Count) \
986 for (yyi = 0; yyi < (Count); yyi++) \
987 (Dst)[yyi] = (Src)[yyi]; \
992 #endif /* !YYCOPY_NEEDED */
994 /* YYFINAL -- State number of the termination state. */
996 /* YYLAST -- Last index in YYTABLE. */
999 /* YYNTOKENS -- Number of terminals. */
1000 #define YYNTOKENS 62
1001 /* YYNNTS -- Number of nonterminals. */
1003 /* YYNRULES -- Number of rules. */
1004 #define YYNRULES 175
1005 /* YYNSTATES -- Number of states. */
1006 #define YYNSTATES 350
1008 /* YYMAXUTOK -- Last valid token kind. */
1009 #define YYMAXUTOK 305
1012 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
1013 as returned by yylex, with out-of-bounds checking. */
1014 #define YYTRANSLATE(YYX) \
1015 (0 <= (YYX) && (YYX) <= YYMAXUTOK \
1016 ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
1019 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
1020 as returned by yylex. */
1021 static const yytype_int8 yytranslate
[] =
1023 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1024 52, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1025 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1026 2, 2, 2, 2, 2, 2, 2, 2, 50, 2,
1027 60, 61, 2, 2, 2, 57, 2, 2, 2, 2,
1028 2, 2, 2, 2, 2, 2, 2, 2, 2, 51,
1029 56, 2, 55, 2, 2, 2, 2, 2, 2, 2,
1030 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1031 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1032 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1033 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1034 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1035 2, 2, 2, 58, 54, 59, 2, 2, 2, 2,
1036 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1037 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1038 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1039 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1040 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1041 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1042 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1043 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1044 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1045 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1046 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1047 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1048 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
1049 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1050 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1051 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
1052 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
1053 45, 46, 47, 48, 49, 53
1057 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
1058 static const yytype_int16 yyrline
[] =
1060 0, 395, 395, 406, 414, 423, 438, 455, 470, 480,
1061 482, 486, 492, 498, 504, 510, 516, 522, 528, 534,
1062 540, 546, 552, 558, 564, 570, 576, 583, 590, 597,
1063 604, 611, 618, 624, 630, 636, 642, 648, 654, 660,
1064 666, 672, 678, 684, 690, 696, 702, 708, 714, 720,
1065 726, 732, 738, 744, 750, 758, 760, 762, 766, 770,
1066 781, 783, 787, 789, 791, 807, 809, 813, 815, 817,
1067 819, 821, 823, 825, 827, 829, 831, 833, 837, 842,
1068 847, 852, 857, 862, 867, 872, 879, 885, 891, 897,
1069 905, 910, 915, 920, 925, 930, 935, 940, 947, 952,
1070 957, 964, 966, 968, 970, 974, 976, 1007, 1014, 1018,
1071 1024, 1029, 1046, 1051, 1068, 1075, 1077, 1079, 1084, 1088,
1072 1092, 1096, 1098, 1100, 1104, 1105, 1109, 1111, 1113, 1115,
1073 1119, 1121, 1123, 1125, 1127, 1129, 1133, 1135, 1144, 1150,
1074 1156, 1157, 1164, 1168, 1170, 1172, 1179, 1181, 1188, 1192,
1075 1193, 1196, 1198, 1200, 1204, 1205, 1214, 1229, 1247, 1264,
1076 1266, 1268, 1275, 1278, 1282, 1284, 1290, 1296, 1316, 1339,
1077 1341, 1364, 1368, 1370, 1372, 1374
1081 /** Accessing symbol of state STATE. */
1082 #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
1085 /* The user-facing name of the symbol whose (internal) number is
1086 YYSYMBOL. No bounds checking. */
1087 static const char *yysymbol_name (yysymbol_kind_t yysymbol
) YY_ATTRIBUTE_UNUSED
;
1089 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
1090 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
1091 static const char *const yytname
[] =
1093 "\"end of file\"", "error", "\"invalid token\"", "IF", "THEN", "ELSE",
1094 "ELIF", "FI", "CASE", "ESAC", "FOR", "SELECT", "WHILE", "UNTIL", "DO",
1095 "DONE", "FUNCTION", "COPROC", "COND_START", "COND_END", "COND_ERROR",
1096 "IN", "BANG", "TIME", "TIMEOPT", "TIMEIGN", "WORD", "ASSIGNMENT_WORD",
1097 "REDIR_WORD", "NUMBER", "ARITH_CMD", "ARITH_FOR_EXPRS", "COND_CMD",
1098 "AND_AND", "OR_OR", "GREATER_GREATER", "LESS_LESS", "LESS_AND",
1099 "LESS_LESS_LESS", "GREATER_AND", "SEMI_SEMI", "SEMI_AND",
1100 "SEMI_SEMI_AND", "LESS_LESS_MINUS", "AND_GREATER", "AND_GREATER_GREATER",
1101 "LESS_GREATER", "GREATER_BAR", "BAR_AND", "DOLPAREN", "'&'", "';'",
1102 "'\\n'", "yacc_EOF", "'|'", "'>'", "'<'", "'-'", "'{'", "'}'", "'('",
1103 "')'", "$accept", "inputunit", "word_list", "redirection",
1104 "simple_command_element", "redirection_list", "simple_command",
1105 "command", "shell_command", "for_command", "arith_for_command",
1106 "select_command", "case_command", "function_def", "function_body",
1107 "subshell", "comsub", "coproc", "if_command", "group_command",
1108 "arith_command", "cond_command", "elif_clause", "case_clause",
1109 "pattern_list", "case_clause_sequence", "pattern", "compound_list",
1110 "list0", "list1", "simple_list_terminator", "list_terminator",
1111 "newline_list", "simple_list", "simple_list1", "pipeline_command",
1112 "pipeline", "timespec", YY_NULLPTR
1116 yysymbol_name (yysymbol_kind_t yysymbol
)
1118 return yytname
[yysymbol
];
1122 #define YYPACT_NINF (-125)
1124 #define yypact_value_is_default(Yyn) \
1125 ((Yyn) == YYPACT_NINF)
1127 #define YYTABLE_NINF (-1)
1129 #define yytable_value_is_error(Yyn) \
1132 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
1134 static const yytype_int16 yypact
[] =
1136 329, 27, -125, 8, 81, 10, -125, -125, 16, 38,
1137 0, 434, -5, -16, -125, 670, 684, -125, 33, 43,
1138 62, 63, 71, 69, 94, 105, 108, 116, -125, -125,
1139 -125, 125, 139, -125, -125, 111, -125, -125, 626, -125,
1140 648, -125, -125, -125, -125, -125, -125, -125, -125, -125,
1141 -125, -125, -125, 5, -21, -125, -15, 434, -125, -125,
1142 -125, 196, 485, -125, 157, 2, 180, 207, 222, 227,
1143 638, 626, 648, 224, -125, -125, -125, -125, -125, 219,
1144 -125, 185, 223, 228, 140, 230, 161, 232, 233, 234,
1145 236, 241, 248, 249, 162, 250, 163, 251, 254, 256,
1146 257, 258, -125, -125, -125, -125, -125, -125, -125, -125,
1147 -125, -125, -125, -125, -125, -125, 225, 380, -125, -125,
1148 229, 231, -125, -125, -125, -125, 648, -125, -125, -125,
1149 -125, -125, 536, 536, -125, -125, -125, -125, -125, -125,
1150 -125, 214, -125, -7, -125, 85, -125, -125, -125, -125,
1151 89, -125, -125, -125, 235, 648, -125, 648, 648, -125,
1152 -125, -125, -125, -125, -125, -125, -125, -125, -125, -125,
1153 -125, -125, -125, -125, -125, -125, -125, -125, -125, -125,
1154 -125, -125, -125, -125, -125, -125, -125, -125, -125, -125,
1155 -125, -125, -125, -125, -125, 485, 485, 138, 138, 587,
1156 587, 17, -125, -125, -125, -125, -125, -125, 88, -125,
1157 122, -125, 274, 238, 100, 101, -125, 122, -125, 276,
1158 278, 260, -125, 648, 648, 260, -125, -125, -15, -15,
1159 -125, -125, -125, 287, 485, 485, 485, 485, 485, 290,
1160 164, -125, 26, -125, -125, 285, -125, 131, -125, 242,
1161 -125, -125, -125, -125, -125, -125, 288, 131, -125, 243,
1162 -125, -125, -125, 260, -125, 297, 302, -125, -125, -125,
1163 152, 152, 152, -125, -125, -125, -125, 170, 61, -125,
1164 -125, 281, -36, 293, 252, -125, -125, -125, 102, -125,
1165 298, 255, 300, 262, -125, -125, 103, -125, -125, -125,
1166 -125, -125, -125, -125, -125, -33, 296, -125, -125, -125,
1167 110, -125, -125, -125, -125, -125, -125, 112, -125, -125,
1168 189, -125, -125, -125, 485, -125, -125, 310, 267, -125,
1169 -125, 314, 275, -125, -125, -125, 485, 318, 277, -125,
1170 -125, 320, 279, -125, -125, -125, -125, -125, -125, -125
1173 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
1174 Performed when YYTABLE does not specify something else to do. Zero
1175 means the default is an error. */
1176 static const yytype_uint8 yydefact
[] =
1178 0, 0, 154, 0, 0, 0, 154, 154, 0, 0,
1179 0, 0, 172, 55, 56, 0, 0, 119, 0, 0,
1180 0, 0, 0, 0, 0, 0, 0, 0, 154, 4,
1181 8, 0, 0, 154, 154, 0, 57, 60, 62, 171,
1182 63, 67, 77, 71, 68, 65, 73, 3, 66, 72,
1183 74, 75, 76, 0, 156, 163, 164, 0, 7, 5,
1184 6, 0, 0, 154, 154, 0, 154, 0, 0, 0,
1185 55, 114, 110, 0, 152, 151, 153, 168, 165, 173,
1186 174, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1187 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1188 0, 0, 17, 26, 41, 35, 50, 32, 44, 38,
1189 47, 29, 53, 54, 23, 20, 0, 0, 11, 12,
1190 0, 0, 1, 55, 61, 58, 64, 149, 150, 2,
1191 154, 154, 157, 158, 154, 154, 167, 166, 154, 155,
1192 138, 139, 148, 0, 154, 0, 154, 154, 154, 154,
1193 0, 154, 154, 154, 154, 105, 103, 112, 111, 120,
1194 175, 154, 19, 28, 43, 37, 52, 34, 46, 40,
1195 49, 31, 25, 22, 15, 16, 18, 27, 42, 36,
1196 51, 33, 45, 39, 48, 30, 24, 21, 13, 14,
1197 108, 109, 118, 107, 59, 0, 0, 161, 162, 0,
1198 0, 0, 154, 154, 154, 154, 154, 154, 0, 154,
1199 0, 154, 0, 0, 0, 0, 154, 0, 154, 0,
1200 0, 0, 154, 106, 113, 0, 159, 160, 170, 169,
1201 154, 154, 115, 0, 0, 0, 141, 142, 140, 0,
1202 124, 154, 0, 154, 154, 0, 9, 0, 154, 0,
1203 88, 89, 154, 154, 154, 154, 0, 0, 154, 0,
1204 69, 70, 104, 0, 101, 0, 0, 117, 143, 144,
1205 145, 146, 147, 100, 130, 132, 134, 125, 0, 98,
1206 136, 0, 0, 0, 0, 78, 10, 154, 0, 79,
1207 0, 0, 0, 0, 90, 154, 0, 91, 102, 116,
1208 154, 131, 133, 135, 99, 0, 0, 154, 80, 81,
1209 0, 154, 154, 86, 87, 92, 93, 0, 154, 154,
1210 121, 154, 137, 126, 127, 154, 154, 0, 0, 154,
1211 154, 0, 0, 154, 123, 128, 129, 0, 0, 84,
1212 85, 0, 0, 96, 97, 122, 82, 83, 94, 95
1215 /* YYPGOTO[NTERM-NUM]. */
1216 static const yytype_int16 yypgoto
[] =
1218 -125, -125, 126, -25, -28, -65, 335, -125, -8, -125,
1219 -125, -125, -125, -125, -96, -125, -125, -125, -125, -125,
1220 -125, -125, 28, -125, 109, -125, 68, -2, -125, -11,
1221 -125, -54, -26, -125, -124, 6, 34, -125
1224 /* YYDEFGOTO[NTERM-NUM]. */
1225 static const yytype_int16 yydefgoto
[] =
1227 0, 35, 247, 36, 37, 126, 38, 39, 40, 41,
1228 42, 43, 44, 45, 156, 46, 47, 48, 49, 50,
1229 51, 52, 233, 239, 240, 241, 282, 121, 140, 141,
1230 129, 77, 62, 53, 54, 142, 56, 57
1233 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1234 positive, shift that token. If negative, reduce the rule whose
1235 number is the opposite. If YYTABLE_NINF, syntax error. */
1236 static const yytype_int16 yytable
[] =
1238 61, 72, 117, 136, 67, 68, 55, 158, 197, 198,
1239 124, 148, 130, 131, 207, 125, 146, 78, 306, 79,
1240 80, 306, 230, 231, 232, 307, 116, 58, 321, 132,
1241 133, 120, 73, 134, 63, 279, 66, 143, 145, 135,
1242 150, 2, 69, 124, 81, 139, 3, 125, 4, 5,
1243 6, 7, 280, 74, 75, 76, 10, 127, 128, 102,
1244 147, 155, 157, 137, 70, 14, 15, 16, 17, 103,
1245 304, 226, 227, 18, 19, 20, 21, 22, 139, 59,
1246 60, 23, 24, 25, 26, 27, 281, 280, 104, 107,
1247 223, 105, 224, 31, 32, 111, 33, 108, 34, 209,
1248 109, 194, 243, 216, 195, 196, 210, 64, 199, 200,
1249 217, 122, 65, 139, 252, 254, 311, 318, 208, 106,
1250 112, 281, 214, 215, 325, 262, 329, 221, 110, 264,
1251 125, 113, 125, 194, 114, 225, 201, 139, 55, 55,
1252 139, 139, 115, 211, 212, 213, 244, 218, 246, 219,
1253 220, 118, 139, 139, 139, 139, 248, 286, 253, 255,
1254 312, 319, 139, 258, 139, 119, 164, 298, 326, 165,
1255 330, 130, 131, 74, 75, 76, 234, 235, 236, 237,
1256 238, 242, 74, 75, 76, 202, 203, 168, 178, 182,
1257 169, 179, 183, 287, 333, 231, 263, 166, 194, 194,
1258 138, 55, 55, 295, 274, 275, 276, 245, 144, 249,
1259 301, 302, 303, 155, 256, 278, 259, 155, 170, 180,
1260 184, 151, 288, 268, 269, 270, 271, 272, 265, 266,
1261 2, 149, 296, 228, 229, 3, 152, 4, 5, 6,
1262 7, 283, 284, 159, 160, 10, 161, 202, 203, 162,
1263 290, 291, 292, 293, 163, 155, 167, 17, 171, 172,
1264 173, 310, 174, 2, 204, 205, 206, 175, 3, 317,
1265 4, 5, 6, 7, 176, 177, 181, 185, 10, 153,
1266 186, 324, 187, 188, 189, 33, 190, 154, 192, 250,
1267 17, 260, 193, 261, 267, 336, 222, 251, 320, 273,
1268 285, 289, 297, 294, 299, 323, 300, 280, 308, 327,
1269 328, 309, 139, 313, 314, 315, 331, 332, 33, 335,
1270 34, 316, 322, 337, 338, 339, 340, 341, 342, 343,
1271 1, 345, 2, 346, 344, 348, 347, 3, 349, 4,
1272 5, 6, 7, 257, 71, 8, 9, 10, 334, 305,
1273 277, 11, 12, 0, 0, 13, 14, 15, 16, 17,
1274 0, 0, 0, 0, 18, 19, 20, 21, 22, 0,
1275 0, 0, 23, 24, 25, 26, 27, 0, 28, 0,
1276 0, 29, 30, 2, 31, 32, 0, 33, 3, 34,
1277 4, 5, 6, 7, 0, 0, 8, 9, 10, 0,
1278 0, 0, 11, 12, 0, 0, 13, 14, 15, 16,
1279 17, 0, 0, 0, 0, 18, 19, 20, 21, 22,
1280 0, 0, 0, 23, 24, 25, 26, 27, 0, 0,
1281 0, 0, 139, 0, 0, 31, 32, 2, 33, 0,
1282 34, 191, 3, 0, 4, 5, 6, 7, 0, 0,
1283 8, 9, 10, 0, 0, 0, 11, 12, 0, 0,
1284 13, 14, 15, 16, 17, 0, 0, 0, 0, 18,
1285 19, 20, 21, 22, 0, 0, 0, 23, 24, 25,
1286 26, 27, 0, 0, 0, 74, 75, 76, 2, 31,
1287 32, 0, 33, 3, 34, 4, 5, 6, 7, 0,
1288 0, 8, 9, 10, 0, 0, 0, 11, 12, 0,
1289 0, 13, 14, 15, 16, 17, 0, 0, 0, 0,
1290 18, 19, 20, 21, 22, 0, 0, 0, 23, 24,
1291 25, 26, 27, 0, 0, 0, 0, 139, 0, 2,
1292 31, 32, 0, 33, 3, 34, 4, 5, 6, 7,
1293 0, 0, 8, 9, 10, 0, 0, 0, 11, 12,
1294 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1295 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1296 24, 25, 26, 27, 0, 0, 0, 0, 0, 0,
1297 2, 31, 32, 0, 33, 3, 34, 4, 5, 6,
1298 7, 0, 0, 8, 9, 10, 0, 0, 0, 0,
1299 0, 0, 0, 13, 14, 15, 16, 17, 0, 0,
1300 0, 0, 18, 19, 20, 21, 22, 0, 0, 0,
1301 23, 24, 25, 26, 27, 0, 0, 0, 0, 139,
1302 0, 2, 31, 32, 0, 33, 3, 34, 4, 5,
1303 6, 7, 123, 14, 15, 16, 10, 0, 0, 0,
1304 0, 18, 19, 20, 21, 22, 0, 0, 17, 23,
1305 24, 25, 26, 27, 0, 0, 15, 16, 0, 0,
1306 0, 31, 32, 18, 19, 20, 21, 22, 0, 0,
1307 0, 23, 24, 25, 26, 27, 33, 0, 34, 0,
1308 0, 0, 0, 31, 32, 82, 83, 84, 85, 86,
1309 0, 0, 0, 87, 0, 0, 88, 89, 0, 92,
1310 93, 94, 95, 96, 0, 90, 91, 97, 0, 0,
1311 98, 99, 0, 0, 0, 0, 0, 0, 0, 100,
1315 static const yytype_int16 yycheck
[] =
1317 2, 9, 28, 57, 6, 7, 0, 72, 132, 133,
1318 38, 65, 33, 34, 21, 40, 14, 11, 54, 24,
1319 25, 54, 5, 6, 7, 61, 28, 0, 61, 50,
1320 51, 33, 32, 48, 26, 9, 26, 63, 64, 54,
1321 66, 3, 26, 71, 60, 52, 8, 72, 10, 11,
1322 12, 13, 26, 51, 52, 53, 18, 52, 53, 26,
1323 58, 69, 70, 57, 26, 27, 28, 29, 30, 26,
1324 9, 195, 196, 35, 36, 37, 38, 39, 52, 52,
1325 53, 43, 44, 45, 46, 47, 60, 26, 26, 26,
1326 155, 29, 157, 55, 56, 26, 58, 26, 60, 14,
1327 29, 126, 14, 14, 130, 131, 21, 26, 134, 135,
1328 21, 0, 31, 52, 14, 14, 14, 14, 144, 57,
1329 26, 60, 148, 149, 14, 221, 14, 153, 57, 225,
1330 155, 26, 157, 158, 26, 161, 138, 52, 132, 133,
1331 52, 52, 26, 58, 146, 147, 58, 58, 26, 151,
1332 152, 26, 52, 52, 52, 52, 210, 26, 58, 58,
1333 58, 58, 52, 217, 52, 26, 26, 263, 58, 29,
1334 58, 33, 34, 51, 52, 53, 202, 203, 204, 205,
1335 206, 207, 51, 52, 53, 33, 34, 26, 26, 26,
1336 29, 29, 29, 247, 5, 6, 222, 57, 223, 224,
1337 4, 195, 196, 257, 40, 41, 42, 209, 51, 211,
1338 40, 41, 42, 221, 216, 241, 218, 225, 57, 57,
1339 57, 14, 248, 234, 235, 236, 237, 238, 230, 231,
1340 3, 51, 258, 199, 200, 8, 14, 10, 11, 12,
1341 13, 243, 244, 19, 25, 18, 61, 33, 34, 26,
1342 252, 253, 254, 255, 26, 263, 26, 30, 26, 26,
1343 26, 287, 26, 3, 50, 51, 52, 26, 8, 295,
1344 10, 11, 12, 13, 26, 26, 26, 26, 18, 52,
1345 26, 307, 26, 26, 26, 58, 61, 60, 59, 15,
1346 30, 15, 61, 15, 7, 321, 61, 59, 300, 9,
1347 15, 59, 59, 15, 7, 307, 4, 26, 15, 311,
1348 312, 59, 52, 15, 59, 15, 318, 319, 58, 321,
1349 60, 59, 26, 325, 326, 15, 59, 329, 330, 15,
1350 1, 333, 3, 15, 59, 15, 59, 8, 59, 10,
1351 11, 12, 13, 217, 9, 16, 17, 18, 320, 281,
1352 241, 22, 23, -1, -1, 26, 27, 28, 29, 30,
1353 -1, -1, -1, -1, 35, 36, 37, 38, 39, -1,
1354 -1, -1, 43, 44, 45, 46, 47, -1, 49, -1,
1355 -1, 52, 53, 3, 55, 56, -1, 58, 8, 60,
1356 10, 11, 12, 13, -1, -1, 16, 17, 18, -1,
1357 -1, -1, 22, 23, -1, -1, 26, 27, 28, 29,
1358 30, -1, -1, -1, -1, 35, 36, 37, 38, 39,
1359 -1, -1, -1, 43, 44, 45, 46, 47, -1, -1,
1360 -1, -1, 52, -1, -1, 55, 56, 3, 58, -1,
1361 60, 61, 8, -1, 10, 11, 12, 13, -1, -1,
1362 16, 17, 18, -1, -1, -1, 22, 23, -1, -1,
1363 26, 27, 28, 29, 30, -1, -1, -1, -1, 35,
1364 36, 37, 38, 39, -1, -1, -1, 43, 44, 45,
1365 46, 47, -1, -1, -1, 51, 52, 53, 3, 55,
1366 56, -1, 58, 8, 60, 10, 11, 12, 13, -1,
1367 -1, 16, 17, 18, -1, -1, -1, 22, 23, -1,
1368 -1, 26, 27, 28, 29, 30, -1, -1, -1, -1,
1369 35, 36, 37, 38, 39, -1, -1, -1, 43, 44,
1370 45, 46, 47, -1, -1, -1, -1, 52, -1, 3,
1371 55, 56, -1, 58, 8, 60, 10, 11, 12, 13,
1372 -1, -1, 16, 17, 18, -1, -1, -1, 22, 23,
1373 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1374 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1375 44, 45, 46, 47, -1, -1, -1, -1, -1, -1,
1376 3, 55, 56, -1, 58, 8, 60, 10, 11, 12,
1377 13, -1, -1, 16, 17, 18, -1, -1, -1, -1,
1378 -1, -1, -1, 26, 27, 28, 29, 30, -1, -1,
1379 -1, -1, 35, 36, 37, 38, 39, -1, -1, -1,
1380 43, 44, 45, 46, 47, -1, -1, -1, -1, 52,
1381 -1, 3, 55, 56, -1, 58, 8, 60, 10, 11,
1382 12, 13, 26, 27, 28, 29, 18, -1, -1, -1,
1383 -1, 35, 36, 37, 38, 39, -1, -1, 30, 43,
1384 44, 45, 46, 47, -1, -1, 28, 29, -1, -1,
1385 -1, 55, 56, 35, 36, 37, 38, 39, -1, -1,
1386 -1, 43, 44, 45, 46, 47, 58, -1, 60, -1,
1387 -1, -1, -1, 55, 56, 35, 36, 37, 38, 39,
1388 -1, -1, -1, 43, -1, -1, 46, 47, -1, 35,
1389 36, 37, 38, 39, -1, 55, 56, 43, -1, -1,
1390 46, 47, -1, -1, -1, -1, -1, -1, -1, 55,
1394 /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
1396 static const yytype_int8 yystos
[] =
1398 0, 1, 3, 8, 10, 11, 12, 13, 16, 17,
1399 18, 22, 23, 26, 27, 28, 29, 30, 35, 36,
1400 37, 38, 39, 43, 44, 45, 46, 47, 49, 52,
1401 53, 55, 56, 58, 60, 63, 65, 66, 68, 69,
1402 70, 71, 72, 73, 74, 75, 77, 78, 79, 80,
1403 81, 82, 83, 95, 96, 97, 98, 99, 0, 52,
1404 53, 89, 94, 26, 26, 31, 26, 89, 89, 26,
1405 26, 68, 70, 32, 51, 52, 53, 93, 97, 24,
1406 25, 60, 35, 36, 37, 38, 39, 43, 46, 47,
1407 55, 56, 35, 36, 37, 38, 39, 43, 46, 47,
1408 55, 56, 26, 26, 26, 29, 57, 26, 26, 29,
1409 57, 26, 26, 26, 26, 26, 89, 94, 26, 26,
1410 89, 89, 0, 26, 66, 65, 67, 52, 53, 92,
1411 33, 34, 50, 51, 48, 54, 93, 97, 4, 52,
1412 90, 91, 97, 94, 51, 94, 14, 58, 93, 51,
1413 94, 14, 14, 52, 60, 70, 76, 70, 67, 19,
1414 25, 61, 26, 26, 26, 29, 57, 26, 26, 29,
1415 57, 26, 26, 26, 26, 26, 26, 26, 26, 29,
1416 57, 26, 26, 29, 57, 26, 26, 26, 26, 26,
1417 61, 61, 59, 61, 65, 94, 94, 96, 96, 94,
1418 94, 89, 33, 34, 50, 51, 52, 21, 94, 14,
1419 21, 58, 89, 89, 94, 94, 14, 21, 58, 89,
1420 89, 94, 61, 67, 67, 94, 96, 96, 98, 98,
1421 5, 6, 7, 84, 94, 94, 94, 94, 94, 85,
1422 86, 87, 94, 14, 58, 89, 26, 64, 93, 89,
1423 15, 59, 14, 58, 14, 58, 89, 64, 93, 89,
1424 15, 15, 76, 94, 76, 89, 89, 7, 91, 91,
1425 91, 91, 91, 9, 40, 41, 42, 86, 94, 9,
1426 26, 60, 88, 89, 89, 15, 26, 93, 94, 59,
1427 89, 89, 89, 89, 15, 93, 94, 59, 76, 7,
1428 4, 40, 41, 42, 9, 88, 54, 61, 15, 59,
1429 94, 14, 58, 15, 59, 15, 59, 94, 14, 58,
1430 89, 61, 26, 89, 94, 14, 58, 89, 89, 14,
1431 58, 89, 89, 5, 84, 89, 94, 89, 89, 15,
1432 59, 89, 89, 15, 59, 89, 15, 59, 15, 59
1435 /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
1436 static const yytype_int8 yyr1
[] =
1438 0, 62, 63, 63, 63, 63, 63, 63, 63, 64,
1439 64, 65, 65, 65, 65, 65, 65, 65, 65, 65,
1440 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
1441 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
1442 65, 65, 65, 65, 65, 65, 65, 65, 65, 65,
1443 65, 65, 65, 65, 65, 66, 66, 66, 67, 67,
1444 68, 68, 69, 69, 69, 69, 69, 70, 70, 70,
1445 70, 70, 70, 70, 70, 70, 70, 70, 71, 71,
1446 71, 71, 71, 71, 71, 71, 72, 72, 72, 72,
1447 73, 73, 73, 73, 73, 73, 73, 73, 74, 74,
1448 74, 75, 75, 75, 75, 76, 76, 77, 78, 78,
1449 79, 79, 79, 79, 79, 80, 80, 80, 81, 82,
1450 83, 84, 84, 84, 85, 85, 86, 86, 86, 86,
1451 87, 87, 87, 87, 87, 87, 88, 88, 89, 89,
1452 90, 90, 90, 91, 91, 91, 91, 91, 91, 92,
1453 92, 93, 93, 93, 94, 94, 95, 95, 95, 96,
1454 96, 96, 96, 96, 97, 97, 97, 97, 97, 98,
1455 98, 98, 99, 99, 99, 99
1458 /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
1459 static const yytype_int8 yyr2
[] =
1461 0, 2, 2, 1, 1, 2, 2, 2, 1, 1,
1462 2, 2, 2, 3, 3, 3, 3, 2, 3, 3,
1463 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
1464 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
1465 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
1466 2, 3, 3, 2, 2, 1, 1, 1, 1, 2,
1467 1, 2, 1, 1, 2, 1, 1, 1, 1, 5,
1468 5, 1, 1, 1, 1, 1, 1, 1, 6, 6,
1469 7, 7, 10, 10, 9, 9, 7, 7, 5, 5,
1470 6, 6, 7, 7, 10, 10, 9, 9, 6, 7,
1471 6, 5, 6, 3, 5, 1, 2, 3, 3, 3,
1472 2, 3, 3, 4, 2, 5, 7, 6, 3, 1,
1473 3, 4, 6, 5, 1, 2, 4, 4, 5, 5,
1474 2, 3, 2, 3, 2, 3, 1, 3, 2, 2,
1475 3, 3, 3, 4, 4, 4, 4, 4, 1, 1,
1476 1, 1, 1, 1, 0, 2, 1, 2, 2, 4,
1477 4, 3, 3, 1, 1, 2, 2, 2, 2, 4,
1482 enum { YYENOMEM
= -2 };
1484 #define yyerrok (yyerrstatus = 0)
1485 #define yyclearin (yychar = YYEMPTY)
1487 #define YYACCEPT goto yyacceptlab
1488 #define YYABORT goto yyabortlab
1489 #define YYERROR goto yyerrorlab
1490 #define YYNOMEM goto yyexhaustedlab
1493 #define YYRECOVERING() (!!yyerrstatus)
1495 #define YYBACKUP(Token, Value) \
1497 if (yychar == YYEMPTY) \
1501 YYPOPSTACK (yylen); \
1507 yyerror (YY_("syntax error: cannot back up")); \
1512 /* Backward compatibility with an undocumented macro.
1513 Use YYerror or YYUNDEF. */
1514 #define YYERRCODE YYUNDEF
1517 /* Enable debugging if requested. */
1521 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1522 # define YYFPRINTF fprintf
1525 # define YYDPRINTF(Args) \
1534 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
1538 YYFPRINTF (stderr, "%s ", Title); \
1539 yy_symbol_print (stderr, \
1541 YYFPRINTF (stderr, "\n"); \
1546 /*-----------------------------------.
1547 | Print this symbol's value on YYO. |
1548 `-----------------------------------*/
1551 yy_symbol_value_print (FILE *yyo
,
1552 yysymbol_kind_t yykind
, YYSTYPE
const * const yyvaluep
)
1554 FILE *yyoutput
= yyo
;
1558 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1560 YY_IGNORE_MAYBE_UNINITIALIZED_END
1564 /*---------------------------.
1565 | Print this symbol on YYO. |
1566 `---------------------------*/
1569 yy_symbol_print (FILE *yyo
,
1570 yysymbol_kind_t yykind
, YYSTYPE
const * const yyvaluep
)
1572 YYFPRINTF (yyo
, "%s %s (",
1573 yykind
< YYNTOKENS
? "token" : "nterm", yysymbol_name (yykind
));
1575 yy_symbol_value_print (yyo
, yykind
, yyvaluep
);
1576 YYFPRINTF (yyo
, ")");
1579 /*------------------------------------------------------------------.
1580 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1582 `------------------------------------------------------------------*/
1585 yy_stack_print (yy_state_t
*yybottom
, yy_state_t
*yytop
)
1587 YYFPRINTF (stderr
, "Stack now");
1588 for (; yybottom
<= yytop
; yybottom
++)
1590 int yybot
= *yybottom
;
1591 YYFPRINTF (stderr
, " %d", yybot
);
1593 YYFPRINTF (stderr
, "\n");
1596 # define YY_STACK_PRINT(Bottom, Top) \
1599 yy_stack_print ((Bottom), (Top)); \
1603 /*------------------------------------------------.
1604 | Report that the YYRULE is going to be reduced. |
1605 `------------------------------------------------*/
1608 yy_reduce_print (yy_state_t
*yyssp
, YYSTYPE
*yyvsp
,
1611 int yylno
= yyrline
[yyrule
];
1612 int yynrhs
= yyr2
[yyrule
];
1614 YYFPRINTF (stderr
, "Reducing stack by rule %d (line %d):\n",
1616 /* The symbols being reduced. */
1617 for (yyi
= 0; yyi
< yynrhs
; yyi
++)
1619 YYFPRINTF (stderr
, " $%d = ", yyi
+ 1);
1620 yy_symbol_print (stderr
,
1621 YY_ACCESSING_SYMBOL (+yyssp
[yyi
+ 1 - yynrhs
]),
1622 &yyvsp
[(yyi
+ 1) - (yynrhs
)]);
1623 YYFPRINTF (stderr
, "\n");
1627 # define YY_REDUCE_PRINT(Rule) \
1630 yy_reduce_print (yyssp, yyvsp, Rule); \
1633 /* Nonzero means print parse trace. It is left uninitialized so that
1634 multiple parsers can coexist. */
1636 #else /* !YYDEBUG */
1637 # define YYDPRINTF(Args) ((void) 0)
1638 # define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
1639 # define YY_STACK_PRINT(Bottom, Top)
1640 # define YY_REDUCE_PRINT(Rule)
1641 #endif /* !YYDEBUG */
1644 /* YYINITDEPTH -- initial size of the parser's stacks. */
1646 # define YYINITDEPTH 200
1649 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1650 if the built-in stack extension method is used).
1652 Do not make this value too large; the results are undefined if
1653 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1654 evaluated with infinite-precision integer arithmetic. */
1657 # define YYMAXDEPTH 10000
1665 /*-----------------------------------------------.
1666 | Release the memory associated to this symbol. |
1667 `-----------------------------------------------*/
1670 yydestruct (const char *yymsg
,
1671 yysymbol_kind_t yykind
, YYSTYPE
*yyvaluep
)
1676 YY_SYMBOL_PRINT (yymsg
, yykind
, yyvaluep
, yylocationp
);
1678 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1680 YY_IGNORE_MAYBE_UNINITIALIZED_END
1684 /* Lookahead token kind. */
1687 /* The semantic value of the lookahead symbol. */
1689 /* Number of syntax errors so far. */
1702 yy_state_fast_t yystate
= 0;
1703 /* Number of tokens to shift before error messages enabled. */
1704 int yyerrstatus
= 0;
1706 /* Refer to the stacks through separate pointers, to allow yyoverflow
1707 to reallocate them elsewhere. */
1710 YYPTRDIFF_T yystacksize
= YYINITDEPTH
;
1712 /* The state stack: array, bottom, top. */
1713 yy_state_t yyssa
[YYINITDEPTH
];
1714 yy_state_t
*yyss
= yyssa
;
1715 yy_state_t
*yyssp
= yyss
;
1717 /* The semantic value stack: array, bottom, top. */
1718 YYSTYPE yyvsa
[YYINITDEPTH
];
1719 YYSTYPE
*yyvs
= yyvsa
;
1720 YYSTYPE
*yyvsp
= yyvs
;
1723 /* The return value of yyparse. */
1725 /* Lookahead symbol kind. */
1726 yysymbol_kind_t yytoken
= YYSYMBOL_YYEMPTY
;
1727 /* The variables used to return semantic value and location from the
1733 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1735 /* The number of symbols on the RHS of the reduced rule.
1736 Keep to zero when no symbol should be popped. */
1739 YYDPRINTF ((stderr
, "Starting parse\n"));
1741 yychar
= YYEMPTY
; /* Cause a token to be read. */
1746 /*------------------------------------------------------------.
1747 | yynewstate -- push a new state, which is found in yystate. |
1748 `------------------------------------------------------------*/
1750 /* In all cases, when you get here, the value and location stacks
1751 have just been pushed. So pushing a state here evens the stacks. */
1755 /*--------------------------------------------------------------------.
1756 | yysetstate -- set current state (the top of the stack) to yystate. |
1757 `--------------------------------------------------------------------*/
1759 YYDPRINTF ((stderr
, "Entering state %d\n", yystate
));
1760 YY_ASSERT (0 <= yystate
&& yystate
< YYNSTATES
);
1761 YY_IGNORE_USELESS_CAST_BEGIN
1762 *yyssp
= YY_CAST (yy_state_t
, yystate
);
1763 YY_IGNORE_USELESS_CAST_END
1764 YY_STACK_PRINT (yyss
, yyssp
);
1766 if (yyss
+ yystacksize
- 1 <= yyssp
)
1767 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1771 /* Get the current used size of the three stacks, in elements. */
1772 YYPTRDIFF_T yysize
= yyssp
- yyss
+ 1;
1774 # if defined yyoverflow
1776 /* Give user a chance to reallocate the stack. Use copies of
1777 these so that the &'s don't force the real ones into
1779 yy_state_t
*yyss1
= yyss
;
1780 YYSTYPE
*yyvs1
= yyvs
;
1782 /* Each stack pointer address is followed by the size of the
1783 data in use in that stack, in bytes. This used to be a
1784 conditional around just the two extra args, but that might
1785 be undefined if yyoverflow is a macro. */
1786 yyoverflow (YY_("memory exhausted"),
1787 &yyss1
, yysize
* YYSIZEOF (*yyssp
),
1788 &yyvs1
, yysize
* YYSIZEOF (*yyvsp
),
1793 # else /* defined YYSTACK_RELOCATE */
1794 /* Extend the stack our own way. */
1795 if (YYMAXDEPTH
<= yystacksize
)
1798 if (YYMAXDEPTH
< yystacksize
)
1799 yystacksize
= YYMAXDEPTH
;
1802 yy_state_t
*yyss1
= yyss
;
1803 union yyalloc
*yyptr
=
1804 YY_CAST (union yyalloc
*,
1805 YYSTACK_ALLOC (YY_CAST (YYSIZE_T
, YYSTACK_BYTES (yystacksize
))));
1808 YYSTACK_RELOCATE (yyss_alloc
, yyss
);
1809 YYSTACK_RELOCATE (yyvs_alloc
, yyvs
);
1810 # undef YYSTACK_RELOCATE
1812 YYSTACK_FREE (yyss1
);
1816 yyssp
= yyss
+ yysize
- 1;
1817 yyvsp
= yyvs
+ yysize
- 1;
1819 YY_IGNORE_USELESS_CAST_BEGIN
1820 YYDPRINTF ((stderr
, "Stack size increased to %ld\n",
1821 YY_CAST (long, yystacksize
)));
1822 YY_IGNORE_USELESS_CAST_END
1824 if (yyss
+ yystacksize
- 1 <= yyssp
)
1827 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1830 if (yystate
== YYFINAL
)
1840 /* Do appropriate processing given the current state. Read a
1841 lookahead token if we need one and don't already have one. */
1843 /* First try to decide what to do without reference to lookahead token. */
1844 yyn
= yypact
[yystate
];
1845 if (yypact_value_is_default (yyn
))
1848 /* Not known => get a lookahead token if don't already have one. */
1850 /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
1851 if (yychar
== YYEMPTY
)
1853 YYDPRINTF ((stderr
, "Reading a token\n"));
1857 if (yychar
<= YYEOF
)
1860 yytoken
= YYSYMBOL_YYEOF
;
1861 YYDPRINTF ((stderr
, "Now at end of input.\n"));
1863 else if (yychar
== YYerror
)
1865 /* The scanner already issued an error message, process directly
1866 to error recovery. But do not keep the error token as
1867 lookahead, it is too special and may lead us to an endless
1868 loop in error recovery. */
1870 yytoken
= YYSYMBOL_YYerror
;
1875 yytoken
= YYTRANSLATE (yychar
);
1876 YY_SYMBOL_PRINT ("Next token is", yytoken
, &yylval
, &yylloc
);
1879 /* If the proper action on seeing token YYTOKEN is to reduce or to
1880 detect an error, take that action. */
1882 if (yyn
< 0 || YYLAST
< yyn
|| yycheck
[yyn
] != yytoken
)
1887 if (yytable_value_is_error (yyn
))
1893 /* Count tokens shifted since error; after three, turn off error
1898 /* Shift the lookahead token. */
1899 YY_SYMBOL_PRINT ("Shifting", yytoken
, &yylval
, &yylloc
);
1901 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1903 YY_IGNORE_MAYBE_UNINITIALIZED_END
1905 /* Discard the shifted token. */
1910 /*-----------------------------------------------------------.
1911 | yydefault -- do the default action for the current state. |
1912 `-----------------------------------------------------------*/
1914 yyn
= yydefact
[yystate
];
1920 /*-----------------------------.
1921 | yyreduce -- do a reduction. |
1922 `-----------------------------*/
1924 /* yyn is the number of a rule to reduce with. */
1927 /* If YYLEN is nonzero, implement the default value of the action:
1930 Otherwise, the following line sets YYVAL to garbage.
1931 This behavior is undocumented and Bison
1932 users should not rely upon it. Assigning to YYVAL
1933 unconditionally makes the parser a bit smaller, and it avoids a
1934 GCC warning that YYVAL may be used uninitialized. */
1935 yyval
= yyvsp
[1-yylen
];
1938 YY_REDUCE_PRINT (yyn
);
1941 case 2: /* inputunit: simple_list simple_list_terminator */
1942 #line 396 "/usr/local/src/chet/src/bash/src/parse.y"
1944 /* Case of regular command. Discard the error
1945 safety net,and return the command just parsed. */
1946 global_command
= (yyvsp
[-1].command
);
1947 eof_encountered
= 0;
1948 /* discard_parser_constructs (0); */
1949 if (parser_state
& PST_CMDSUBST
)
1950 parser_state
|= PST_EOFTOKEN
;
1953 #line 1954 "y.tab.c"
1956 case 3: /* inputunit: comsub */
1957 #line 407 "/usr/local/src/chet/src/bash/src/parse.y"
1959 /* This is special; look at the production and how
1960 parse_comsub sets token_to_read */
1961 global_command
= (yyvsp
[0].command
);
1962 eof_encountered
= 0;
1965 #line 1966 "y.tab.c"
1968 case 4: /* inputunit: '\n' */
1969 #line 415 "/usr/local/src/chet/src/bash/src/parse.y"
1971 /* Case of regular command, but not a very
1972 interesting one. Return a NULL command. */
1973 global_command
= (COMMAND
*)NULL
;
1974 if (parser_state
& PST_CMDSUBST
)
1975 parser_state
|= PST_EOFTOKEN
;
1978 #line 1979 "y.tab.c"
1981 case 5: /* inputunit: error '\n' */
1982 #line 424 "/usr/local/src/chet/src/bash/src/parse.y"
1984 /* Error during parsing. Return NULL command. */
1985 global_command
= (COMMAND
*)NULL
;
1986 eof_encountered
= 0;
1987 /* discard_parser_constructs (1); */
1988 if (interactive
&& parse_and_execute_level
== 0)
1997 #line 1998 "y.tab.c"
2000 case 6: /* inputunit: error yacc_EOF */
2001 #line 439 "/usr/local/src/chet/src/bash/src/parse.y"
2003 /* EOF after an error. Do ignoreeof or not. Really
2004 only interesting in non-interactive shells */
2005 global_command
= (COMMAND
*)NULL
;
2006 if (last_command_exit_value
== 0)
2007 last_command_exit_value
= EX_BADUSAGE
; /* force error return */
2008 if (interactive
&& parse_and_execute_level
== 0)
2010 handle_eof_input_unit ();
2018 #line 2019 "y.tab.c"
2021 case 7: /* inputunit: error $end */
2022 #line 456 "/usr/local/src/chet/src/bash/src/parse.y"
2024 global_command
= (COMMAND
*)NULL
;
2025 if (last_command_exit_value
== 0)
2026 last_command_exit_value
= EX_BADUSAGE
; /* force error return */
2027 if (interactive
&& parse_and_execute_level
== 0)
2029 handle_eof_input_unit ();
2037 #line 2038 "y.tab.c"
2040 case 8: /* inputunit: yacc_EOF */
2041 #line 471 "/usr/local/src/chet/src/bash/src/parse.y"
2043 /* Case of EOF seen by itself. Do ignoreeof or
2045 global_command
= (COMMAND
*)NULL
;
2046 handle_eof_input_unit ();
2049 #line 2050 "y.tab.c"
2052 case 9: /* word_list: WORD */
2053 #line 481 "/usr/local/src/chet/src/bash/src/parse.y"
2054 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
2055 #line 2056 "y.tab.c"
2058 case 10: /* word_list: word_list WORD */
2059 #line 483 "/usr/local/src/chet/src/bash/src/parse.y"
2060 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-1].word_list
)); }
2061 #line 2062 "y.tab.c"
2064 case 11: /* redirection: '>' WORD */
2065 #line 487 "/usr/local/src/chet/src/bash/src/parse.y"
2068 redir
.filename
= (yyvsp
[0].word
);
2069 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2071 #line 2072 "y.tab.c"
2074 case 12: /* redirection: '<' WORD */
2075 #line 493 "/usr/local/src/chet/src/bash/src/parse.y"
2078 redir
.filename
= (yyvsp
[0].word
);
2079 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2081 #line 2082 "y.tab.c"
2084 case 13: /* redirection: NUMBER '>' WORD */
2085 #line 499 "/usr/local/src/chet/src/bash/src/parse.y"
2087 source
.dest
= (yyvsp
[-2].number
);
2088 redir
.filename
= (yyvsp
[0].word
);
2089 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2091 #line 2092 "y.tab.c"
2094 case 14: /* redirection: NUMBER '<' WORD */
2095 #line 505 "/usr/local/src/chet/src/bash/src/parse.y"
2097 source
.dest
= (yyvsp
[-2].number
);
2098 redir
.filename
= (yyvsp
[0].word
);
2099 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2101 #line 2102 "y.tab.c"
2104 case 15: /* redirection: REDIR_WORD '>' WORD */
2105 #line 511 "/usr/local/src/chet/src/bash/src/parse.y"
2107 source
.filename
= (yyvsp
[-2].word
);
2108 redir
.filename
= (yyvsp
[0].word
);
2109 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, REDIR_VARASSIGN
);
2111 #line 2112 "y.tab.c"
2114 case 16: /* redirection: REDIR_WORD '<' WORD */
2115 #line 517 "/usr/local/src/chet/src/bash/src/parse.y"
2117 source
.filename
= (yyvsp
[-2].word
);
2118 redir
.filename
= (yyvsp
[0].word
);
2119 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, REDIR_VARASSIGN
);
2121 #line 2122 "y.tab.c"
2124 case 17: /* redirection: GREATER_GREATER WORD */
2125 #line 523 "/usr/local/src/chet/src/bash/src/parse.y"
2128 redir
.filename
= (yyvsp
[0].word
);
2129 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2131 #line 2132 "y.tab.c"
2134 case 18: /* redirection: NUMBER GREATER_GREATER WORD */
2135 #line 529 "/usr/local/src/chet/src/bash/src/parse.y"
2137 source
.dest
= (yyvsp
[-2].number
);
2138 redir
.filename
= (yyvsp
[0].word
);
2139 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2141 #line 2142 "y.tab.c"
2144 case 19: /* redirection: REDIR_WORD GREATER_GREATER WORD */
2145 #line 535 "/usr/local/src/chet/src/bash/src/parse.y"
2147 source
.filename
= (yyvsp
[-2].word
);
2148 redir
.filename
= (yyvsp
[0].word
);
2149 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, REDIR_VARASSIGN
);
2151 #line 2152 "y.tab.c"
2154 case 20: /* redirection: GREATER_BAR WORD */
2155 #line 541 "/usr/local/src/chet/src/bash/src/parse.y"
2158 redir
.filename
= (yyvsp
[0].word
);
2159 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2161 #line 2162 "y.tab.c"
2164 case 21: /* redirection: NUMBER GREATER_BAR WORD */
2165 #line 547 "/usr/local/src/chet/src/bash/src/parse.y"
2167 source
.dest
= (yyvsp
[-2].number
);
2168 redir
.filename
= (yyvsp
[0].word
);
2169 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2171 #line 2172 "y.tab.c"
2174 case 22: /* redirection: REDIR_WORD GREATER_BAR WORD */
2175 #line 553 "/usr/local/src/chet/src/bash/src/parse.y"
2177 source
.filename
= (yyvsp
[-2].word
);
2178 redir
.filename
= (yyvsp
[0].word
);
2179 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, REDIR_VARASSIGN
);
2181 #line 2182 "y.tab.c"
2184 case 23: /* redirection: LESS_GREATER WORD */
2185 #line 559 "/usr/local/src/chet/src/bash/src/parse.y"
2188 redir
.filename
= (yyvsp
[0].word
);
2189 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2191 #line 2192 "y.tab.c"
2194 case 24: /* redirection: NUMBER LESS_GREATER WORD */
2195 #line 565 "/usr/local/src/chet/src/bash/src/parse.y"
2197 source
.dest
= (yyvsp
[-2].number
);
2198 redir
.filename
= (yyvsp
[0].word
);
2199 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2201 #line 2202 "y.tab.c"
2204 case 25: /* redirection: REDIR_WORD LESS_GREATER WORD */
2205 #line 571 "/usr/local/src/chet/src/bash/src/parse.y"
2207 source
.filename
= (yyvsp
[-2].word
);
2208 redir
.filename
= (yyvsp
[0].word
);
2209 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, REDIR_VARASSIGN
);
2211 #line 2212 "y.tab.c"
2214 case 26: /* redirection: LESS_LESS WORD */
2215 #line 577 "/usr/local/src/chet/src/bash/src/parse.y"
2218 redir
.filename
= (yyvsp
[0].word
);
2219 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2220 push_heredoc ((yyval
.redirect
));
2222 #line 2223 "y.tab.c"
2225 case 27: /* redirection: NUMBER LESS_LESS WORD */
2226 #line 584 "/usr/local/src/chet/src/bash/src/parse.y"
2228 source
.dest
= (yyvsp
[-2].number
);
2229 redir
.filename
= (yyvsp
[0].word
);
2230 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2231 push_heredoc ((yyval
.redirect
));
2233 #line 2234 "y.tab.c"
2236 case 28: /* redirection: REDIR_WORD LESS_LESS WORD */
2237 #line 591 "/usr/local/src/chet/src/bash/src/parse.y"
2239 source
.filename
= (yyvsp
[-2].word
);
2240 redir
.filename
= (yyvsp
[0].word
);
2241 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, REDIR_VARASSIGN
);
2242 push_heredoc ((yyval
.redirect
));
2244 #line 2245 "y.tab.c"
2247 case 29: /* redirection: LESS_LESS_MINUS WORD */
2248 #line 598 "/usr/local/src/chet/src/bash/src/parse.y"
2251 redir
.filename
= (yyvsp
[0].word
);
2252 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2253 push_heredoc ((yyval
.redirect
));
2255 #line 2256 "y.tab.c"
2258 case 30: /* redirection: NUMBER LESS_LESS_MINUS WORD */
2259 #line 605 "/usr/local/src/chet/src/bash/src/parse.y"
2261 source
.dest
= (yyvsp
[-2].number
);
2262 redir
.filename
= (yyvsp
[0].word
);
2263 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2264 push_heredoc ((yyval
.redirect
));
2266 #line 2267 "y.tab.c"
2269 case 31: /* redirection: REDIR_WORD LESS_LESS_MINUS WORD */
2270 #line 612 "/usr/local/src/chet/src/bash/src/parse.y"
2272 source
.filename
= (yyvsp
[-2].word
);
2273 redir
.filename
= (yyvsp
[0].word
);
2274 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, REDIR_VARASSIGN
);
2275 push_heredoc ((yyval
.redirect
));
2277 #line 2278 "y.tab.c"
2280 case 32: /* redirection: LESS_LESS_LESS WORD */
2281 #line 619 "/usr/local/src/chet/src/bash/src/parse.y"
2284 redir
.filename
= (yyvsp
[0].word
);
2285 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2287 #line 2288 "y.tab.c"
2290 case 33: /* redirection: NUMBER LESS_LESS_LESS WORD */
2291 #line 625 "/usr/local/src/chet/src/bash/src/parse.y"
2293 source
.dest
= (yyvsp
[-2].number
);
2294 redir
.filename
= (yyvsp
[0].word
);
2295 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2297 #line 2298 "y.tab.c"
2300 case 34: /* redirection: REDIR_WORD LESS_LESS_LESS WORD */
2301 #line 631 "/usr/local/src/chet/src/bash/src/parse.y"
2303 source
.filename
= (yyvsp
[-2].word
);
2304 redir
.filename
= (yyvsp
[0].word
);
2305 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, REDIR_VARASSIGN
);
2307 #line 2308 "y.tab.c"
2310 case 35: /* redirection: LESS_AND NUMBER */
2311 #line 637 "/usr/local/src/chet/src/bash/src/parse.y"
2314 redir
.dest
= (yyvsp
[0].number
);
2315 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2317 #line 2318 "y.tab.c"
2320 case 36: /* redirection: NUMBER LESS_AND NUMBER */
2321 #line 643 "/usr/local/src/chet/src/bash/src/parse.y"
2323 source
.dest
= (yyvsp
[-2].number
);
2324 redir
.dest
= (yyvsp
[0].number
);
2325 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2327 #line 2328 "y.tab.c"
2330 case 37: /* redirection: REDIR_WORD LESS_AND NUMBER */
2331 #line 649 "/usr/local/src/chet/src/bash/src/parse.y"
2333 source
.filename
= (yyvsp
[-2].word
);
2334 redir
.dest
= (yyvsp
[0].number
);
2335 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, REDIR_VARASSIGN
);
2337 #line 2338 "y.tab.c"
2340 case 38: /* redirection: GREATER_AND NUMBER */
2341 #line 655 "/usr/local/src/chet/src/bash/src/parse.y"
2344 redir
.dest
= (yyvsp
[0].number
);
2345 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2347 #line 2348 "y.tab.c"
2350 case 39: /* redirection: NUMBER GREATER_AND NUMBER */
2351 #line 661 "/usr/local/src/chet/src/bash/src/parse.y"
2353 source
.dest
= (yyvsp
[-2].number
);
2354 redir
.dest
= (yyvsp
[0].number
);
2355 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2357 #line 2358 "y.tab.c"
2360 case 40: /* redirection: REDIR_WORD GREATER_AND NUMBER */
2361 #line 667 "/usr/local/src/chet/src/bash/src/parse.y"
2363 source
.filename
= (yyvsp
[-2].word
);
2364 redir
.dest
= (yyvsp
[0].number
);
2365 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, REDIR_VARASSIGN
);
2367 #line 2368 "y.tab.c"
2370 case 41: /* redirection: LESS_AND WORD */
2371 #line 673 "/usr/local/src/chet/src/bash/src/parse.y"
2374 redir
.filename
= (yyvsp
[0].word
);
2375 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2377 #line 2378 "y.tab.c"
2380 case 42: /* redirection: NUMBER LESS_AND WORD */
2381 #line 679 "/usr/local/src/chet/src/bash/src/parse.y"
2383 source
.dest
= (yyvsp
[-2].number
);
2384 redir
.filename
= (yyvsp
[0].word
);
2385 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2387 #line 2388 "y.tab.c"
2390 case 43: /* redirection: REDIR_WORD LESS_AND WORD */
2391 #line 685 "/usr/local/src/chet/src/bash/src/parse.y"
2393 source
.filename
= (yyvsp
[-2].word
);
2394 redir
.filename
= (yyvsp
[0].word
);
2395 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, REDIR_VARASSIGN
);
2397 #line 2398 "y.tab.c"
2400 case 44: /* redirection: GREATER_AND WORD */
2401 #line 691 "/usr/local/src/chet/src/bash/src/parse.y"
2404 redir
.filename
= (yyvsp
[0].word
);
2405 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2407 #line 2408 "y.tab.c"
2410 case 45: /* redirection: NUMBER GREATER_AND WORD */
2411 #line 697 "/usr/local/src/chet/src/bash/src/parse.y"
2413 source
.dest
= (yyvsp
[-2].number
);
2414 redir
.filename
= (yyvsp
[0].word
);
2415 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2417 #line 2418 "y.tab.c"
2420 case 46: /* redirection: REDIR_WORD GREATER_AND WORD */
2421 #line 703 "/usr/local/src/chet/src/bash/src/parse.y"
2423 source
.filename
= (yyvsp
[-2].word
);
2424 redir
.filename
= (yyvsp
[0].word
);
2425 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, REDIR_VARASSIGN
);
2427 #line 2428 "y.tab.c"
2430 case 47: /* redirection: GREATER_AND '-' */
2431 #line 709 "/usr/local/src/chet/src/bash/src/parse.y"
2435 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2437 #line 2438 "y.tab.c"
2440 case 48: /* redirection: NUMBER GREATER_AND '-' */
2441 #line 715 "/usr/local/src/chet/src/bash/src/parse.y"
2443 source
.dest
= (yyvsp
[-2].number
);
2445 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2447 #line 2448 "y.tab.c"
2450 case 49: /* redirection: REDIR_WORD GREATER_AND '-' */
2451 #line 721 "/usr/local/src/chet/src/bash/src/parse.y"
2453 source
.filename
= (yyvsp
[-2].word
);
2455 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2457 #line 2458 "y.tab.c"
2460 case 50: /* redirection: LESS_AND '-' */
2461 #line 727 "/usr/local/src/chet/src/bash/src/parse.y"
2465 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2467 #line 2468 "y.tab.c"
2470 case 51: /* redirection: NUMBER LESS_AND '-' */
2471 #line 733 "/usr/local/src/chet/src/bash/src/parse.y"
2473 source
.dest
= (yyvsp
[-2].number
);
2475 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2477 #line 2478 "y.tab.c"
2480 case 52: /* redirection: REDIR_WORD LESS_AND '-' */
2481 #line 739 "/usr/local/src/chet/src/bash/src/parse.y"
2483 source
.filename
= (yyvsp
[-2].word
);
2485 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2487 #line 2488 "y.tab.c"
2490 case 53: /* redirection: AND_GREATER WORD */
2491 #line 745 "/usr/local/src/chet/src/bash/src/parse.y"
2494 redir
.filename
= (yyvsp
[0].word
);
2495 (yyval
.redirect
) = make_redirection (source
, r_err_and_out
, redir
, 0);
2497 #line 2498 "y.tab.c"
2500 case 54: /* redirection: AND_GREATER_GREATER WORD */
2501 #line 751 "/usr/local/src/chet/src/bash/src/parse.y"
2504 redir
.filename
= (yyvsp
[0].word
);
2505 (yyval
.redirect
) = make_redirection (source
, r_append_err_and_out
, redir
, 0);
2507 #line 2508 "y.tab.c"
2510 case 55: /* simple_command_element: WORD */
2511 #line 759 "/usr/local/src/chet/src/bash/src/parse.y"
2512 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2513 #line 2514 "y.tab.c"
2516 case 56: /* simple_command_element: ASSIGNMENT_WORD */
2517 #line 761 "/usr/local/src/chet/src/bash/src/parse.y"
2518 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2519 #line 2520 "y.tab.c"
2522 case 57: /* simple_command_element: redirection */
2523 #line 763 "/usr/local/src/chet/src/bash/src/parse.y"
2524 { (yyval
.element
).redirect
= (yyvsp
[0].redirect
); (yyval
.element
).word
= 0; }
2525 #line 2526 "y.tab.c"
2528 case 58: /* redirection_list: redirection */
2529 #line 767 "/usr/local/src/chet/src/bash/src/parse.y"
2531 (yyval
.redirect
) = (yyvsp
[0].redirect
);
2533 #line 2534 "y.tab.c"
2536 case 59: /* redirection_list: redirection_list redirection */
2537 #line 771 "/usr/local/src/chet/src/bash/src/parse.y"
2539 register REDIRECT
*t
;
2541 for (t
= (yyvsp
[-1].redirect
); t
->next
; t
= t
->next
)
2543 t
->next
= (yyvsp
[0].redirect
);
2544 (yyval
.redirect
) = (yyvsp
[-1].redirect
);
2546 #line 2547 "y.tab.c"
2549 case 60: /* simple_command: simple_command_element */
2550 #line 782 "/usr/local/src/chet/src/bash/src/parse.y"
2551 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (COMMAND
*)NULL
); }
2552 #line 2553 "y.tab.c"
2555 case 61: /* simple_command: simple_command simple_command_element */
2556 #line 784 "/usr/local/src/chet/src/bash/src/parse.y"
2557 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (yyvsp
[-1].command
)); }
2558 #line 2559 "y.tab.c"
2561 case 62: /* command: simple_command */
2562 #line 788 "/usr/local/src/chet/src/bash/src/parse.y"
2563 { (yyval
.command
) = clean_simple_command ((yyvsp
[0].command
)); }
2564 #line 2565 "y.tab.c"
2567 case 63: /* command: shell_command */
2568 #line 790 "/usr/local/src/chet/src/bash/src/parse.y"
2569 { (yyval
.command
) = (yyvsp
[0].command
); }
2570 #line 2571 "y.tab.c"
2573 case 64: /* command: shell_command redirection_list */
2574 #line 792 "/usr/local/src/chet/src/bash/src/parse.y"
2578 tc
= (yyvsp
[-1].command
);
2579 if (tc
&& tc
->redirects
)
2581 register REDIRECT
*t
;
2582 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2584 t
->next
= (yyvsp
[0].redirect
);
2587 tc
->redirects
= (yyvsp
[0].redirect
);
2588 (yyval
.command
) = (yyvsp
[-1].command
);
2590 #line 2591 "y.tab.c"
2593 case 65: /* command: function_def */
2594 #line 808 "/usr/local/src/chet/src/bash/src/parse.y"
2595 { (yyval
.command
) = (yyvsp
[0].command
); }
2596 #line 2597 "y.tab.c"
2599 case 66: /* command: coproc */
2600 #line 810 "/usr/local/src/chet/src/bash/src/parse.y"
2601 { (yyval
.command
) = (yyvsp
[0].command
); }
2602 #line 2603 "y.tab.c"
2605 case 67: /* shell_command: for_command */
2606 #line 814 "/usr/local/src/chet/src/bash/src/parse.y"
2607 { (yyval
.command
) = (yyvsp
[0].command
); }
2608 #line 2609 "y.tab.c"
2611 case 68: /* shell_command: case_command */
2612 #line 816 "/usr/local/src/chet/src/bash/src/parse.y"
2613 { (yyval
.command
) = (yyvsp
[0].command
); }
2614 #line 2615 "y.tab.c"
2617 case 69: /* shell_command: WHILE compound_list DO compound_list DONE */
2618 #line 818 "/usr/local/src/chet/src/bash/src/parse.y"
2619 { (yyval
.command
) = make_while_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2620 #line 2621 "y.tab.c"
2623 case 70: /* shell_command: UNTIL compound_list DO compound_list DONE */
2624 #line 820 "/usr/local/src/chet/src/bash/src/parse.y"
2625 { (yyval
.command
) = make_until_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2626 #line 2627 "y.tab.c"
2629 case 71: /* shell_command: select_command */
2630 #line 822 "/usr/local/src/chet/src/bash/src/parse.y"
2631 { (yyval
.command
) = (yyvsp
[0].command
); }
2632 #line 2633 "y.tab.c"
2635 case 72: /* shell_command: if_command */
2636 #line 824 "/usr/local/src/chet/src/bash/src/parse.y"
2637 { (yyval
.command
) = (yyvsp
[0].command
); }
2638 #line 2639 "y.tab.c"
2641 case 73: /* shell_command: subshell */
2642 #line 826 "/usr/local/src/chet/src/bash/src/parse.y"
2643 { (yyval
.command
) = (yyvsp
[0].command
); }
2644 #line 2645 "y.tab.c"
2647 case 74: /* shell_command: group_command */
2648 #line 828 "/usr/local/src/chet/src/bash/src/parse.y"
2649 { (yyval
.command
) = (yyvsp
[0].command
); }
2650 #line 2651 "y.tab.c"
2653 case 75: /* shell_command: arith_command */
2654 #line 830 "/usr/local/src/chet/src/bash/src/parse.y"
2655 { (yyval
.command
) = (yyvsp
[0].command
); }
2656 #line 2657 "y.tab.c"
2659 case 76: /* shell_command: cond_command */
2660 #line 832 "/usr/local/src/chet/src/bash/src/parse.y"
2661 { (yyval
.command
) = (yyvsp
[0].command
); }
2662 #line 2663 "y.tab.c"
2665 case 77: /* shell_command: arith_for_command */
2666 #line 834 "/usr/local/src/chet/src/bash/src/parse.y"
2667 { (yyval
.command
) = (yyvsp
[0].command
); }
2668 #line 2669 "y.tab.c"
2671 case 78: /* for_command: FOR WORD newline_list DO compound_list DONE */
2672 #line 838 "/usr/local/src/chet/src/bash/src/parse.y"
2674 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2675 if (word_top
> 0) word_top
--;
2677 #line 2678 "y.tab.c"
2680 case 79: /* for_command: FOR WORD newline_list '{' compound_list '}' */
2681 #line 843 "/usr/local/src/chet/src/bash/src/parse.y"
2683 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2684 if (word_top
> 0) word_top
--;
2686 #line 2687 "y.tab.c"
2689 case 80: /* for_command: FOR WORD ';' newline_list DO compound_list DONE */
2690 #line 848 "/usr/local/src/chet/src/bash/src/parse.y"
2692 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2693 if (word_top
> 0) word_top
--;
2695 #line 2696 "y.tab.c"
2698 case 81: /* for_command: FOR WORD ';' newline_list '{' compound_list '}' */
2699 #line 853 "/usr/local/src/chet/src/bash/src/parse.y"
2701 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2702 if (word_top
> 0) word_top
--;
2704 #line 2705 "y.tab.c"
2707 case 82: /* for_command: FOR WORD newline_list IN word_list list_terminator newline_list DO compound_list DONE */
2708 #line 858 "/usr/local/src/chet/src/bash/src/parse.y"
2710 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2711 if (word_top
> 0) word_top
--;
2713 #line 2714 "y.tab.c"
2716 case 83: /* for_command: FOR WORD newline_list IN word_list list_terminator newline_list '{' compound_list '}' */
2717 #line 863 "/usr/local/src/chet/src/bash/src/parse.y"
2719 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2720 if (word_top
> 0) word_top
--;
2722 #line 2723 "y.tab.c"
2725 case 84: /* for_command: FOR WORD newline_list IN list_terminator newline_list DO compound_list DONE */
2726 #line 868 "/usr/local/src/chet/src/bash/src/parse.y"
2728 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2729 if (word_top
> 0) word_top
--;
2731 #line 2732 "y.tab.c"
2734 case 85: /* for_command: FOR WORD newline_list IN list_terminator newline_list '{' compound_list '}' */
2735 #line 873 "/usr/local/src/chet/src/bash/src/parse.y"
2737 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2738 if (word_top
> 0) word_top
--;
2740 #line 2741 "y.tab.c"
2743 case 86: /* arith_for_command: FOR ARITH_FOR_EXPRS list_terminator newline_list DO compound_list DONE */
2744 #line 880 "/usr/local/src/chet/src/bash/src/parse.y"
2746 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2747 if ((yyval
.command
) == 0) YYERROR
;
2748 if (word_top
> 0) word_top
--;
2750 #line 2751 "y.tab.c"
2753 case 87: /* arith_for_command: FOR ARITH_FOR_EXPRS list_terminator newline_list '{' compound_list '}' */
2754 #line 886 "/usr/local/src/chet/src/bash/src/parse.y"
2756 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2757 if ((yyval
.command
) == 0) YYERROR
;
2758 if (word_top
> 0) word_top
--;
2760 #line 2761 "y.tab.c"
2763 case 88: /* arith_for_command: FOR ARITH_FOR_EXPRS DO compound_list DONE */
2764 #line 892 "/usr/local/src/chet/src/bash/src/parse.y"
2766 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2767 if ((yyval
.command
) == 0) YYERROR
;
2768 if (word_top
> 0) word_top
--;
2770 #line 2771 "y.tab.c"
2773 case 89: /* arith_for_command: FOR ARITH_FOR_EXPRS '{' compound_list '}' */
2774 #line 898 "/usr/local/src/chet/src/bash/src/parse.y"
2776 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2777 if ((yyval
.command
) == 0) YYERROR
;
2778 if (word_top
> 0) word_top
--;
2780 #line 2781 "y.tab.c"
2783 case 90: /* select_command: SELECT WORD newline_list DO compound_list DONE */
2784 #line 906 "/usr/local/src/chet/src/bash/src/parse.y"
2786 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2787 if (word_top
> 0) word_top
--;
2789 #line 2790 "y.tab.c"
2792 case 91: /* select_command: SELECT WORD newline_list '{' compound_list '}' */
2793 #line 911 "/usr/local/src/chet/src/bash/src/parse.y"
2795 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2796 if (word_top
> 0) word_top
--;
2798 #line 2799 "y.tab.c"
2801 case 92: /* select_command: SELECT WORD ';' newline_list DO compound_list DONE */
2802 #line 916 "/usr/local/src/chet/src/bash/src/parse.y"
2804 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2805 if (word_top
> 0) word_top
--;
2807 #line 2808 "y.tab.c"
2810 case 93: /* select_command: SELECT WORD ';' newline_list '{' compound_list '}' */
2811 #line 921 "/usr/local/src/chet/src/bash/src/parse.y"
2813 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2814 if (word_top
> 0) word_top
--;
2816 #line 2817 "y.tab.c"
2819 case 94: /* select_command: SELECT WORD newline_list IN word_list list_terminator newline_list DO compound_list DONE */
2820 #line 926 "/usr/local/src/chet/src/bash/src/parse.y"
2822 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2823 if (word_top
> 0) word_top
--;
2825 #line 2826 "y.tab.c"
2828 case 95: /* select_command: SELECT WORD newline_list IN word_list list_terminator newline_list '{' compound_list '}' */
2829 #line 931 "/usr/local/src/chet/src/bash/src/parse.y"
2831 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2832 if (word_top
> 0) word_top
--;
2834 #line 2835 "y.tab.c"
2837 case 96: /* select_command: SELECT WORD newline_list IN list_terminator newline_list DO compound_list DONE */
2838 #line 936 "/usr/local/src/chet/src/bash/src/parse.y"
2840 (yyval
.command
) = make_select_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2841 if (word_top
> 0) word_top
--;
2843 #line 2844 "y.tab.c"
2846 case 97: /* select_command: SELECT WORD newline_list IN list_terminator newline_list '{' compound_list '}' */
2847 #line 941 "/usr/local/src/chet/src/bash/src/parse.y"
2849 (yyval
.command
) = make_select_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2850 if (word_top
> 0) word_top
--;
2852 #line 2853 "y.tab.c"
2855 case 98: /* case_command: CASE WORD newline_list IN newline_list ESAC */
2856 #line 948 "/usr/local/src/chet/src/bash/src/parse.y"
2858 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (PATTERN_LIST
*)NULL
, word_lineno
[word_top
]);
2859 if (word_top
> 0) word_top
--;
2861 #line 2862 "y.tab.c"
2864 case 99: /* case_command: CASE WORD newline_list IN case_clause_sequence newline_list ESAC */
2865 #line 953 "/usr/local/src/chet/src/bash/src/parse.y"
2867 (yyval
.command
) = make_case_command ((yyvsp
[-5].word
), (yyvsp
[-2].pattern
), word_lineno
[word_top
]);
2868 if (word_top
> 0) word_top
--;
2870 #line 2871 "y.tab.c"
2873 case 100: /* case_command: CASE WORD newline_list IN case_clause ESAC */
2874 #line 958 "/usr/local/src/chet/src/bash/src/parse.y"
2876 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (yyvsp
[-1].pattern
), word_lineno
[word_top
]);
2877 if (word_top
> 0) word_top
--;
2879 #line 2880 "y.tab.c"
2882 case 101: /* function_def: WORD '(' ')' newline_list function_body */
2883 #line 965 "/usr/local/src/chet/src/bash/src/parse.y"
2884 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2885 #line 2886 "y.tab.c"
2888 case 102: /* function_def: FUNCTION WORD '(' ')' newline_list function_body */
2889 #line 967 "/usr/local/src/chet/src/bash/src/parse.y"
2890 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2891 #line 2892 "y.tab.c"
2894 case 103: /* function_def: FUNCTION WORD function_body */
2895 #line 969 "/usr/local/src/chet/src/bash/src/parse.y"
2896 { (yyval
.command
) = make_function_def ((yyvsp
[-1].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2897 #line 2898 "y.tab.c"
2900 case 104: /* function_def: FUNCTION WORD '\n' newline_list function_body */
2901 #line 971 "/usr/local/src/chet/src/bash/src/parse.y"
2902 { (yyval
.command
) = make_function_def ((yyvsp
[-3].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2903 #line 2904 "y.tab.c"
2906 case 105: /* function_body: shell_command */
2907 #line 975 "/usr/local/src/chet/src/bash/src/parse.y"
2908 { (yyval
.command
) = (yyvsp
[0].command
); }
2909 #line 2910 "y.tab.c"
2912 case 106: /* function_body: shell_command redirection_list */
2913 #line 977 "/usr/local/src/chet/src/bash/src/parse.y"
2917 tc
= (yyvsp
[-1].command
);
2918 /* According to Posix.2 3.9.5, redirections
2919 specified after the body of a function should
2920 be attached to the function and performed when
2921 the function is executed, not as part of the
2922 function definition command. */
2923 /* XXX - I don't think it matters, but we might
2924 want to change this in the future to avoid
2925 problems differentiating between a function
2926 definition with a redirection and a function
2927 definition containing a single command with a
2928 redirection. The two are semantically equivalent,
2929 though -- the only difference is in how the
2930 command printing code displays the redirections. */
2931 if (tc
&& tc
->redirects
)
2933 register REDIRECT
*t
;
2934 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2936 t
->next
= (yyvsp
[0].redirect
);
2939 tc
->redirects
= (yyvsp
[0].redirect
);
2940 (yyval
.command
) = (yyvsp
[-1].command
);
2942 #line 2943 "y.tab.c"
2945 case 107: /* subshell: '(' compound_list ')' */
2946 #line 1008 "/usr/local/src/chet/src/bash/src/parse.y"
2948 (yyval
.command
) = make_subshell_command ((yyvsp
[-1].command
));
2949 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
;
2951 #line 2952 "y.tab.c"
2954 case 108: /* comsub: DOLPAREN compound_list ')' */
2955 #line 1015 "/usr/local/src/chet/src/bash/src/parse.y"
2957 (yyval
.command
) = (yyvsp
[-1].command
);
2959 #line 2960 "y.tab.c"
2962 case 109: /* comsub: DOLPAREN newline_list ')' */
2963 #line 1019 "/usr/local/src/chet/src/bash/src/parse.y"
2965 (yyval
.command
) = (COMMAND
*)NULL
;
2967 #line 2968 "y.tab.c"
2970 case 110: /* coproc: COPROC shell_command */
2971 #line 1025 "/usr/local/src/chet/src/bash/src/parse.y"
2973 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[0].command
));
2974 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2976 #line 2977 "y.tab.c"
2979 case 111: /* coproc: COPROC shell_command redirection_list */
2980 #line 1030 "/usr/local/src/chet/src/bash/src/parse.y"
2984 tc
= (yyvsp
[-1].command
);
2985 if (tc
&& tc
->redirects
)
2987 register REDIRECT
*t
;
2988 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2990 t
->next
= (yyvsp
[0].redirect
);
2993 tc
->redirects
= (yyvsp
[0].redirect
);
2994 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[-1].command
));
2995 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2997 #line 2998 "y.tab.c"
3000 case 112: /* coproc: COPROC WORD shell_command */
3001 #line 1047 "/usr/local/src/chet/src/bash/src/parse.y"
3003 (yyval
.command
) = make_coproc_command ((yyvsp
[-1].word
)->word
, (yyvsp
[0].command
));
3004 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
3006 #line 3007 "y.tab.c"
3009 case 113: /* coproc: COPROC WORD shell_command redirection_list */
3010 #line 1052 "/usr/local/src/chet/src/bash/src/parse.y"
3014 tc
= (yyvsp
[-1].command
);
3015 if (tc
&& tc
->redirects
)
3017 register REDIRECT
*t
;
3018 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
3020 t
->next
= (yyvsp
[0].redirect
);
3023 tc
->redirects
= (yyvsp
[0].redirect
);
3024 (yyval
.command
) = make_coproc_command ((yyvsp
[-2].word
)->word
, (yyvsp
[-1].command
));
3025 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
3027 #line 3028 "y.tab.c"
3030 case 114: /* coproc: COPROC simple_command */
3031 #line 1069 "/usr/local/src/chet/src/bash/src/parse.y"
3033 (yyval
.command
) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp
[0].command
)));
3034 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
3036 #line 3037 "y.tab.c"
3039 case 115: /* if_command: IF compound_list THEN compound_list FI */
3040 #line 1076 "/usr/local/src/chet/src/bash/src/parse.y"
3041 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (COMMAND
*)NULL
); }
3042 #line 3043 "y.tab.c"
3045 case 116: /* if_command: IF compound_list THEN compound_list ELSE compound_list FI */
3046 #line 1078 "/usr/local/src/chet/src/bash/src/parse.y"
3047 { (yyval
.command
) = make_if_command ((yyvsp
[-5].command
), (yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
3048 #line 3049 "y.tab.c"
3051 case 117: /* if_command: IF compound_list THEN compound_list elif_clause FI */
3052 #line 1080 "/usr/local/src/chet/src/bash/src/parse.y"
3053 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[-1].command
)); }
3054 #line 3055 "y.tab.c"
3057 case 118: /* group_command: '{' compound_list '}' */
3058 #line 1085 "/usr/local/src/chet/src/bash/src/parse.y"
3059 { (yyval
.command
) = make_group_command ((yyvsp
[-1].command
)); }
3060 #line 3061 "y.tab.c"
3063 case 119: /* arith_command: ARITH_CMD */
3064 #line 1089 "/usr/local/src/chet/src/bash/src/parse.y"
3065 { (yyval
.command
) = make_arith_command ((yyvsp
[0].word_list
)); }
3066 #line 3067 "y.tab.c"
3069 case 120: /* cond_command: COND_START COND_CMD COND_END */
3070 #line 1093 "/usr/local/src/chet/src/bash/src/parse.y"
3071 { (yyval
.command
) = (yyvsp
[-1].command
); }
3072 #line 3073 "y.tab.c"
3075 case 121: /* elif_clause: ELIF compound_list THEN compound_list */
3076 #line 1097 "/usr/local/src/chet/src/bash/src/parse.y"
3077 { (yyval
.command
) = make_if_command ((yyvsp
[-2].command
), (yyvsp
[0].command
), (COMMAND
*)NULL
); }
3078 #line 3079 "y.tab.c"
3081 case 122: /* elif_clause: ELIF compound_list THEN compound_list ELSE compound_list */
3082 #line 1099 "/usr/local/src/chet/src/bash/src/parse.y"
3083 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[0].command
)); }
3084 #line 3085 "y.tab.c"
3087 case 123: /* elif_clause: ELIF compound_list THEN compound_list elif_clause */
3088 #line 1101 "/usr/local/src/chet/src/bash/src/parse.y"
3089 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (yyvsp
[0].command
)); }
3090 #line 3091 "y.tab.c"
3093 case 125: /* case_clause: case_clause_sequence pattern_list */
3094 #line 1106 "/usr/local/src/chet/src/bash/src/parse.y"
3095 { (yyvsp
[0].pattern
)->next
= (yyvsp
[-1].pattern
); (yyval
.pattern
) = (yyvsp
[0].pattern
); }
3096 #line 3097 "y.tab.c"
3099 case 126: /* pattern_list: newline_list pattern ')' compound_list */
3100 #line 1110 "/usr/local/src/chet/src/bash/src/parse.y"
3101 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
3102 #line 3103 "y.tab.c"
3105 case 127: /* pattern_list: newline_list pattern ')' newline_list */
3106 #line 1112 "/usr/local/src/chet/src/bash/src/parse.y"
3107 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
3108 #line 3109 "y.tab.c"
3111 case 128: /* pattern_list: newline_list '(' pattern ')' compound_list */
3112 #line 1114 "/usr/local/src/chet/src/bash/src/parse.y"
3113 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
3114 #line 3115 "y.tab.c"
3117 case 129: /* pattern_list: newline_list '(' pattern ')' newline_list */
3118 #line 1116 "/usr/local/src/chet/src/bash/src/parse.y"
3119 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
3120 #line 3121 "y.tab.c"
3123 case 130: /* case_clause_sequence: pattern_list SEMI_SEMI */
3124 #line 1120 "/usr/local/src/chet/src/bash/src/parse.y"
3125 { (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3126 #line 3127 "y.tab.c"
3129 case 131: /* case_clause_sequence: case_clause_sequence pattern_list SEMI_SEMI */
3130 #line 1122 "/usr/local/src/chet/src/bash/src/parse.y"
3131 { (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3132 #line 3133 "y.tab.c"
3135 case 132: /* case_clause_sequence: pattern_list SEMI_AND */
3136 #line 1124 "/usr/local/src/chet/src/bash/src/parse.y"
3137 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3138 #line 3139 "y.tab.c"
3141 case 133: /* case_clause_sequence: case_clause_sequence pattern_list SEMI_AND */
3142 #line 1126 "/usr/local/src/chet/src/bash/src/parse.y"
3143 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3144 #line 3145 "y.tab.c"
3147 case 134: /* case_clause_sequence: pattern_list SEMI_SEMI_AND */
3148 #line 1128 "/usr/local/src/chet/src/bash/src/parse.y"
3149 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3150 #line 3151 "y.tab.c"
3153 case 135: /* case_clause_sequence: case_clause_sequence pattern_list SEMI_SEMI_AND */
3154 #line 1130 "/usr/local/src/chet/src/bash/src/parse.y"
3155 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3156 #line 3157 "y.tab.c"
3159 case 136: /* pattern: WORD */
3160 #line 1134 "/usr/local/src/chet/src/bash/src/parse.y"
3161 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
3162 #line 3163 "y.tab.c"
3165 case 137: /* pattern: pattern '|' WORD */
3166 #line 1136 "/usr/local/src/chet/src/bash/src/parse.y"
3167 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-2].word_list
)); }
3168 #line 3169 "y.tab.c"
3171 case 138: /* compound_list: newline_list list0 */
3172 #line 1145 "/usr/local/src/chet/src/bash/src/parse.y"
3174 (yyval
.command
) = (yyvsp
[0].command
);
3175 if (need_here_doc
&& last_read_token
== '\n')
3176 gather_here_documents ();
3178 #line 3179 "y.tab.c"
3181 case 139: /* compound_list: newline_list list1 */
3182 #line 1151 "/usr/local/src/chet/src/bash/src/parse.y"
3184 (yyval
.command
) = (yyvsp
[0].command
);
3186 #line 3187 "y.tab.c"
3189 case 141: /* list0: list1 '&' newline_list */
3190 #line 1158 "/usr/local/src/chet/src/bash/src/parse.y"
3192 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3193 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3195 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3197 #line 3198 "y.tab.c"
3200 case 143: /* list1: list1 AND_AND newline_list list1 */
3201 #line 1169 "/usr/local/src/chet/src/bash/src/parse.y"
3202 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3203 #line 3204 "y.tab.c"
3206 case 144: /* list1: list1 OR_OR newline_list list1 */
3207 #line 1171 "/usr/local/src/chet/src/bash/src/parse.y"
3208 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3209 #line 3210 "y.tab.c"
3212 case 145: /* list1: list1 '&' newline_list list1 */
3213 #line 1173 "/usr/local/src/chet/src/bash/src/parse.y"
3215 if ((yyvsp
[-3].command
)->type
== cm_connection
)
3216 (yyval
.command
) = connect_async_list ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3218 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3220 #line 3221 "y.tab.c"
3223 case 146: /* list1: list1 ';' newline_list list1 */
3224 #line 1180 "/usr/local/src/chet/src/bash/src/parse.y"
3225 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';'); }
3226 #line 3227 "y.tab.c"
3229 case 147: /* list1: list1 '\n' newline_list list1 */
3230 #line 1182 "/usr/local/src/chet/src/bash/src/parse.y"
3232 if (parser_state
& PST_CMDSUBST
)
3233 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '\n');
3235 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';');
3237 #line 3238 "y.tab.c"
3240 case 148: /* list1: pipeline_command */
3241 #line 1189 "/usr/local/src/chet/src/bash/src/parse.y"
3242 { (yyval
.command
) = (yyvsp
[0].command
); }
3243 #line 3244 "y.tab.c"
3246 case 151: /* list_terminator: '\n' */
3247 #line 1197 "/usr/local/src/chet/src/bash/src/parse.y"
3248 { (yyval
.number
) = '\n'; }
3249 #line 3250 "y.tab.c"
3252 case 152: /* list_terminator: ';' */
3253 #line 1199 "/usr/local/src/chet/src/bash/src/parse.y"
3254 { (yyval
.number
) = ';'; }
3255 #line 3256 "y.tab.c"
3258 case 153: /* list_terminator: yacc_EOF */
3259 #line 1201 "/usr/local/src/chet/src/bash/src/parse.y"
3260 { (yyval
.number
) = yacc_EOF
; }
3261 #line 3262 "y.tab.c"
3264 case 156: /* simple_list: simple_list1 */
3265 #line 1215 "/usr/local/src/chet/src/bash/src/parse.y"
3267 (yyval
.command
) = (yyvsp
[0].command
);
3269 gather_here_documents (); /* XXX */
3270 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3272 INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 -> simple_list"));
3273 global_command
= (yyvsp
[0].command
);
3274 eof_encountered
= 0;
3275 if (bash_input
.type
== st_string
)
3276 rewind_input_string ();
3280 #line 3281 "y.tab.c"
3283 case 157: /* simple_list: simple_list1 '&' */
3284 #line 1230 "/usr/local/src/chet/src/bash/src/parse.y"
3286 if ((yyvsp
[-1].command
)->type
== cm_connection
)
3287 (yyval
.command
) = connect_async_list ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3289 (yyval
.command
) = command_connect ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3291 gather_here_documents (); /* XXX */
3292 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3294 INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 '&' -> simple_list"));
3295 global_command
= (yyvsp
[-1].command
);
3296 eof_encountered
= 0;
3297 if (bash_input
.type
== st_string
)
3298 rewind_input_string ();
3302 #line 3303 "y.tab.c"
3305 case 158: /* simple_list: simple_list1 ';' */
3306 #line 1248 "/usr/local/src/chet/src/bash/src/parse.y"
3308 (yyval
.command
) = (yyvsp
[-1].command
);
3310 gather_here_documents (); /* XXX */
3311 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3313 INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 ';' -> simple_list"));
3314 global_command
= (yyvsp
[-1].command
);
3315 eof_encountered
= 0;
3316 if (bash_input
.type
== st_string
)
3317 rewind_input_string ();
3321 #line 3322 "y.tab.c"
3324 case 159: /* simple_list1: simple_list1 AND_AND newline_list simple_list1 */
3325 #line 1265 "/usr/local/src/chet/src/bash/src/parse.y"
3326 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3327 #line 3328 "y.tab.c"
3330 case 160: /* simple_list1: simple_list1 OR_OR newline_list simple_list1 */
3331 #line 1267 "/usr/local/src/chet/src/bash/src/parse.y"
3332 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3333 #line 3334 "y.tab.c"
3336 case 161: /* simple_list1: simple_list1 '&' simple_list1 */
3337 #line 1269 "/usr/local/src/chet/src/bash/src/parse.y"
3339 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3340 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3342 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3344 #line 3345 "y.tab.c"
3347 case 162: /* simple_list1: simple_list1 ';' simple_list1 */
3348 #line 1276 "/usr/local/src/chet/src/bash/src/parse.y"
3349 { (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), ';'); }
3350 #line 3351 "y.tab.c"
3353 case 163: /* simple_list1: pipeline_command */
3354 #line 1279 "/usr/local/src/chet/src/bash/src/parse.y"
3355 { (yyval
.command
) = (yyvsp
[0].command
); }
3356 #line 3357 "y.tab.c"
3359 case 164: /* pipeline_command: pipeline */
3360 #line 1283 "/usr/local/src/chet/src/bash/src/parse.y"
3361 { (yyval
.command
) = (yyvsp
[0].command
); }
3362 #line 3363 "y.tab.c"
3365 case 165: /* pipeline_command: BANG pipeline_command */
3366 #line 1285 "/usr/local/src/chet/src/bash/src/parse.y"
3368 if ((yyvsp
[0].command
))
3369 (yyvsp
[0].command
)->flags
^= CMD_INVERT_RETURN
; /* toggle */
3370 (yyval
.command
) = (yyvsp
[0].command
);
3372 #line 3373 "y.tab.c"
3375 case 166: /* pipeline_command: timespec pipeline_command */
3376 #line 1291 "/usr/local/src/chet/src/bash/src/parse.y"
3378 if ((yyvsp
[0].command
))
3379 (yyvsp
[0].command
)->flags
|= (yyvsp
[-1].number
);
3380 (yyval
.command
) = (yyvsp
[0].command
);
3382 #line 3383 "y.tab.c"
3385 case 167: /* pipeline_command: timespec list_terminator */
3386 #line 1297 "/usr/local/src/chet/src/bash/src/parse.y"
3390 /* Boy, this is unclean. `time' by itself can
3391 time a null command. We cheat and push a
3392 newline back if the list_terminator was a newline
3393 to avoid the double-newline problem (one to
3394 terminate this, one to terminate the command) */
3397 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3398 (yyval
.command
)->flags
|= (yyvsp
[-1].number
);
3399 /* XXX - let's cheat and push a newline back */
3400 if ((yyvsp
[0].number
) == '\n')
3401 token_to_read
= '\n';
3402 else if ((yyvsp
[0].number
) == ';')
3403 token_to_read
= ';';
3404 parser_state
&= ~PST_REDIRLIST
; /* make_simple_command sets this */
3406 #line 3407 "y.tab.c"
3409 case 168: /* pipeline_command: BANG list_terminator */
3410 #line 1317 "/usr/local/src/chet/src/bash/src/parse.y"
3414 /* This is just as unclean. Posix says that `!'
3415 by itself should be equivalent to `false'.
3417 newline back if the list_terminator was a newline
3418 to avoid the double-newline problem (one to
3419 terminate this, one to terminate the command) */
3422 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3423 (yyval
.command
)->flags
|= CMD_INVERT_RETURN
;
3424 /* XXX - let's cheat and push a newline back */
3425 if ((yyvsp
[0].number
) == '\n')
3426 token_to_read
= '\n';
3427 if ((yyvsp
[0].number
) == ';')
3428 token_to_read
= ';';
3429 parser_state
&= ~PST_REDIRLIST
; /* make_simple_command sets this */
3431 #line 3432 "y.tab.c"
3434 case 169: /* pipeline: pipeline '|' newline_list pipeline */
3435 #line 1340 "/usr/local/src/chet/src/bash/src/parse.y"
3436 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|'); }
3437 #line 3438 "y.tab.c"
3440 case 170: /* pipeline: pipeline BAR_AND newline_list pipeline */
3441 #line 1342 "/usr/local/src/chet/src/bash/src/parse.y"
3443 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3448 tc
= (yyvsp
[-3].command
)->type
== cm_simple
? (COMMAND
*)(yyvsp
[-3].command
)->value
.Simple
: (yyvsp
[-3].command
);
3451 r
= make_redirection (sd
, r_duplicating_output
, rd
, 0);
3454 register REDIRECT
*t
;
3455 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
3462 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|');
3464 #line 3465 "y.tab.c"
3467 case 171: /* pipeline: command */
3468 #line 1365 "/usr/local/src/chet/src/bash/src/parse.y"
3469 { (yyval
.command
) = (yyvsp
[0].command
); }
3470 #line 3471 "y.tab.c"
3473 case 172: /* timespec: TIME */
3474 #line 1369 "/usr/local/src/chet/src/bash/src/parse.y"
3475 { (yyval
.number
) = CMD_TIME_PIPELINE
; }
3476 #line 3477 "y.tab.c"
3479 case 173: /* timespec: TIME TIMEOPT */
3480 #line 1371 "/usr/local/src/chet/src/bash/src/parse.y"
3481 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3482 #line 3483 "y.tab.c"
3485 case 174: /* timespec: TIME TIMEIGN */
3486 #line 1373 "/usr/local/src/chet/src/bash/src/parse.y"
3487 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3488 #line 3489 "y.tab.c"
3491 case 175: /* timespec: TIME TIMEOPT TIMEIGN */
3492 #line 1375 "/usr/local/src/chet/src/bash/src/parse.y"
3493 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3494 #line 3495 "y.tab.c"
3498 #line 3499 "y.tab.c"
3502 /* User semantic actions sometimes alter yychar, and that requires
3503 that yytoken be updated with the new translation. We take the
3504 approach of translating immediately before every use of yytoken.
3505 One alternative is translating here after every semantic action,
3506 but that translation would be missed if the semantic action invokes
3507 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3508 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
3509 incorrect destructor might then be invoked immediately. In the
3510 case of YYERROR or YYBACKUP, subsequent parser actions might lead
3511 to an incorrect destructor call or verbose syntax error message
3512 before the lookahead is translated. */
3513 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t
, yyr1
[yyn
]), &yyval
, &yyloc
);
3520 /* Now 'shift' the result of the reduction. Determine what state
3521 that goes to, based on the state we popped back to and the rule
3522 number reduced by. */
3524 const int yylhs
= yyr1
[yyn
] - YYNTOKENS
;
3525 const int yyi
= yypgoto
[yylhs
] + *yyssp
;
3526 yystate
= (0 <= yyi
&& yyi
<= YYLAST
&& yycheck
[yyi
] == *yyssp
3528 : yydefgoto
[yylhs
]);
3534 /*--------------------------------------.
3535 | yyerrlab -- here on detecting error. |
3536 `--------------------------------------*/
3538 /* Make sure we have latest lookahead translation. See comments at
3539 user semantic actions for why this is necessary. */
3540 yytoken
= yychar
== YYEMPTY
? YYSYMBOL_YYEMPTY
: YYTRANSLATE (yychar
);
3541 /* If not already recovering from an error, report this error. */
3545 yyerror (YY_("syntax error"));
3548 if (yyerrstatus
== 3)
3550 /* If just tried and failed to reuse lookahead token after an
3551 error, discard it. */
3553 if (yychar
<= YYEOF
)
3555 /* Return failure if at end of input. */
3556 if (yychar
== YYEOF
)
3561 yydestruct ("Error: discarding",
3567 /* Else will try to reuse lookahead token after shifting the error
3572 /*---------------------------------------------------.
3573 | yyerrorlab -- error raised explicitly by YYERROR. |
3574 `---------------------------------------------------*/
3576 /* Pacify compilers when the user code never invokes YYERROR and the
3577 label yyerrorlab therefore never appears in user code. */
3582 /* Do not reclaim the symbols of the rule whose action triggered
3586 YY_STACK_PRINT (yyss
, yyssp
);
3591 /*-------------------------------------------------------------.
3592 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3593 `-------------------------------------------------------------*/
3595 yyerrstatus
= 3; /* Each real token shifted decrements this. */
3597 /* Pop stack until we find a state that shifts the error token. */
3600 yyn
= yypact
[yystate
];
3601 if (!yypact_value_is_default (yyn
))
3603 yyn
+= YYSYMBOL_YYerror
;
3604 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYSYMBOL_YYerror
)
3612 /* Pop the current state because it cannot handle the error token. */
3617 yydestruct ("Error: popping",
3618 YY_ACCESSING_SYMBOL (yystate
), yyvsp
);
3621 YY_STACK_PRINT (yyss
, yyssp
);
3624 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3626 YY_IGNORE_MAYBE_UNINITIALIZED_END
3629 /* Shift the error token. */
3630 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn
), yyvsp
, yylsp
);
3636 /*-------------------------------------.
3637 | yyacceptlab -- YYACCEPT comes here. |
3638 `-------------------------------------*/
3644 /*-----------------------------------.
3645 | yyabortlab -- YYABORT comes here. |
3646 `-----------------------------------*/
3652 /*-----------------------------------------------------------.
3653 | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
3654 `-----------------------------------------------------------*/
3656 yyerror (YY_("memory exhausted"));
3661 /*----------------------------------------------------------.
3662 | yyreturnlab -- parsing is finished, clean up and return. |
3663 `----------------------------------------------------------*/
3665 if (yychar
!= YYEMPTY
)
3667 /* Make sure we have latest lookahead translation. See comments at
3668 user semantic actions for why this is necessary. */
3669 yytoken
= YYTRANSLATE (yychar
);
3670 yydestruct ("Cleanup: discarding lookahead",
3673 /* Do not reclaim the symbols of the rule whose action triggered
3674 this YYABORT or YYACCEPT. */
3676 YY_STACK_PRINT (yyss
, yyssp
);
3677 while (yyssp
!= yyss
)
3679 yydestruct ("Cleanup: popping",
3680 YY_ACCESSING_SYMBOL (+*yyssp
), yyvsp
);
3685 YYSTACK_FREE (yyss
);
3691 #line 1377 "/usr/local/src/chet/src/bash/src/parse.y"
3694 /* Initial size to allocate for tokens, and the
3695 amount to grow them by. */
3696 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3697 #define TOKEN_DEFAULT_GROW_SIZE 512
3699 /* Should we call prompt_again? */
3700 #define SHOULD_PROMPT() \
3701 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3704 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3706 # define expanding_alias() 0
3709 /* Global var is non-zero when end of file has been reached. */
3710 int EOF_Reached
= 0;
3719 yyoutstream
= stdout
;
3720 yyerrstream
= stderr
;
3725 /* yy_getc () returns the next available character from input or EOF.
3726 yy_ungetc (c) makes `c' the next character to read.
3727 init_yy_io (get, unget, type, location) makes the function GET the
3728 installed function for getting the next character, makes UNGET the
3729 installed function for un-getting a character, sets the type of stream
3730 (either string or file) from TYPE, and makes LOCATION point to where
3731 the input is coming from. */
3733 /* Unconditionally returns end-of-file. */
3740 /* Variable containing the current get and unget functions.
3741 See ./input.h for a clearer description. */
3742 BASH_INPUT bash_input
;
3744 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3745 is non-null, avoiding a memory leak. */
3747 initialize_bash_input ()
3749 bash_input
.type
= st_none
;
3750 FREE (bash_input
.name
);
3751 bash_input
.name
= (char *)NULL
;
3752 bash_input
.location
.file
= (FILE *)NULL
;
3753 bash_input
.location
.string
= (char *)NULL
;
3754 bash_input
.getter
= (sh_cget_func_t
*)NULL
;
3755 bash_input
.ungetter
= (sh_cunget_func_t
*)NULL
;
3758 /* Set the contents of the current bash input stream from
3759 GET, UNGET, TYPE, NAME, and LOCATION. */
3761 init_yy_io (get
, unget
, type
, name
, location
)
3762 sh_cget_func_t
*get
;
3763 sh_cunget_func_t
*unget
;
3764 enum stream_type type
;
3766 INPUT_STREAM location
;
3768 bash_input
.type
= type
;
3769 FREE (bash_input
.name
);
3770 bash_input
.name
= name
? savestring (name
) : (char *)NULL
;
3774 memcpy((char *)&bash_input
.location
.string
, (char *)&location
.string
, sizeof(location
));
3776 bash_input
.location
= location
;
3778 bash_input
.getter
= get
;
3779 bash_input
.ungetter
= unget
;
3785 return (bash_input
.name
? bash_input
.name
: "stdin");
3788 /* Call this to get the next character of input. */
3792 return (*(bash_input
.getter
)) ();
3795 /* Call this to unget C. That is, to make C the next character
3801 return (*(bash_input
.ungetter
)) (c
);
3804 #if defined (BUFFERED_INPUT)
3805 #ifdef INCLUDE_UNUSED
3807 input_file_descriptor ()
3809 switch (bash_input
.type
)
3812 return (fileno (bash_input
.location
.file
));
3814 return (bash_input
.location
.buffered_fd
);
3817 return (fileno (stdin
));
3821 #endif /* BUFFERED_INPUT */
3823 /* **************************************************************** */
3825 /* Let input be read from readline (). */
3827 /* **************************************************************** */
3829 #if defined (READLINE)
3830 char *current_readline_prompt
= (char *)NULL
;
3831 char *current_readline_line
= (char *)NULL
;
3832 int current_readline_line_index
= 0;
3837 SigHandler
*old_sigint
;
3841 if (current_readline_line
== 0)
3843 if (bash_readline_initialized
== 0)
3844 initialize_readline ();
3846 #if defined (JOB_CONTROL)
3848 give_terminal_to (shell_pgrp
, 0);
3849 #endif /* JOB_CONTROL */
3851 old_sigint
= IMPOSSIBLE_TRAP_HANDLER
;
3852 if (signal_is_ignored (SIGINT
) == 0)
3854 old_sigint
= (SigHandler
*)set_signal_handler (SIGINT
, sigint_sighandler
);
3857 sh_unset_nodelay_mode (fileno (rl_instream
)); /* just in case */
3858 current_readline_line
= readline (current_readline_prompt
?
3859 current_readline_prompt
: "");
3862 if (signal_is_ignored (SIGINT
) == 0)
3864 if (old_sigint
!= IMPOSSIBLE_TRAP_HANDLER
)
3865 set_signal_handler (SIGINT
, old_sigint
);
3869 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3870 reset_readline_prompt ();
3873 if (current_readline_line
== 0)
3876 current_readline_line_index
= 0;
3877 line_len
= strlen (current_readline_line
);
3879 current_readline_line
= (char *)xrealloc (current_readline_line
, 2 + line_len
);
3880 current_readline_line
[line_len
++] = '\n';
3881 current_readline_line
[line_len
] = '\0';
3884 if (current_readline_line
[current_readline_line_index
] == 0)
3886 free (current_readline_line
);
3887 current_readline_line
= (char *)NULL
;
3888 return (yy_readline_get ());
3892 c
= current_readline_line
[current_readline_line_index
++];
3898 yy_readline_unget (c
)
3901 if (current_readline_line_index
&& current_readline_line
)
3902 current_readline_line
[--current_readline_line_index
] = c
;
3907 with_input_from_stdin ()
3909 INPUT_STREAM location
;
3911 if (bash_input
.type
!= st_stdin
&& stream_on_stack (st_stdin
) == 0)
3913 location
.string
= current_readline_line
;
3914 init_yy_io (yy_readline_get
, yy_readline_unget
,
3915 st_stdin
, "readline stdin", location
);
3919 /* Will we be collecting another input line and printing a prompt? This uses
3920 different conditions than SHOULD_PROMPT(), since readline allows a user to
3921 embed a newline in the middle of the line it collects, which the parser
3922 will interpret as a line break and command delimiter. */
3924 parser_will_prompt ()
3926 return (current_readline_line
== 0 || current_readline_line
[current_readline_line_index
] == 0);
3929 #else /* !READLINE */
3932 with_input_from_stdin ()
3934 with_input_from_stream (stdin
, "stdin");
3936 #endif /* !READLINE */
3938 /* **************************************************************** */
3940 /* Let input come from STRING. STRING is zero terminated. */
3942 /* **************************************************************** */
3947 register char *string
;
3948 register unsigned char c
;
3950 string
= bash_input
.location
.string
;
3952 /* If the string doesn't exist, or is empty, EOF found. */
3953 if (string
&& *string
)
3956 bash_input
.location
.string
= string
;
3967 *(--bash_input
.location
.string
) = c
;
3972 with_input_from_string (string
, name
)
3976 INPUT_STREAM location
;
3978 location
.string
= string
;
3979 init_yy_io (yy_string_get
, yy_string_unget
, st_string
, name
, location
);
3982 /* Count the number of characters we've consumed from bash_input.location.string
3983 and read into shell_input_line, but have not returned from shell_getc.
3984 That is the true input location. Rewind bash_input.location.string by
3985 that number of characters, so it points to the last character actually
3986 consumed by the parser. */
3988 rewind_input_string ()
3992 /* number of unconsumed characters in the input -- XXX need to take newlines
3993 into account, e.g., $(...\n) */
3994 xchars
= shell_input_line_len
- shell_input_line_index
;
3995 if (bash_input
.location
.string
[-1] == '\n')
3998 /* XXX - how to reflect bash_input.location.string back to string passed to
3999 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
4000 far into the string we parsed. parse_and_execute knows where bash_input.
4001 location.string is, and how far from orig_string that is -- that's the
4002 number of characters the command consumed. */
4004 /* bash_input.location.string - xchars should be where we parsed to */
4005 /* need to do more validation on xchars value for sanity -- test cases. */
4006 bash_input
.location
.string
-= xchars
;
4009 /* **************************************************************** */
4011 /* Let input come from STREAM. */
4013 /* **************************************************************** */
4015 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
4016 define, and just use getc/ungetc if it was defined, but since bash
4017 installs most of its signal handlers without the SA_RESTART flag, some
4018 signals received during a read(2) will not cause the read to be restarted.
4019 We will need to restart it ourselves. */
4027 if (bash_input
.location
.file
)
4029 /* XXX - don't need terminate_immediately; getc_with_restart checks
4030 for terminating signals itself if read returns < 0 */
4031 result
= getc_with_restart (bash_input
.location
.file
);
4040 return (ungetc_with_restart (c
, bash_input
.location
.file
));
4044 with_input_from_stream (stream
, name
)
4048 INPUT_STREAM location
;
4050 location
.file
= stream
;
4051 init_yy_io (yy_stream_get
, yy_stream_unget
, st_stream
, name
, location
);
4054 typedef struct stream_saver
{
4055 struct stream_saver
*next
;
4056 BASH_INPUT bash_input
;
4058 #if defined (BUFFERED_INPUT)
4059 BUFFERED_STREAM
*bstream
;
4060 #endif /* BUFFERED_INPUT */
4063 /* The globally known line number. */
4064 int line_number
= 0;
4066 /* The line number offset set by assigning to LINENO. Not currently used. */
4067 int line_number_base
= 0;
4069 #if defined (COND_COMMAND)
4070 static int cond_lineno
;
4071 static int cond_token
;
4074 STREAM_SAVER
*stream_list
= (STREAM_SAVER
*)NULL
;
4077 push_stream (reset_lineno
)
4080 STREAM_SAVER
*saver
= (STREAM_SAVER
*)xmalloc (sizeof (STREAM_SAVER
));
4082 xbcopy ((char *)&bash_input
, (char *)&(saver
->bash_input
), sizeof (BASH_INPUT
));
4084 #if defined (BUFFERED_INPUT)
4085 saver
->bstream
= (BUFFERED_STREAM
*)NULL
;
4086 /* If we have a buffered stream, clear out buffers[fd]. */
4087 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4088 saver
->bstream
= set_buffered_stream (bash_input
.location
.buffered_fd
,
4089 (BUFFERED_STREAM
*)NULL
);
4090 #endif /* BUFFERED_INPUT */
4092 saver
->line
= line_number
;
4093 bash_input
.name
= (char *)NULL
;
4094 saver
->next
= stream_list
;
4095 stream_list
= saver
;
4108 STREAM_SAVER
*saver
= stream_list
;
4111 stream_list
= stream_list
->next
;
4113 init_yy_io (saver
->bash_input
.getter
,
4114 saver
->bash_input
.ungetter
,
4115 saver
->bash_input
.type
,
4116 saver
->bash_input
.name
,
4117 saver
->bash_input
.location
);
4119 #if defined (BUFFERED_INPUT)
4120 /* If we have a buffered stream, restore buffers[fd]. */
4121 /* If the input file descriptor was changed while this was on the
4122 save stack, update the buffered fd to the new file descriptor and
4123 re-establish the buffer <-> bash_input fd correspondence. */
4124 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4126 if (bash_input_fd_changed
)
4128 bash_input_fd_changed
= 0;
4129 if (default_buffered_input
>= 0)
4131 bash_input
.location
.buffered_fd
= default_buffered_input
;
4132 saver
->bstream
->b_fd
= default_buffered_input
;
4133 SET_CLOSE_ON_EXEC (default_buffered_input
);
4136 /* XXX could free buffered stream returned as result here. */
4137 set_buffered_stream (bash_input
.location
.buffered_fd
, saver
->bstream
);
4139 #endif /* BUFFERED_INPUT */
4141 line_number
= saver
->line
;
4143 FREE (saver
->bash_input
.name
);
4148 /* Return 1 if a stream of type TYPE is saved on the stack. */
4150 stream_on_stack (type
)
4151 enum stream_type type
;
4153 register STREAM_SAVER
*s
;
4155 for (s
= stream_list
; s
; s
= s
->next
)
4156 if (s
->bash_input
.type
== type
)
4161 /* Save the current token state and return it in a malloced array. */
4167 ret
= (int *)xmalloc (4 * sizeof (int));
4168 ret
[0] = last_read_token
;
4169 ret
[1] = token_before_that
;
4170 ret
[2] = two_tokens_ago
;
4171 ret
[3] = current_token
;
4176 restore_token_state (ts
)
4181 last_read_token
= ts
[0];
4182 token_before_that
= ts
[1];
4183 two_tokens_ago
= ts
[2];
4184 current_token
= ts
[3];
4188 * This is used to inhibit alias expansion and reserved word recognition
4189 * inside case statement pattern lists. A `case statement pattern list' is:
4191 * everything between the `in' in a `case word in' and the next ')'
4193 * everything between a `;;' and the next `)' or `esac'
4196 #define END_OF_ALIAS 0
4199 * Pseudo-global variables used in implementing token-wise alias expansion.
4203 * Pushing and popping strings. This works together with shell_getc to
4204 * implement alias expansion on a per-token basis.
4207 #define PSH_ALIAS 0x01
4208 #define PSH_DPAREN 0x02
4209 #define PSH_SOURCE 0x04
4210 #define PSH_ARRAY 0x08
4212 typedef struct string_saver
{
4213 struct string_saver
*next
;
4214 int expand_alias
; /* Value to set expand_alias to when string is popped. */
4217 alias_t
*expander
; /* alias that caused this line to be pushed. */
4219 size_t saved_line_size
, saved_line_index
, saved_line_len
;
4220 int saved_line_terminator
;
4224 STRING_SAVER
*pushed_string_list
= (STRING_SAVER
*)NULL
;
4227 * Push the current shell_input_line onto a stack of such lines and make S
4228 * the current input. Used when expanding aliases. EXPAND is used to set
4229 * the value of expand_next_token when the string is popped, so that the
4230 * word after the alias in the original line is handled correctly when the
4231 * alias expands to multiple words. TOKEN is the token that was expanded
4232 * into S; it is saved and used to prevent infinite recursive expansion.
4235 push_string (s
, expand
, ap
)
4240 STRING_SAVER
*temp
= (STRING_SAVER
*)xmalloc (sizeof (STRING_SAVER
));
4242 temp
->expand_alias
= expand
;
4243 temp
->saved_line
= shell_input_line
;
4244 temp
->saved_line_size
= shell_input_line_size
;
4245 temp
->saved_line_len
= shell_input_line_len
;
4246 temp
->saved_line_index
= shell_input_line_index
;
4247 temp
->saved_line_terminator
= shell_input_line_terminator
;
4250 temp
->expander
= ap
;
4252 temp
->flags
= PSH_ALIAS
;
4254 temp
->next
= pushed_string_list
;
4255 pushed_string_list
= temp
;
4259 ap
->flags
|= AL_BEINGEXPANDED
;
4262 shell_input_line
= s
;
4263 shell_input_line_size
= shell_input_line_len
= STRLEN (s
);
4264 shell_input_line_index
= 0;
4265 shell_input_line_terminator
= '\0';
4267 parser_state
&= ~PST_ALEXPNEXT
; /* XXX */
4270 set_line_mbstate ();
4274 * Make the top of the pushed_string stack be the current shell input.
4275 * Only called when there is something on the stack. Called from shell_getc
4276 * when it thinks it has consumed the string generated by an alias expansion
4277 * and needs to return to the original input line.
4284 FREE (shell_input_line
);
4285 shell_input_line
= pushed_string_list
->saved_line
;
4286 shell_input_line_index
= pushed_string_list
->saved_line_index
;
4287 shell_input_line_size
= pushed_string_list
->saved_line_size
;
4288 shell_input_line_len
= pushed_string_list
->saved_line_len
;
4289 shell_input_line_terminator
= pushed_string_list
->saved_line_terminator
;
4292 if (pushed_string_list
->expand_alias
)
4293 parser_state
|= PST_ALEXPNEXT
;
4295 parser_state
&= ~PST_ALEXPNEXT
;
4298 t
= pushed_string_list
;
4299 pushed_string_list
= pushed_string_list
->next
;
4303 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4308 set_line_mbstate ();
4314 register STRING_SAVER
*t
, *t1
;
4316 for (t
= pushed_string_list
; t
; )
4319 FREE (t
->saved_line
);
4322 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4327 pushed_string_list
= (STRING_SAVER
*)NULL
;
4331 free_pushed_string_input ()
4333 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4334 free_string_list ();
4339 parser_expanding_alias ()
4341 return (expanding_alias ());
4345 parser_save_alias ()
4347 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4348 push_string ((char *)NULL
, 0, (alias_t
*)NULL
);
4349 pushed_string_list
->flags
= PSH_SOURCE
; /* XXX - for now */
4356 parser_restore_alias ()
4358 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4359 if (pushed_string_list
)
4367 /* Before freeing AP, make sure that there aren't any cases of pointer
4368 aliasing that could cause us to reference freed memory later on. */
4370 clear_string_list_expander (ap
)
4373 register STRING_SAVER
*t
;
4375 for (t
= pushed_string_list
; t
; t
= t
->next
)
4377 if (t
->expander
&& t
->expander
== ap
)
4384 clear_shell_input_line ()
4386 if (shell_input_line
)
4387 shell_input_line
[shell_input_line_index
= 0] = '\0';
4390 /* Return a line of text, taken from wherever yylex () reads input.
4391 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4392 is non-zero, we remove unquoted \<newline> pairs. This is used by
4393 read_secondary_line to read here documents. */
4395 read_a_line (remove_quoted_newline
)
4396 int remove_quoted_newline
;
4398 static char *line_buffer
= (char *)NULL
;
4399 static int buffer_size
= 0;
4400 int indx
, c
, peekc
, pass_next
;
4402 #if defined (READLINE)
4403 if (no_line_editing
&& SHOULD_PROMPT ())
4405 if (SHOULD_PROMPT ())
4409 pass_next
= indx
= 0;
4412 /* Allow immediate exit if interrupted during input. */
4417 /* Ignore null bytes in input. */
4421 /* If there is no more input, then we return NULL. */
4424 if (interactive
&& bash_input
.type
== st_stream
)
4427 return ((char *)NULL
);
4431 /* `+2' in case the final character in the buffer is a newline or we
4432 have to handle CTLESC or CTLNUL. */
4433 RESIZE_MALLOCED_BUFFER (line_buffer
, indx
, 2, buffer_size
, 128);
4435 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4436 here document with an unquoted delimiter. In this case,
4437 the line will be expanded as if it were in double quotes.
4438 We allow a backslash to escape the next character, but we
4439 need to treat the backslash specially only if a backslash
4440 quoting a backslash-newline pair appears in the line. */
4443 line_buffer
[indx
++] = c
;
4446 else if (c
== '\\' && remove_quoted_newline
)
4453 continue; /* Make the unquoted \<newline> pair disappear. */
4459 line_buffer
[indx
++] = c
; /* Preserve the backslash. */
4464 /* remove_quoted_newline is non-zero if the here-document delimiter
4465 is unquoted. In this case, we will be expanding the lines and
4466 need to make sure CTLESC and CTLNUL in the input are quoted. */
4467 if (remove_quoted_newline
&& (c
== CTLESC
|| c
== CTLNUL
))
4468 line_buffer
[indx
++] = CTLESC
;
4469 line_buffer
[indx
++] = c
;
4474 line_buffer
[indx
] = '\0';
4475 return (line_buffer
);
4480 /* Return a line as in read_a_line (), but insure that the prompt is
4481 the secondary prompt. This is used to read the lines of a here
4482 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4483 newlines quoted with backslashes while reading the line. It is
4484 non-zero unless the delimiter of the here document was quoted. */
4486 read_secondary_line (remove_quoted_newline
)
4487 int remove_quoted_newline
;
4492 prompt_string_pointer
= &ps2_prompt
;
4493 if (SHOULD_PROMPT ())
4495 ret
= read_a_line (remove_quoted_newline
);
4496 #if defined (HISTORY)
4497 if (ret
&& remember_on_history
&& (parser_state
& PST_HEREDOC
))
4499 /* To make adding the here-document body right, we need to rely on
4500 history_delimiting_chars() returning \n for the first line of the
4501 here-document body and the null string for the second and subsequent
4502 lines, so we avoid double newlines.
4503 current_command_line_count == 2 for the first line of the body. */
4505 current_command_line_count
++;
4506 maybe_add_history (ret
);
4508 #endif /* HISTORY */
4512 /* **************************************************************** */
4516 /* **************************************************************** */
4518 /* Reserved words. These are only recognized as the first word of a
4520 STRING_INT_ALIST word_token_alist
[] = {
4529 #if defined (SELECT_COMMAND)
4530 { "select", SELECT
},
4537 { "function", FUNCTION
},
4538 #if defined (COMMAND_TIMING)
4544 #if defined (COND_COMMAND)
4545 { "[[", COND_START
},
4548 #if defined (COPROCESS_SUPPORT)
4549 { "coproc", COPROC
},
4554 /* other tokens that can be returned by read_token() */
4555 STRING_INT_ALIST other_token_alist
[] = {
4556 /* Multiple-character tokens with special values */
4561 { ">>", GREATER_GREATER
},
4562 { "<<", LESS_LESS
},
4564 { ">&", GREATER_AND
},
4565 { ";;", SEMI_SEMI
},
4567 { ";;&", SEMI_SEMI_AND
},
4568 { "<<-", LESS_LESS_MINUS
},
4569 { "<<<", LESS_LESS_LESS
},
4570 { "&>", AND_GREATER
},
4571 { "&>>", AND_GREATER_GREATER
},
4572 { "<>", LESS_GREATER
},
4573 { ">|", GREATER_BAR
},
4575 { "EOF", yacc_EOF
},
4576 /* Tokens whose value is the character itself */
4587 { "newline", '\n' },
4591 /* others not listed here:
4592 WORD look at yylval.word
4593 ASSIGNMENT_WORD look at yylval.word
4594 NUMBER look at yylval.number
4595 ARITH_CMD look at yylval.word_list
4596 ARITH_FOR_EXPRS look at yylval.word_list
4597 COND_CMD look at yylval.command
4600 /* These are used by read_token_word, but appear up here so that shell_getc
4601 can use them to decide when to add otherwise blank lines to the history. */
4603 /* The primary delimiter stack. */
4604 struct dstack dstack
= { (char *)NULL
, 0, 0 };
4606 /* A temporary delimiter stack to be used when decoding prompt strings.
4607 This is needed because command substitutions in prompt strings (e.g., PS2)
4608 can screw up the parser's quoting state. */
4609 static struct dstack temp_dstack
= { (char *)NULL
, 0, 0 };
4611 /* Macro for accessing the top delimiter on the stack. Returns the
4612 delimiter or zero if none. */
4613 #define current_delimiter(ds) \
4614 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4616 #define push_delimiter(ds, character) \
4619 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4620 ds.delimiters = (char *)xrealloc \
4621 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4622 ds.delimiters[ds.delimiter_depth] = character; \
4623 ds.delimiter_depth++; \
4627 #define pop_delimiter(ds) ds.delimiter_depth--
4629 /* Return the next shell input character. This always reads characters
4630 from shell_input_line; when that line is exhausted, it is time to
4631 read the next line. This is called by read_token when the shell is
4632 processing normal command input. */
4634 /* This implements one-character lookahead/lookbehind across physical input
4635 lines, to avoid something being lost because it's pushed back with
4636 shell_ungetc when we're at the start of a line. */
4637 static int eol_ungetc_lookahead
= 0;
4639 static int unquoted_backslash
= 0;
4642 shell_getc (remove_quoted_newline
)
4643 int remove_quoted_newline
;
4646 int c
, truncating
, last_was_backslash
;
4651 last_was_backslash
= 0;
4652 if (sigwinch_received
)
4654 sigwinch_received
= 0;
4655 get_new_window_size (0, (int *)0, (int *)0);
4658 if (eol_ungetc_lookahead
)
4660 c
= eol_ungetc_lookahead
;
4661 eol_ungetc_lookahead
= 0;
4665 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4666 /* If shell_input_line[shell_input_line_index] == 0, but there is
4667 something on the pushed list of strings, then we don't want to go
4668 off and get another line. We let the code down below handle it. */
4670 if (!shell_input_line
|| ((!shell_input_line
[shell_input_line_index
]) &&
4671 (pushed_string_list
== (STRING_SAVER
*)NULL
)))
4672 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4673 if (!shell_input_line
|| !shell_input_line
[shell_input_line_index
])
4674 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4678 /* Let's not let one really really long line blow up memory allocation */
4679 if (shell_input_line
&& shell_input_line_size
>= 32768)
4681 free (shell_input_line
);
4682 shell_input_line
= 0;
4683 shell_input_line_size
= 0;
4688 /* Allow immediate exit if interrupted during input. */
4692 shell_input_line_terminator
= 0;
4694 /* If the shell is interactive, but not currently printing a prompt
4695 (interactive_shell && interactive == 0), we don't want to print
4696 notifies or cleanup the jobs -- we want to defer it until we do
4697 print the next prompt. */
4698 if (interactive_shell
== 0 || SHOULD_PROMPT())
4700 #if defined (JOB_CONTROL)
4701 /* This can cause a problem when reading a command as the result
4702 of a trap, when the trap is called from flush_child. This call
4703 had better not cause jobs to disappear from the job table in
4704 that case, or we will have big trouble. */
4705 notify_and_cleanup ();
4706 #else /* !JOB_CONTROL */
4707 cleanup_dead_jobs ();
4708 #endif /* !JOB_CONTROL */
4711 #if defined (READLINE)
4712 if (no_line_editing
&& SHOULD_PROMPT())
4714 if (SHOULD_PROMPT())
4718 if (bash_input
.type
== st_stream
)
4725 /* Allow immediate exit if interrupted during input. */
4730 /* If we get EOS while parsing a string, treat it as EOF so we
4731 don't just keep looping. Happens very rarely */
4732 if (bash_input
.type
== st_string
)
4735 shell_input_line_terminator
= EOF
;
4736 shell_input_line
[i
] = '\0';
4743 /* Theoretical overflow */
4744 /* If we can't put 256 bytes more into the buffer, allocate
4745 everything we can and fill it as full as we can. */
4746 /* XXX - we ignore rest of line using `truncating' flag */
4747 if (shell_input_line_size
> (SIZE_MAX
- 256))
4751 n
= SIZE_MAX
- i
; /* how much more can we put into the buffer? */
4752 if (n
<= 2) /* we have to save 1 for the newline added below */
4754 if (truncating
== 0)
4755 internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size
, (unsigned long)SIZE_MAX
);
4756 shell_input_line
[i
] = '\0';
4759 if (shell_input_line_size
< SIZE_MAX
)
4761 shell_input_line_size
= SIZE_MAX
;
4762 shell_input_line
= xrealloc (shell_input_line
, shell_input_line_size
);
4766 RESIZE_MALLOCED_BUFFER (shell_input_line
, i
, 2, shell_input_line_size
, 256);
4770 if (bash_input
.type
== st_stream
)
4774 shell_input_line_terminator
= EOF
;
4776 shell_input_line
[i
] = '\0';
4780 if (truncating
== 0 || c
== '\n')
4781 shell_input_line
[i
++] = c
;
4785 shell_input_line
[--i
] = '\0';
4786 current_command_line_count
++;
4790 last_was_backslash
= last_was_backslash
== 0 && c
== '\\';
4793 shell_input_line_index
= 0;
4794 shell_input_line_len
= i
; /* == strlen (shell_input_line) */
4796 set_line_mbstate ();
4798 #if defined (HISTORY)
4799 if (remember_on_history
&& shell_input_line
&& shell_input_line
[0])
4802 # if defined (BANG_HISTORY)
4803 /* If the current delimiter is a single quote, we should not be
4804 performing history expansion, even if we're on a different
4805 line from the original single quote. */
4806 if (current_delimiter (dstack
) == '\'')
4807 history_quoting_state
= '\'';
4808 else if (current_delimiter (dstack
) == '"')
4809 history_quoting_state
= '"';
4811 history_quoting_state
= 0;
4813 /* Calling with a third argument of 1 allows remember_on_history to
4814 determine whether or not the line is saved to the history list */
4815 expansions
= pre_process_line (shell_input_line
, 1, 1);
4816 # if defined (BANG_HISTORY)
4817 history_quoting_state
= 0;
4819 if (expansions
!= shell_input_line
)
4821 free (shell_input_line
);
4822 shell_input_line
= expansions
;
4823 shell_input_line_len
= shell_input_line
?
4824 strlen (shell_input_line
) : 0;
4825 if (shell_input_line_len
== 0)
4826 current_command_line_count
--;
4828 /* We have to force the xrealloc below because we don't know
4829 the true allocated size of shell_input_line anymore. */
4830 shell_input_line_size
= shell_input_line_len
;
4832 set_line_mbstate ();
4835 /* Try to do something intelligent with blank lines encountered while
4836 entering multi-line commands. XXX - this is grotesque */
4837 else if (remember_on_history
&& shell_input_line
&&
4838 shell_input_line
[0] == '\0' &&
4839 current_command_line_count
> 1)
4841 if (current_delimiter (dstack
))
4842 /* We know shell_input_line[0] == 0 and we're reading some sort of
4843 quoted string. This means we've got a line consisting of only
4844 a newline in a quoted string. We want to make sure this line
4845 gets added to the history. */
4846 maybe_add_history (shell_input_line
);
4850 hdcs
= history_delimiting_chars (shell_input_line
);
4851 if (hdcs
&& hdcs
[0] == ';')
4852 maybe_add_history (shell_input_line
);
4856 #endif /* HISTORY */
4858 if (shell_input_line
)
4860 /* Lines that signify the end of the shell's input should not be
4861 echoed. We should not echo lines while parsing command
4862 substitutions with recursive calls into the parsing engine; those
4863 should only be echoed once when we read the word. That is the
4864 reason for the test against shell_eof_token, which is set to a
4865 right paren when parsing the contents of command substitutions. */
4866 if (echo_input_at_read
&& (shell_input_line
[0] ||
4867 shell_input_line_terminator
!= EOF
) &&
4868 shell_eof_token
== 0)
4869 fprintf (stderr
, "%s\n", shell_input_line
);
4873 shell_input_line_size
= 0;
4874 prompt_string_pointer
= ¤t_prompt_string
;
4875 if (SHOULD_PROMPT ())
4880 /* Add the newline to the end of this string, iff the string does
4881 not already end in an EOF character. */
4882 if (shell_input_line_terminator
!= EOF
)
4884 if (shell_input_line_size
< SIZE_MAX
-3 && (shell_input_line_len
+3 > shell_input_line_size
))
4885 shell_input_line
= (char *)xrealloc (shell_input_line
,
4886 1 + (shell_input_line_size
+= 2));
4888 /* Don't add a newline to a string that ends with a backslash if we're
4889 going to be removing quoted newlines, since that will eat the
4890 backslash. Add another backslash instead (will be removed by
4892 if (bash_input
.type
== st_string
&& expanding_alias() == 0 && last_was_backslash
&& c
== EOF
&& remove_quoted_newline
)
4893 shell_input_line
[shell_input_line_len
] = '\\';
4895 shell_input_line
[shell_input_line_len
] = '\n';
4896 shell_input_line
[shell_input_line_len
+ 1] = '\0';
4898 #if defined (HANDLE_MULTIBYTE)
4899 /* This is kind of an abstraction violation, but there's no need to
4900 go through the entire shell_input_line again with a call to
4901 set_line_mbstate(). */
4902 EXTEND_SHELL_INPUT_LINE_PROPERTY();
4903 shell_input_line_property
[shell_input_line_len
] = 1;
4909 if (shell_input_line_index
== 0)
4910 unquoted_backslash
= 0;
4912 uc
= shell_input_line
[shell_input_line_index
];
4916 unquoted_backslash
= unquoted_backslash
== 0 && uc
== '\\';
4917 shell_input_line_index
++;
4920 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4921 /* If UC is NULL, we have reached the end of the current input string. If
4922 pushed_string_list is non-empty, it's time to pop to the previous string
4923 because we have fully consumed the result of the last alias expansion.
4924 Do it transparently; just return the next character of the string popped
4926 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4927 currently tested) and the flags value is not PSH_SOURCE, we are not
4928 parsing an alias, we have just saved one (push_string, when called by
4929 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4930 case is handled below. */
4932 /* If we're at the end of an alias expansion add a space to make sure that
4933 the alias remains marked as being in use while we expand its last word.
4934 This makes sure that pop_string doesn't mark the alias as not in use
4935 before the string resulting from the alias expansion is tokenized and
4936 checked for alias expansion, preventing recursion. At this point, the
4937 last character in shell_input_line is the last character of the alias
4938 expansion. We test that last character to determine whether or not to
4939 return the space that will delimit the token and postpone the pop_string.
4940 This set of conditions duplicates what used to be in mk_alexpansion ()
4941 below, with the addition that we don't add a space if we're currently
4942 reading a quoted string or in a shell comment. */
4943 #ifndef OLD_ALIAS_HACK
4944 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
&&
4945 pushed_string_list
->flags
!= PSH_DPAREN
&&
4946 (parser_state
& PST_COMMENT
) == 0 &&
4947 (parser_state
& PST_ENDALIAS
) == 0 && /* only once */
4948 shell_input_line_index
> 0 &&
4949 shellblank (shell_input_line
[shell_input_line_index
-1]) == 0 &&
4950 shell_input_line
[shell_input_line_index
-1] != '\n' &&
4951 unquoted_backslash
== 0 &&
4952 shellmeta (shell_input_line
[shell_input_line_index
-1]) == 0 &&
4953 (current_delimiter (dstack
) != '\'' && current_delimiter (dstack
) != '"'))
4955 parser_state
|= PST_ENDALIAS
;
4956 /* We need to do this to make sure last_shell_getc_is_singlebyte returns
4957 true, since we are returning a single-byte space. */
4958 if (shell_input_line_index
== shell_input_line_len
&& last_shell_getc_is_singlebyte
== 0)
4961 EXTEND_SHELL_INPUT_LINE_PROPERTY();
4962 shell_input_line_property
[shell_input_line_len
++] = 1;
4963 /* extend shell_input_line to accommodate the shell_ungetc that
4964 read_token_word() will perform, since we're extending the index */
4965 RESIZE_MALLOCED_BUFFER (shell_input_line
, shell_input_line_index
, 2, shell_input_line_size
, 16);
4966 shell_input_line
[++shell_input_line_index
] = '\0'; /* XXX */
4968 shell_input_line_property
[shell_input_line_index
- 1] = 1;
4971 return ' '; /* END_ALIAS */
4976 #endif /* ALIAS || DPAREN_ARITHMETIC */
4977 /* This case works for PSH_DPAREN as well as the shell_ungets() case that uses
4979 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
)
4981 parser_state
&= ~PST_ENDALIAS
;
4983 uc
= shell_input_line
[shell_input_line_index
];
4985 shell_input_line_index
++;
4988 if MBTEST(uc
== '\\' && remove_quoted_newline
&& shell_input_line
[shell_input_line_index
] == '\n')
4990 if (SHOULD_PROMPT ())
4994 /* What do we do here if we're expanding an alias whose definition
4995 includes an escaped newline? If that's the last character in the
4996 alias expansion, we just pop the pushed string list (recall that
4997 we inhibit the appending of a space if newline is the last
4998 character). If it's not the last character, we need to consume the
4999 quoted newline and move to the next character in the expansion. */
5001 if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] == '\0')
5006 else if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] != '\0')
5008 shell_input_line_index
++; /* skip newline */
5009 goto next_alias_char
; /* and get next character */
5016 if (uc
== 0 && shell_input_line_terminator
== EOF
)
5017 return ((shell_input_line_index
!= 0) ? '\n' : EOF
);
5019 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5020 /* We already know that we are not parsing an alias expansion because of the
5021 check for expanding_alias() above. This knows how parse_and_execute
5022 handles switching to st_string input while an alias is being expanded,
5023 hence the check for pushed_string_list without pushed_string_list->expander
5024 and the check for PSH_SOURCE as pushed_string_list->flags.
5025 parse_and_execute and parse_string both change the input type to st_string
5026 and place the string to be parsed and executed into location.string, so
5027 we should not stop reading that until the pointer is '\0'.
5028 The check for shell_input_line_terminator may be superfluous.
5030 This solves the problem of `.' inside a multi-line alias with embedded
5031 newlines executing things out of order. */
5032 if (uc
== 0 && bash_input
.type
== st_string
&& *bash_input
.location
.string
&&
5033 pushed_string_list
&& pushed_string_list
->flags
== PSH_SOURCE
&&
5034 shell_input_line_terminator
== 0)
5036 shell_input_line_index
= 0;
5044 /* Put C back into the input for the shell. This might need changes for
5045 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
5046 character different than we read, shell_input_line_property doesn't need
5047 to change when manipulating shell_input_line. The define for
5048 last_shell_getc_is_singlebyte should take care of it, though. */
5053 if (shell_input_line
&& shell_input_line_index
)
5054 shell_input_line
[--shell_input_line_index
] = c
;
5056 eol_ungetc_lookahead
= c
;
5059 /* Push S back into shell_input_line; updating shell_input_line_index */
5064 size_t slen
, chars_left
;
5068 if (shell_input_line
[shell_input_line_index
] == '\0')
5070 /* Easy, just overwrite shell_input_line. This is preferred because it
5071 saves on set_line_mbstate () and other overhead like push_string */
5072 if (shell_input_line_size
<= slen
)
5073 RESIZE_MALLOCED_BUFFER (shell_input_line
, shell_input_line_index
, slen
+ 1, shell_input_line_size
, 64);
5074 strcpy (shell_input_line
, s
);
5075 shell_input_line_index
= 0;
5076 shell_input_line_len
= slen
;
5077 shell_input_line_terminator
= 0;
5079 else if (shell_input_line_index
>= slen
)
5081 /* Just as easy, just back up shell_input_line_index, but it means we
5082 will re-process some characters in set_line_mbstate(). Need to
5083 watch pushing back newlines here. */
5085 shell_input_line
[--shell_input_line_index
] = s
[--slen
];
5087 else if (s
[slen
- 1] == '\n')
5089 push_string (savestring (s
), 0, (alias_t
*)NULL
);
5090 /* push_string does set_line_mbstate () */
5095 /* Harder case: pushing back input string that's longer than what we've
5096 consumed from shell_input_line so far. */
5097 INTERNAL_DEBUG (("shell_ungets: not at end of shell_input_line"));
5099 chars_left
= shell_input_line_len
- shell_input_line_index
;
5100 if (shell_input_line_size
<= (slen
+ chars_left
))
5101 RESIZE_MALLOCED_BUFFER (shell_input_line
, shell_input_line_index
, chars_left
+ slen
+ 1, shell_input_line_size
, 64);
5102 memmove (shell_input_line
+ slen
, shell_input_line
+ shell_input_line_index
, shell_input_line_len
- shell_input_line_index
);
5103 strcpy (shell_input_line
, s
);
5104 shell_input_line_index
= 0;
5105 shell_input_line_len
= strlen (shell_input_line
); /* chars_left + slen? */
5108 #if defined (HANDLE_MULTIBYTE)
5109 set_line_mbstate (); /* XXX */
5114 parser_remaining_input ()
5116 if (shell_input_line
== 0)
5118 if ((int)shell_input_line_index
< 0 || shell_input_line_index
>= shell_input_line_len
)
5119 return ""; /* XXX */
5120 return (shell_input_line
+ shell_input_line_index
);
5123 #ifdef INCLUDE_UNUSED
5124 /* Back the input pointer up by one, effectively `ungetting' a character. */
5128 if (shell_input_line
&& shell_input_line_index
)
5129 shell_input_line_index
--;
5133 /* Discard input until CHARACTER is seen, then push that character back
5134 onto the input stream. */
5136 discard_until (character
)
5141 while ((c
= shell_getc (0)) != EOF
&& c
!= character
)
5149 execute_variable_command (command
, vname
)
5150 char *command
, *vname
;
5153 sh_parser_state_t ps
;
5155 save_parser_state (&ps
);
5156 last_lastarg
= get_string_value ("_");
5158 last_lastarg
= savestring (last_lastarg
);
5160 parse_and_execute (savestring (command
), vname
, SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOOPTIMIZE
);
5162 restore_parser_state (&ps
);
5163 bind_variable ("_", last_lastarg
, 0);
5164 FREE (last_lastarg
);
5166 if (token_to_read
== '\n') /* reset_parser was called */
5174 two_tokens_ago
= token_before_that
;
5175 token_before_that
= last_read_token
;
5176 last_read_token
= current_token
;
5181 /* Place to remember the token. We try to keep the buffer
5182 at a reasonable size, but it can grow. */
5183 static char *token
= (char *)NULL
;
5185 /* Current size of the token buffer. */
5186 static size_t token_buffer_size
;
5188 /* Command to read_token () explaining what we want it to do. */
5191 #define prompt_is_ps1 \
5192 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
5194 /* Function for yyparse to call. yylex keeps track of
5195 the last two tokens read, and calls read_token. */
5199 if (interactive
&& (current_token
== 0 || current_token
== '\n'))
5201 /* Before we print a prompt, we might have to check mailboxes.
5202 We do this only if it is time to do so. Notice that only here
5203 is the mail alarm reset; nothing takes place in check_mail ()
5204 except the checking of mail. Please don't change this. */
5205 if (prompt_is_ps1
&& parse_and_execute_level
== 0 && time_to_check_mail ())
5208 reset_mail_timer ();
5211 /* Avoid printing a prompt if we're not going to read anything, e.g.
5212 after resetting the parser with read_token (RESET). */
5213 if (token_to_read
== 0 && SHOULD_PROMPT ())
5217 two_tokens_ago
= token_before_that
;
5218 token_before_that
= last_read_token
;
5219 last_read_token
= current_token
;
5220 current_token
= read_token (READ
);
5222 if ((parser_state
& PST_EOFTOKEN
) && current_token
== shell_eof_token
)
5224 /* placeholder for any special handling. */
5225 return (current_token
);
5228 if (current_token
< 0)
5229 #if defined (YYERRCODE) && !defined (YYUNDEF)
5230 current_token
= EOF_Reached
? YYEOF
: YYERRCODE
;
5232 current_token
= EOF_Reached
? YYEOF
: YYUNDEF
;
5235 return (current_token
);
5238 /* When non-zero, we have read the required tokens
5239 which allow ESAC to be the next one read. */
5240 static int esacs_needed_count
;
5242 /* When non-zero, we can read IN as an acceptable token, regardless of how
5243 many newlines we read. */
5244 static int expecting_in_token
;
5250 if (need_here_doc
>= HEREDOC_MAX
)
5252 last_command_exit_value
= EX_BADUSAGE
;
5254 report_syntax_error (_("maximum here-document count exceeded"));
5256 exit_shell (last_command_exit_value
);
5258 redir_stack
[need_here_doc
++] = r
;
5262 gather_here_documents ()
5267 here_doc_first_line
= 1;
5268 while (need_here_doc
> 0)
5270 parser_state
|= PST_HEREDOC
;
5271 make_here_document (redir_stack
[r
++], line_number
);
5272 parser_state
&= ~PST_HEREDOC
;
5274 redir_stack
[r
- 1] = 0; /* XXX */
5276 here_doc_first_line
= 0; /* just in case */
5279 /* When non-zero, an open-brace used to create a group is awaiting a close
5281 static int open_brace_count
;
5283 /* In the following three macros, `token' is always last_read_token */
5285 /* Are we in the middle of parsing a redirection where we are about to read
5286 a word? This is used to make sure alias expansion doesn't happen in the
5287 middle of a redirection, even though we're parsing a simple command. */
5288 #define parsing_redirection(token) \
5289 (token == '<' || token == '>' || \
5290 token == GREATER_GREATER || token == GREATER_BAR || \
5291 token == LESS_GREATER || token == LESS_LESS_MINUS || \
5292 token == LESS_LESS || token == LESS_LESS_LESS || \
5293 token == LESS_AND || token == GREATER_AND || token == AND_GREATER)
5295 /* Is `token' one that will allow a WORD to be read in a command position?
5296 We can read a simple command name on which we should attempt alias expansion
5297 or we can read an assignment statement. */
5298 #define command_token_position(token) \
5299 (((token) == ASSIGNMENT_WORD) || \
5300 ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \
5301 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
5303 /* Are we in a position where we can read an assignment statement? */
5304 #define assignment_acceptable(token) \
5305 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
5307 /* Check to see if TOKEN is a reserved word and return the token
5309 #define CHECK_FOR_RESERVED_WORD(tok) \
5311 if (!dollar_present && !quoted && \
5312 reserved_word_acceptable (last_read_token)) \
5315 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5316 if (STREQ (tok, word_token_alist[i].word)) \
5318 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
5320 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
5322 if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \
5323 break; /* Posix grammar rule 4 */ \
5324 if ((parser_state & PST_CASEPAT) && last_read_token == '(' && word_token_alist[i].token == ESAC) /*)*/ \
5325 break; /* phantom Posix grammar rule 4 */ \
5326 if (word_token_alist[i].token == ESAC) { \
5327 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5328 esacs_needed_count--; \
5329 } else if (word_token_alist[i].token == CASE) \
5330 parser_state |= PST_CASESTMT; \
5331 else if (word_token_alist[i].token == COND_END) \
5332 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5333 else if (word_token_alist[i].token == COND_START) \
5334 parser_state |= PST_CONDCMD; \
5335 else if (word_token_alist[i].token == '{') \
5336 open_brace_count++; \
5337 else if (word_token_alist[i].token == '}' && open_brace_count) \
5338 open_brace_count--; \
5339 return (word_token_alist[i].token); \
5346 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5349 It is eligible for expansion if EXPAND_ALIASES is set, and
5350 the token is unquoted and the last token read was a command
5351 separator (or expand_next_token is set), and we are currently
5352 processing an alias (pushed_string_list is non-empty) and this
5353 token is not the same as the current or any previously
5356 Special cases that disqualify:
5357 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
5367 r
= xmalloc (l
+ 2);
5369 #ifdef OLD_ALIAS_HACK
5370 /* If the last character in the alias is a newline, don't add a trailing
5371 space to the expansion. Works with shell_getc above. */
5372 /* Need to do something about the case where the alias expansion contains
5373 an unmatched quoted string, since appending this space affects the
5374 subsequent output. */
5375 if (l
> 0 && r
[l
- 1] != ' ' && r
[l
- 1] != '\n' && shellmeta(r
[l
- 1]) == 0)
5383 alias_expand_token (tokstr
)
5390 if (((parser_state
& PST_ALEXPNEXT
) || command_token_position (last_read_token
)) &&
5391 (parser_state
& PST_CASEPAT
) == 0)
5393 if ((parser_state
& PST_ALEXPNEXT
) || assignment_acceptable (last_read_token
))
5396 ap
= find_alias (tokstr
);
5398 /* Currently expanding this token. */
5399 if (ap
&& (ap
->flags
& AL_BEINGEXPANDED
))
5400 return (NO_EXPANSION
);
5402 #ifdef OLD_ALIAS_HACK
5403 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5404 so the lookahead by the parser works right (the alias needs to remain
5405 `in use' while parsing its last word to avoid alias recursion for
5406 something like "alias echo=echo"). If this gets changed, make sure
5407 the code in shell_getc that deals with reaching the end of an
5408 expanded alias is changed with it. */
5410 expanded
= ap
? mk_alexpansion (ap
->value
) : (char *)NULL
;
5414 push_string (expanded
, ap
->flags
& AL_EXPANDNEXT
, ap
);
5415 return (RE_READ_TOKEN
);
5418 /* This is an eligible token that does not have an expansion. */
5419 return (NO_EXPANSION
);
5421 return (NO_EXPANSION
);
5426 time_command_acceptable ()
5428 #if defined (COMMAND_TIMING)
5431 if (posixly_correct
&& shell_compatibility_level
> 41)
5433 /* Quick check of the rest of the line to find the next token. If it
5434 begins with a `-', Posix says to not return `time' as the token.
5435 This was interp 267. */
5436 i
= shell_input_line_index
;
5437 while (i
< shell_input_line_len
&& (shell_input_line
[i
] == ' ' || shell_input_line
[i
] == '\t'))
5439 if (shell_input_line
[i
] == '-')
5443 switch (last_read_token
)
5448 if (token_before_that
== '|')
5463 case ')': /* only valid in case statement */
5464 case BANG
: /* ! time pipeline */
5465 case TIME
: /* time time pipeline */
5466 case TIMEOPT
: /* time -p time pipeline */
5467 case TIMEIGN
: /* time -p -- ... */
5475 #endif /* COMMAND_TIMING */
5478 /* Handle special cases of token recognition:
5479 IN is recognized if the last token was WORD and the token
5480 before that was FOR or CASE or SELECT.
5482 DO is recognized if the last token was WORD and the token
5483 before that was FOR or SELECT.
5485 ESAC is recognized if the last token caused `esacs_needed_count'
5488 `{' is recognized if the last token as WORD and the token
5489 before that was FUNCTION, or if we just parsed an arithmetic
5492 `}' is recognized if there is an unclosed `{' present.
5494 `-p' is returned as TIMEOPT if the last read token was TIME.
5495 `--' is returned as TIMEIGN if the last read token was TIME or TIMEOPT.
5497 ']]' is returned as COND_END if the parser is currently parsing
5498 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5500 `time' is returned as TIME if and only if it is immediately
5501 preceded by one of `;', `\n', `||', `&&', or `&'.
5505 special_case_tokens (tokstr
)
5508 /* Posix grammar rule 6 */
5509 if ((last_read_token
== WORD
) &&
5510 #if defined (SELECT_COMMAND)
5511 ((token_before_that
== FOR
) || (token_before_that
== CASE
) || (token_before_that
== SELECT
)) &&
5513 ((token_before_that
== FOR
) || (token_before_that
== CASE
)) &&
5515 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5517 if (token_before_that
== CASE
)
5519 parser_state
|= PST_CASEPAT
;
5520 esacs_needed_count
++;
5522 if (expecting_in_token
)
5523 expecting_in_token
--;
5527 /* XXX - leaving above code intact for now, but it should eventually be
5528 removed in favor of this clause. */
5529 /* Posix grammar rule 6 */
5530 if (expecting_in_token
&& (last_read_token
== WORD
|| last_read_token
== '\n') &&
5531 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5533 if (parser_state
& PST_CASESTMT
)
5535 parser_state
|= PST_CASEPAT
;
5536 esacs_needed_count
++;
5538 expecting_in_token
--;
5541 /* Posix grammar rule 6, third word in FOR: for i; do command-list; done */
5542 else if (expecting_in_token
&& (last_read_token
== '\n' || last_read_token
== ';') &&
5543 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5545 expecting_in_token
--;
5549 /* for i do; command-list; done */
5550 if (last_read_token
== WORD
&&
5551 #if defined (SELECT_COMMAND)
5552 (token_before_that
== FOR
|| token_before_that
== SELECT
) &&
5554 (token_before_that
== FOR
) &&
5556 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5558 if (expecting_in_token
)
5559 expecting_in_token
--;
5563 /* Ditto for ESAC in the CASE case.
5564 Specifically, this handles "case word in esac", which is a legal
5565 construct, certainly because someone will pass an empty arg to the
5566 case construct, and we don't want it to barf. Of course, we should
5567 insist that the case construct has at least one pattern in it, but
5568 the designers disagree. */
5569 if (esacs_needed_count
)
5571 if (last_read_token
== IN
&& STREQ (tokstr
, "esac"))
5573 esacs_needed_count
--;
5574 parser_state
&= ~PST_CASEPAT
;
5579 /* The start of a shell function definition. */
5580 if (parser_state
& PST_ALLOWOPNBRC
)
5582 parser_state
&= ~PST_ALLOWOPNBRC
;
5583 if (tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5586 function_bstart
= line_number
;
5587 return ('{'); /* } */
5591 /* We allow a `do' after a for ((...)) without an intervening
5593 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == 'd' && tokstr
[1] == 'o' && !tokstr
[2])
5595 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5598 return ('{'); /* } */
5601 if (open_brace_count
&& reserved_word_acceptable (last_read_token
) && tokstr
[0] == '}' && !tokstr
[1])
5603 open_brace_count
--; /* { */
5607 #if defined (COMMAND_TIMING)
5608 /* Handle -p after `time'. */
5609 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == 'p' && !tokstr
[2])
5611 /* Handle -- after `time'. */
5612 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5614 /* Handle -- after `time -p'. */
5615 if (last_read_token
== TIMEOPT
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5619 #if defined (COND_COMMAND) /* [[ */
5620 if ((parser_state
& PST_CONDEXPR
) && tokstr
[0] == ']' && tokstr
[1] == ']' && tokstr
[2] == '\0')
5627 /* Called from shell.c when Control-C is typed at top level. Or
5628 by the error rule at top level. */
5632 dstack
.delimiter_depth
= 0; /* No delimiters found so far. */
5633 open_brace_count
= 0;
5635 #if defined (EXTENDED_GLOB)
5636 /* Reset to global value of extended glob */
5637 if (parser_state
& (PST_EXTPAT
|PST_CMDSUBST
))
5638 extended_glob
= extglob_flag
;
5640 if (parser_state
& (PST_CMDSUBST
|PST_STRING
))
5641 expand_aliases
= expaliases_flag
;
5644 here_doc_first_line
= 0;
5646 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5647 if (pushed_string_list
)
5648 free_string_list ();
5649 #endif /* ALIAS || DPAREN_ARITHMETIC */
5651 /* This is where we resynchronize to the next newline on error/reset */
5652 if (shell_input_line
)
5654 free (shell_input_line
);
5655 shell_input_line
= (char *)NULL
;
5656 shell_input_line_size
= shell_input_line_index
= 0;
5659 FREE (word_desc_to_read
);
5660 word_desc_to_read
= (WORD_DESC
*)NULL
;
5662 eol_ungetc_lookahead
= 0;
5664 /* added post-bash-5.1 */
5667 esacs_needed_count
= expecting_in_token
= 0;
5669 current_token
= '\n'; /* XXX */
5670 last_read_token
= '\n';
5671 token_to_read
= '\n';
5675 reset_readahead_token ()
5677 if (token_to_read
== '\n')
5681 /* Read the next token. Command can be READ (normal operation) or
5682 RESET (to normalize state). */
5684 read_token (command
)
5687 int character
; /* Current character. */
5688 int peek_char
; /* Temporary look-ahead character. */
5689 int result
; /* The thing to return. */
5691 if (command
== RESET
)
5699 result
= token_to_read
;
5700 if (token_to_read
== WORD
|| token_to_read
== ASSIGNMENT_WORD
)
5702 yylval
.word
= word_desc_to_read
;
5703 word_desc_to_read
= (WORD_DESC
*)NULL
;
5709 #if defined (COND_COMMAND)
5710 if ((parser_state
& (PST_CONDCMD
|PST_CONDEXPR
)) == PST_CONDCMD
)
5712 cond_lineno
= line_number
;
5713 parser_state
|= PST_CONDEXPR
;
5714 yylval
.command
= parse_cond_command ();
5715 if (cond_token
!= COND_END
)
5720 token_to_read
= COND_END
;
5721 parser_state
&= ~(PST_CONDEXPR
|PST_CONDCMD
);
5727 /* This is a place to jump back to once we have successfully expanded a
5728 token with an alias and pushed the string with push_string () */
5732 /* Read a single word from input. Start by skipping blanks. */
5733 while ((character
= shell_getc (1)) != EOF
&& shellblank (character
))
5736 if (character
== EOF
)
5742 /* If we hit the end of the string and we're not expanding an alias (e.g.,
5743 we are eval'ing a string that is an incomplete command), return EOF */
5744 if (character
== '\0' && bash_input
.type
== st_string
&& expanding_alias() == 0)
5746 INTERNAL_DEBUG (("shell_getc: bash_input.location.string = `%s'", bash_input
.location
.string
));
5751 if MBTEST(character
== '#' && (!interactive
|| interactive_comments
))
5753 /* A comment. Discard until EOL or EOF, and then return a newline. */
5754 parser_state
|= PST_COMMENT
;
5755 discard_until ('\n');
5757 parser_state
&= ~PST_COMMENT
;
5758 character
= '\n'; /* this will take the next if statement and return. */
5761 if MBTEST(character
== '\n')
5763 /* If we're about to return an unquoted newline, we can go and collect
5764 the text of any pending here document. */
5766 gather_here_documents ();
5769 parser_state
&= ~PST_ALEXPNEXT
;
5772 parser_state
&= ~PST_ASSIGNOK
;
5777 if (parser_state
& PST_REGEXP
)
5780 /* Shell meta-characters. */
5781 if MBTEST(shellmeta (character
))
5784 /* Turn off alias tokenization iff this character sequence would
5785 not leave us ready to read a command. */
5786 if (character
== '<' || character
== '>')
5787 parser_state
&= ~PST_ALEXPNEXT
;
5790 parser_state
&= ~PST_ASSIGNOK
;
5792 /* If we are parsing a command substitution and we have read a character
5793 that marks the end of it, don't bother to skip over quoted newlines
5794 when we read the next token. We're just interested in a character
5795 that will turn this into a two-character token, so we let the higher
5796 layers deal with quoted newlines following the command substitution. */
5797 if ((parser_state
& PST_CMDSUBST
) && character
== shell_eof_token
)
5798 peek_char
= shell_getc (0);
5800 peek_char
= shell_getc (1);
5802 if MBTEST(character
== peek_char
)
5807 /* If '<' then we could be at "<<" or at "<<-". We have to
5808 look ahead one more character. */
5809 peek_char
= shell_getc (1);
5810 if MBTEST(peek_char
== '-')
5811 return (LESS_LESS_MINUS
);
5812 else if MBTEST(peek_char
== '<')
5813 return (LESS_LESS_LESS
);
5816 shell_ungetc (peek_char
);
5821 return (GREATER_GREATER
);
5824 parser_state
|= PST_CASEPAT
;
5826 parser_state
&= ~PST_ALEXPNEXT
;
5829 peek_char
= shell_getc (1);
5830 if MBTEST(peek_char
== '&')
5831 return (SEMI_SEMI_AND
);
5834 shell_ungetc (peek_char
);
5844 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5846 result
= parse_dparen (character
);
5854 else if MBTEST(character
== '<' && peek_char
== '&')
5856 else if MBTEST(character
== '>' && peek_char
== '&')
5857 return (GREATER_AND
);
5858 else if MBTEST(character
== '<' && peek_char
== '>')
5859 return (LESS_GREATER
);
5860 else if MBTEST(character
== '>' && peek_char
== '|')
5861 return (GREATER_BAR
);
5862 else if MBTEST(character
== '&' && peek_char
== '>')
5864 peek_char
= shell_getc (1);
5865 if MBTEST(peek_char
== '>')
5866 return (AND_GREATER_GREATER
);
5869 shell_ungetc (peek_char
);
5870 return (AND_GREATER
);
5873 else if MBTEST(character
== '|' && peek_char
== '&')
5875 else if MBTEST(character
== ';' && peek_char
== '&')
5877 parser_state
|= PST_CASEPAT
;
5879 parser_state
&= ~PST_ALEXPNEXT
;
5884 shell_ungetc (peek_char
);
5886 /* If we look like we are reading the start of a function
5887 definition, then let the reader know about it so that
5888 we will do the right thing with `{'. */
5889 if MBTEST(character
== ')' && last_read_token
== '(' && token_before_that
== WORD
)
5891 parser_state
|= PST_ALLOWOPNBRC
;
5893 parser_state
&= ~PST_ALEXPNEXT
;
5895 function_dstart
= line_number
;
5898 /* case pattern lists may be preceded by an optional left paren. If
5899 we're not trying to parse a case pattern list, the left paren
5900 indicates a subshell. */
5901 if MBTEST(character
== '(' && (parser_state
& PST_CASEPAT
) == 0) /* ) */
5902 parser_state
|= PST_SUBSHELL
;
5904 else if MBTEST((parser_state
& PST_CASEPAT
) && character
== ')')
5905 parser_state
&= ~PST_CASEPAT
;
5907 else if MBTEST((parser_state
& PST_SUBSHELL
) && character
== ')')
5908 parser_state
&= ~PST_SUBSHELL
;
5910 #if defined (PROCESS_SUBSTITUTION)
5911 /* Check for the constructs which introduce process substitution.
5912 Shells running in `posix mode' don't do process substitution. */
5913 if MBTEST((character
!= '>' && character
!= '<') || peek_char
!= '(') /*)*/
5914 #endif /* PROCESS_SUBSTITUTION */
5918 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5919 if MBTEST(character
== '-' && (last_read_token
== LESS_AND
|| last_read_token
== GREATER_AND
))
5923 /* Okay, if we got this far, we have to read a word. Read one,
5924 and then check it against the known ones. */
5925 result
= read_token_word (character
);
5927 if (result
== RE_READ_TOKEN
)
5934 * Match a $(...) or other grouping construct. This has to handle embedded
5935 * quoted strings ('', ``, "") and nested constructs. It also must handle
5936 * reprompting the user, if necessary, after reading a newline, and returning
5937 * correct error values if it reads EOF.
5939 #define P_FIRSTCLOSE 0x0001
5940 #define P_ALLOWESC 0x0002
5941 #define P_DQUOTE 0x0004
5942 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5943 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5944 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5945 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5946 #define P_ARITH 0x0080 /* parsing a $(( )) arithmetic expansion */
5948 /* Lexical state while parsing a grouping construct or $(...). */
5949 #define LEX_WASDOL 0x0001
5950 #define LEX_CKCOMMENT 0x0002
5951 #define LEX_INCOMMENT 0x0004
5952 #define LEX_PASSNEXT 0x0008
5953 #define LEX_RESWDOK 0x0010
5954 #define LEX_CKCASE 0x0020
5955 #define LEX_INCASE 0x0040
5956 #define LEX_INHEREDOC 0x0080
5957 #define LEX_HEREDELIM 0x0100 /* reading here-doc delimiter */
5958 #define LEX_STRIPDOC 0x0200 /* <<- strip tabs from here doc delim */
5959 #define LEX_QUOTEDDOC 0x0400 /* here doc with quoted delim */
5960 #define LEX_INWORD 0x0800
5961 #define LEX_GTLT 0x1000
5962 #define LEX_CKESAC 0x2000 /* check esac after in -- for later */
5963 #define LEX_CASEWD 0x4000 /* word after case */
5964 #define LEX_PATLIST 0x8000 /* case statement pattern list */
5966 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5968 #define CHECK_NESTRET_ERROR() \
5970 if (nestret == &matched_pair_error) \
5973 return &matched_pair_error; \
5977 #define APPEND_NESTRET() \
5981 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5982 strcpy (ret + retind, nestret); \
5983 retind += nestlen; \
5987 static char matched_pair_error
;
5990 parse_matched_pair (qc
, open
, close
, lenp
, flags
)
5991 int qc
; /* `"' if this construct is within double quotes */
5995 int count
, ch
, prevch
, tflags
;
5996 int nestlen
, ttranslen
, start_lineno
;
5997 char *ret
, *nestret
, *ttrans
;
5998 int retind
, retsize
, rflags
;
6001 dolbrace_state
= (flags
& P_DOLBRACE
) ? DOLBRACE_PARAM
: 0;
6003 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
6007 if ((flags
& P_COMMAND
) && qc
!= '`' && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
6008 tflags
|= LEX_CKCOMMENT
;
6010 /* RFLAGS is the set of flags we want to pass to recursive calls. */
6011 rflags
= (qc
== '"') ? P_DQUOTE
: (flags
& P_DQUOTE
);
6013 ret
= (char *)xmalloc (retsize
= 64);
6016 start_lineno
= line_number
;
6017 ch
= EOF
; /* just in case */
6021 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_PASSNEXT
)) == 0);
6026 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
6027 EOF_Reached
= 1; /* XXX */
6028 parser_state
|= PST_NOERROR
; /* avoid redundant error message */
6029 return (&matched_pair_error
);
6032 /* Possible reprompting. */
6033 if MBTEST(ch
== '\n' && SHOULD_PROMPT ())
6036 /* Don't bother counting parens or doing anything else if in a comment
6037 or part of a case statement */
6038 if (tflags
& LEX_INCOMMENT
)
6040 /* Add this character. */
6041 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6044 if MBTEST(ch
== '\n')
6045 tflags
&= ~LEX_INCOMMENT
;
6050 /* Not exactly right yet, should handle shell metacharacters, too. If
6051 any changes are made to this test, make analogous changes to subst.c:
6052 extract_delimited_string(). */
6053 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (retind
== 0 || ret
[retind
-1] == '\n' || shellblank (ret
[retind
- 1])))
6054 tflags
|= LEX_INCOMMENT
;
6056 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
6058 tflags
&= ~LEX_PASSNEXT
;
6059 /* XXX - PST_NOEXPAND? */
6060 if MBTEST(qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
6063 retind
--; /* swallow previously-added backslash */
6067 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6068 if MBTEST(ch
== CTLESC
)
6069 ret
[retind
++] = CTLESC
;
6073 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
6074 we've already prepended CTLESC to single-quoted results of $'...'.
6075 We may want to do this for other CTLESC-quoted characters in
6077 else if MBTEST((parser_state
& PST_REPARSE
) && open
== '\'' && (ch
== CTLESC
|| ch
== CTLNUL
))
6079 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6083 else if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
6085 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6086 ret
[retind
++] = CTLESC
;
6090 else if MBTEST(ch
== close
) /* ending delimiter */
6092 /* handle nested ${...} specially. */
6093 else if MBTEST(open
!= close
&& (tflags
& LEX_WASDOL
) && open
== '{' && ch
== open
) /* } */
6095 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && ch
== open
) /* nested begin */
6098 /* Add this character. */
6099 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6102 /* If we just read the ending character, don't bother continuing. */
6106 if (open
== '\'') /* '' inside grouping construct */
6108 if MBTEST((flags
& P_ALLOWESC
) && ch
== '\\')
6109 tflags
|= LEX_PASSNEXT
;
6113 if MBTEST(ch
== '\\') /* backslashes */
6114 tflags
|= LEX_PASSNEXT
;
6116 /* Based on which dolstate is currently in (param, op, or word),
6117 decide what the op is. We're really only concerned if it's % or
6118 #, so we can turn on a flag that says whether or not we should
6119 treat single quotes as special when inside a double-quoted
6120 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
6121 since they share the same defines. */
6122 /* FLAG POSIX INTERP 221 */
6123 if (flags
& P_DOLBRACE
)
6125 /* ${param%[%]word} */
6126 if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '%' && retind
> 1)
6127 dolbrace_state
= DOLBRACE_QUOTE
;
6128 /* ${param#[#]word} */
6129 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '#' && retind
> 1)
6130 dolbrace_state
= DOLBRACE_QUOTE
;
6131 /* ${param/[/]pat/rep} */
6132 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '/' && retind
> 1)
6133 dolbrace_state
= DOLBRACE_QUOTE2
; /* XXX */
6134 /* ${param^[^]pat} */
6135 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '^' && retind
> 1)
6136 dolbrace_state
= DOLBRACE_QUOTE
;
6137 /* ${param,[,]pat} */
6138 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== ',' && retind
> 1)
6139 dolbrace_state
= DOLBRACE_QUOTE
;
6140 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& strchr ("#%^,~:-=?+/", ch
) != 0)
6141 dolbrace_state
= DOLBRACE_OP
;
6142 else if MBTEST(dolbrace_state
== DOLBRACE_OP
&& strchr ("#%^,~:-=?+/", ch
) == 0)
6143 dolbrace_state
= DOLBRACE_WORD
;
6146 /* The big hammer. Single quotes aren't special in double quotes. The
6147 problem is that Posix used to say the single quotes are semi-special:
6148 within a double-quoted ${...} construct "an even number of
6149 unescaped double-quotes or single-quotes, if any, shall occur." */
6150 /* This was changed in Austin Group Interp 221 */
6151 if MBTEST(posixly_correct
&& shell_compatibility_level
> 41 && dolbrace_state
!= DOLBRACE_QUOTE
&& dolbrace_state
!= DOLBRACE_QUOTE2
&& (flags
& P_DQUOTE
) && (flags
& P_DOLBRACE
) && ch
== '\'')
6154 /* Could also check open == '`' if we want to parse grouping constructs
6155 inside old-style command substitution. */
6156 if (open
!= close
) /* a grouping construct */
6158 if MBTEST(shellquote (ch
))
6160 /* '', ``, or "" inside $(...) or other grouping construct. */
6161 push_delimiter (dstack
, ch
);
6162 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
6163 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
6165 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
6166 pop_delimiter (dstack
);
6167 CHECK_NESTRET_ERROR ();
6169 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0 || dolbrace_state
== DOLBRACE_QUOTE
|| dolbrace_state
== DOLBRACE_QUOTE2
))
6171 /* Translate $'...' here. */
6173 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
6176 /* If we're parsing a double-quoted brace expansion and we are
6177 not in a place where single quotes are treated specially,
6178 make sure we single-quote the results of the ansi
6179 expansion because quote removal should remove them later */
6180 /* FLAG POSIX INTERP 221 */
6181 if ((shell_compatibility_level
> 42) && (rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_QUOTE2
|| dolbrace_state
== DOLBRACE_QUOTE
) && (flags
& P_DOLBRACE
))
6183 nestret
= sh_single_quote (ttrans
);
6185 nestlen
= strlen (nestret
);
6187 #if 0 /* TAG:bash-5.3 */
6188 /* This single-quotes PARAM in ${PARAM OP WORD} when PARAM
6189 contains a $'...' even when extended_quote is set. */
6190 else if ((rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_PARAM
) && (flags
& P_DOLBRACE
))
6192 nestret
= sh_single_quote (ttrans
);
6194 nestlen
= strlen (nestret
);
6197 else if ((rflags
& P_DQUOTE
) == 0)
6199 nestret
= sh_single_quote (ttrans
);
6201 nestlen
= strlen (nestret
);
6205 /* Should we quote CTLESC here? */
6207 nestlen
= ttranslen
;
6209 retind
-= 2; /* back up before the $' */
6211 #if defined (TRANSLATABLE_STRINGS)
6212 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6214 /* Locale expand $"..." here. */
6216 ttrans
= locale_expand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
6219 /* If we're supposed to single-quote translated strings,
6220 check whether the translated result is different from
6221 the original and single-quote the string if it is. */
6222 if (singlequote_translations
&&
6223 ((nestlen
- 1) != ttranslen
|| STREQN (nestret
, ttrans
, ttranslen
) == 0))
6225 if ((rflags
& P_DQUOTE
) == 0)
6226 nestret
= sh_single_quote (ttrans
);
6227 else if ((rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_QUOTE2
) && (flags
& P_DOLBRACE
))
6228 nestret
= sh_single_quote (ttrans
);
6230 /* single quotes aren't special, use backslash instead */
6231 nestret
= sh_backslash_quote_for_double_quotes (ttrans
, 0);
6234 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
6236 nestlen
= strlen (nestret
);
6237 retind
-= 2; /* back up before the $" */
6239 #endif /* TRANSLATABLE_STRINGS */
6244 else if ((flags
& (P_ARRAYSUB
|P_DOLBRACE
)) && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6245 goto parse_dollar_word
;
6246 else if ((flags
& P_ARITH
) && (tflags
& LEX_WASDOL
) && ch
== '(') /*)*/
6247 /* $() inside $(( ))/$[ ] */
6248 goto parse_dollar_word
;
6249 #if defined (PROCESS_SUBSTITUTION)
6250 /* XXX - technically this should only be recognized at the start of
6252 else if ((flags
& (P_ARRAYSUB
|P_DOLBRACE
)) && (tflags
& LEX_GTLT
) && (ch
== '(')) /* ) */
6253 goto parse_dollar_word
;
6256 /* Parse an old-style command substitution within double quotes as a
6258 /* XXX - sh and ksh93 don't do this - XXX */
6259 else if MBTEST(open
== '"' && ch
== '`')
6261 nestret
= parse_matched_pair (0, '`', '`', &nestlen
, rflags
);
6263 CHECK_NESTRET_ERROR ();
6268 else if MBTEST(open
!= '`' && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6269 /* check for $(), $[], or ${} inside quoted string. */
6272 if (open
== ch
) /* undo previous increment */
6274 if (ch
== '(') /* ) */
6275 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
6276 else if (ch
== '{') /* } */
6277 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
6278 else if (ch
== '[') /* ] */
6279 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
|P_ARITH
);
6281 CHECK_NESTRET_ERROR ();
6286 #if defined (PROCESS_SUBSTITUTION)
6287 if MBTEST((ch
== '<' || ch
== '>') && (tflags
& LEX_GTLT
) == 0)
6290 tflags
&= ~LEX_GTLT
;
6292 if MBTEST(ch
== '$' && (tflags
& LEX_WASDOL
) == 0)
6293 tflags
|= LEX_WASDOL
;
6295 tflags
&= ~LEX_WASDOL
;
6301 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
6313 fprintf (stderr
, "%d -> ", f
);
6317 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
6319 if (f
& LEX_CKCOMMENT
)
6321 f
&= ~LEX_CKCOMMENT
;
6322 fprintf (stderr
, "LEX_CKCOMMENT%s", f
? "|" : "");
6324 if (f
& LEX_INCOMMENT
)
6326 f
&= ~LEX_INCOMMENT
;
6327 fprintf (stderr
, "LEX_INCOMMENT%s", f
? "|" : "");
6329 if (f
& LEX_PASSNEXT
)
6332 fprintf (stderr
, "LEX_PASSNEXT%s", f
? "|" : "");
6334 if (f
& LEX_RESWDOK
)
6337 fprintf (stderr
, "LEX_RESWDOK%s", f
? "|" : "");
6342 fprintf (stderr
, "LEX_CKCASE%s", f
? "|" : "");
6347 fprintf (stderr
, "LEX_CKESAC%s", f
? "|" : "");
6352 fprintf (stderr
, "LEX_INCASE%s", f
? "|" : "");
6357 fprintf (stderr
, "LEX_CASEWD%s", f
? "|" : "");
6359 if (f
& LEX_PATLIST
)
6362 fprintf (stderr
, "LEX_PATLIST%s", f
? "|" : "");
6364 if (f
& LEX_INHEREDOC
)
6366 f
&= ~LEX_INHEREDOC
;
6367 fprintf (stderr
, "LEX_INHEREDOC%s", f
? "|" : "");
6369 if (f
& LEX_HEREDELIM
)
6371 f
&= ~LEX_HEREDELIM
;
6372 fprintf (stderr
, "LEX_HEREDELIM%s", f
? "|" : "");
6374 if (f
& LEX_STRIPDOC
)
6377 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
6379 if (f
& LEX_QUOTEDDOC
)
6381 f
&= ~LEX_QUOTEDDOC
;
6382 fprintf (stderr
, "LEX_QUOTEDDOC%s", f
? "|" : "");
6387 fprintf (stderr
, "LEX_INWORD%s", f
? "|" : "");
6390 fprintf (stderr
, "\n");
6395 /* Parse a $(...) command substitution. This reads input from the current
6398 parse_comsub (qc
, open
, close
, lenp
, flags
)
6399 int qc
; /* `"' if this construct is within double quotes */
6404 int start_lineno
, local_extglob
, was_extpat
;
6407 sh_parser_state_t ps
;
6408 STRING_SAVER
*saved_strings
;
6409 COMMAND
*saved_global
, *parsed_command
;
6411 /* Posix interp 217 says arithmetic expressions have precedence, so
6412 assume $(( introduces arithmetic expansion and parse accordingly. */
6413 if (open
== '(') /*)*/
6415 peekc
= shell_getc (1);
6416 shell_ungetc (peekc
);
6417 if (peekc
== '(') /*)*/
6418 return (parse_matched_pair (qc
, open
, close
, lenp
, P_ARITH
));
6421 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
6423 /*debug_parser(1);*/
6424 start_lineno
= line_number
;
6426 save_parser_state (&ps
);
6428 was_extpat
= (parser_state
& PST_EXTPAT
);
6430 /* State flags we don't want to persist into command substitutions. */
6431 parser_state
&= ~(PST_REGEXP
|PST_EXTPAT
|PST_CONDCMD
|PST_CONDEXPR
|PST_COMPASSIGN
);
6432 /* Could do PST_CASESTMT too, but that also affects history. Setting
6433 expecting_in_token below should take care of the parsing requirements.
6434 Unsetting PST_REDIRLIST isn't strictly necessary because of how we set
6435 token_to_read below, but we do it anyway. */
6436 parser_state
&= ~(PST_CASEPAT
|PST_ALEXPNEXT
|PST_SUBSHELL
|PST_REDIRLIST
);
6437 /* State flags we want to set for this run through the parser. */
6438 parser_state
|= PST_CMDSUBST
|PST_EOFTOKEN
|PST_NOEXPAND
;
6440 /* leave pushed_string_list alone, since we might need to consume characters
6441 from it to satisfy this command substitution (in some perverse case). */
6442 shell_eof_token
= close
;
6444 saved_global
= global_command
; /* might not be necessary */
6445 global_command
= (COMMAND
*)NULL
;
6447 /* These are reset by reset_parser() */
6449 esacs_needed_count
= expecting_in_token
= 0;
6451 /* We want to expand aliases on this pass if we're in posix mode, since the
6452 standard says you have to take aliases into account when looking for the
6453 terminating right paren. Otherwise, we defer until execution time for
6454 backwards compatibility. */
6456 expand_aliases
= posixly_correct
!= 0;
6457 #if defined (EXTENDED_GLOB)
6458 /* If (parser_state & PST_EXTPAT), we're parsing an extended pattern for a
6459 conditional command and have already set extended_glob appropriately. */
6460 if (shell_compatibility_level
<= 51 && was_extpat
== 0)
6462 local_extglob
= extended_glob
;
6467 current_token
= '\n'; /* XXX */
6468 token_to_read
= DOLPAREN
; /* let's trick the parser */
6472 if (need_here_doc
> 0)
6474 internal_warning ("command substitution: %d unterminated here-document%s", need_here_doc
, (need_here_doc
== 1) ? "" : "s");
6475 gather_here_documents (); /* XXX check compatibility level? */
6478 #if defined (EXTENDED_GLOB)
6479 if (shell_compatibility_level
<= 51 && was_extpat
== 0)
6480 extended_glob
= local_extglob
;
6483 parsed_command
= global_command
;
6487 shell_eof_token
= ps
.eof_token
;
6488 expand_aliases
= ps
.expand_aliases
;
6490 /* yyparse() has already called yyerror() and reset_parser() */
6491 parser_state
|= PST_NOERROR
;
6492 return (&matched_pair_error
);
6496 /* parser_error (start_lineno, _("could not parse command substitution")); */
6497 /* Non-interactive shells exit on parse error in a command substitution. */
6498 if (last_command_exit_value
== 0)
6499 last_command_exit_value
= EXECUTION_FAILURE
;
6500 set_exit_status (last_command_exit_value
);
6501 if (interactive_shell
== 0)
6502 jump_to_top_level (FORCE_EOF
); /* This is like reader_loop() */
6505 shell_eof_token
= ps
.eof_token
;
6506 expand_aliases
= ps
.expand_aliases
;
6508 jump_to_top_level (DISCARD
); /* XXX - return (&matched_pair_error)? */
6512 if (current_token
!= shell_eof_token
)
6514 INTERNAL_DEBUG(("current_token (%d) != shell_eof_token (%c)", current_token
, shell_eof_token
));
6515 token_to_read
= current_token
;
6517 /* If we get here we can check eof_encountered and if it's 1 but the
6518 previous EOF_Reached test didn't succeed, we can assume that the shell
6519 is interactive and ignoreeof is set. We might want to restore the
6520 parser state in this case. */
6521 shell_eof_token
= ps
.eof_token
;
6522 expand_aliases
= ps
.expand_aliases
;
6524 return (&matched_pair_error
);
6527 /* We don't want to restore the old pushed string list, since we might have
6528 used it to consume additional input from an alias while parsing this
6529 command substitution. */
6530 saved_strings
= pushed_string_list
;
6531 restore_parser_state (&ps
);
6532 pushed_string_list
= saved_strings
;
6534 tcmd
= print_comsub (parsed_command
); /* returns static memory */
6535 retlen
= strlen (tcmd
);
6536 if (tcmd
[0] == '(') /* ) need a space to prevent arithmetic expansion */
6538 ret
= xmalloc (retlen
+ 2);
6539 if (tcmd
[0] == '(') /* ) */
6542 strcpy (ret
+ 1, tcmd
);
6546 ret
[retlen
++] = ')';
6549 dispose_command (parsed_command
);
6550 global_command
= saved_global
;
6555 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6559 /* Recursively call the parser to parse a $(...) command substitution. This is
6560 called by the word expansion code and so does not have to reset as much
6561 parser state before calling yyparse(). */
6563 xparse_dolparen (base
, string
, indp
, flags
)
6569 sh_parser_state_t ps
;
6570 sh_input_line_state_t ls
;
6571 int orig_ind
, nc
, sflags
, start_lineno
, local_extglob
;
6572 char *ret
, *ep
, *ostring
;
6574 /*debug_parser(1);*/
6577 start_lineno
= line_number
;
6581 if (flags
& SX_NOALLOC
)
6582 return (char *)NULL
;
6589 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s' string=`%s'", shell_input_line_size, shell_input_line, string);*/
6591 sflags
= SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOFREE
;
6592 if (flags
& SX_NOLONGJMP
)
6593 sflags
|= SEVAL_NOLONGJMP
;
6595 save_parser_state (&ps
);
6596 save_input_line_state (&ls
);
6598 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
6599 pushed_string_list
= (STRING_SAVER
*)NULL
;
6602 parser_state
|= PST_CMDSUBST
|PST_EOFTOKEN
; /* allow instant ')' */ /*(*/
6603 shell_eof_token
= ')';
6604 if (flags
& SX_COMPLETE
)
6605 parser_state
|= PST_NOERROR
;
6607 /* Don't expand aliases on this pass at all. Either parse_comsub() does it
6608 at parse time, in which case this string already has aliases expanded,
6609 or command_substitute() does it in the child process executing the
6610 command substitution and we want to defer it completely until then. The
6611 old value will be restored by restore_parser_state(). */
6613 #if defined (EXTENDED_GLOB)
6614 local_extglob
= extended_glob
;
6617 token_to_read
= DOLPAREN
; /* let's trick the parser */
6619 nc
= parse_string (string
, "command substitution", sflags
, (COMMAND
**)NULL
, &ep
);
6621 /* Should we save and restore the bison/yacc lookahead token (yychar) here?
6622 Or only if it's not YYEMPTY? */
6623 if (current_token
== shell_eof_token
)
6624 yyclearin
; /* might want to clear lookahead token unconditionally */
6626 reset_parser (); /* resets extended_glob too */
6627 /* reset_parser() clears shell_input_line and associated variables, including
6628 parser_state, so we want to reset things, then restore what we need. */
6629 restore_input_line_state (&ls
);
6630 restore_parser_state (&ps
);
6632 #if defined (EXTENDED_GLOB)
6633 extended_glob
= local_extglob
;
6637 /* If parse_string returns < 0, we need to jump to top level with the
6638 negative of the return value. We abandon the rest of this input line
6642 clear_shell_input_line (); /* XXX */
6643 if (bash_input
.type
!= st_string
) /* paranoia */
6644 parser_state
&= ~(PST_CMDSUBST
|PST_EOFTOKEN
);
6645 if ((flags
& SX_NOLONGJMP
) == 0)
6646 jump_to_top_level (-nc
); /* XXX */
6649 /* Need to find how many characters parse_string() consumed, update
6650 *indp, if flags != 0, copy the portion of the string parsed into RET
6651 and return it. If flags & 1 (SX_NOALLOC) we can return NULL. */
6658 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number
, ep
[-1], ep
);
6661 while (ep
> ostring
&& ep
[-1] == '\n') ep
--;
6665 *indp
= ep
- base
- 1;
6669 if (base
[*indp
] != ')')
6670 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number
, *indp
, base
[*indp
], base
);
6671 if (*indp
< orig_ind
)
6672 itrace("xparse_dolparen:%d: *indp (%d) < orig_ind (%d), orig_string = `%s'", line_number
, *indp
, orig_ind
, ostring
);
6675 if (base
[*indp
] != ')' && (flags
& SX_NOLONGJMP
) == 0)
6678 if ((flags
& SX_NOERROR
) == 0)
6679 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), ')');
6680 jump_to_top_level (DISCARD
);
6683 if (flags
& SX_NOALLOC
)
6684 return (char *)NULL
;
6692 ret
= substring (ostring
, 0, nc
- 1);
6697 /* Recursively call the parser to parse the string from a $(...) command
6698 substitution to a COMMAND *. This is called from command_substitute() and
6699 has the same parser state constraints as xparse_dolparen(). */
6701 parse_string_to_command (string
, flags
)
6705 sh_parser_state_t ps
;
6706 sh_input_line_state_t ls
;
6713 return (COMMAND
*)NULL
;
6716 slen
= STRLEN (string
);
6718 /*itrace("parse_string_to_command: size = %d shell_input_line = `%s' string=`%s'", shell_input_line_size, shell_input_line, string);*/
6720 sflags
= SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOFREE
;
6721 if (flags
& SX_NOLONGJMP
)
6722 sflags
|= SEVAL_NOLONGJMP
;
6724 save_parser_state (&ps
);
6725 save_input_line_state (&ls
);
6727 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
6728 pushed_string_list
= (STRING_SAVER
*)NULL
;
6730 if (flags
& SX_COMPLETE
)
6731 parser_state
|= PST_NOERROR
;
6733 parser_state
|= PST_STRING
;
6737 nc
= parse_string (string
, "command substitution", sflags
, &cmd
, &ep
);
6740 /* reset_parser() clears shell_input_line and associated variables, including
6741 parser_state, so we want to reset things, then restore what we need. */
6742 restore_input_line_state (&ls
);
6743 restore_parser_state (&ps
);
6745 /* If parse_string returns < 0, we need to jump to top level with the
6746 negative of the return value. We abandon the rest of this input line
6750 clear_shell_input_line (); /* XXX */
6751 if ((flags
& SX_NOLONGJMP
) == 0)
6752 jump_to_top_level (-nc
); /* XXX */
6755 /* Need to check how many characters parse_string() consumed, make sure it's
6756 the entire string. */
6759 dispose_command (cmd
);
6760 return (COMMAND
*)NULL
;
6766 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6767 /* Parse a double-paren construct. It can be either an arithmetic
6768 command, an arithmetic `for' command, or a nested subshell. Returns
6769 the parsed token, -1 on error, or -2 if we didn't do anything and
6770 should just go on. */
6779 #if defined (ARITH_FOR_COMMAND)
6780 if (last_read_token
== FOR
)
6782 if (word_top
< MAX_CASE_NEST
)
6784 arith_for_lineno
= word_lineno
[word_top
] = line_number
;
6785 cmdtyp
= parse_arith_cmd (&wval
, 0);
6788 wd
= alloc_word_desc ();
6790 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6791 return (ARITH_FOR_EXPRS
);
6794 return -1; /* ERROR */
6798 #if defined (DPAREN_ARITHMETIC)
6799 if (reserved_word_acceptable (last_read_token
))
6801 sline
= line_number
;
6803 cmdtyp
= parse_arith_cmd (&wval
, 0);
6804 if (cmdtyp
== 1) /* arithmetic command */
6806 wd
= alloc_word_desc ();
6808 wd
->flags
= W_QUOTED
|W_NOSPLIT
|W_NOGLOB
|W_NOTILDE
|W_NOPROCSUB
;
6809 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6812 else if (cmdtyp
== 0) /* nested subshell */
6814 push_string (wval
, 0, (alias_t
*)NULL
);
6815 pushed_string_list
->flags
= PSH_DPAREN
;
6816 if ((parser_state
& PST_CASEPAT
) == 0)
6817 parser_state
|= PST_SUBSHELL
;
6825 return -2; /* XXX */
6828 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6829 If not, assume it's a nested subshell for backwards compatibility and
6830 return 0. In any case, put the characters we've consumed into a locally-
6831 allocated buffer and make *ep point to that buffer. Return -1 on an
6832 error, for example EOF. */
6834 parse_arith_cmd (ep
, adddq
)
6838 int exp_lineno
, rval
, c
;
6839 char *ttok
, *tokstr
;
6842 exp_lineno
= line_number
;
6843 ttok
= parse_matched_pair (0, '(', ')', &ttoklen
, P_ARITH
);
6845 if (ttok
== &matched_pair_error
)
6847 /* Check that the next character is the closing right paren. If
6848 not, this is a syntax error. ( */
6853 tokstr
= (char *)xmalloc (ttoklen
+ 4);
6855 /* if ADDDQ != 0 then (( ... )) -> "..." */
6856 if (rval
== 1 && adddq
) /* arith cmd, add double quotes */
6859 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6860 tokstr
[ttoklen
] = '"';
6861 tokstr
[ttoklen
+1] = '\0';
6863 else if (rval
== 1) /* arith cmd, don't add double quotes */
6865 strncpy (tokstr
, ttok
, ttoklen
- 1);
6866 tokstr
[ttoklen
-1] = '\0';
6868 else /* nested subshell */
6871 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6872 tokstr
[ttoklen
] = ')';
6873 tokstr
[ttoklen
+1] = c
;
6874 tokstr
[ttoklen
+2] = '\0';
6881 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6883 #if defined (COND_COMMAND)
6889 if (EOF_Reached
&& cond_token
!= COND_ERROR
) /* [[ */
6890 parser_error (cond_lineno
, _("unexpected EOF while looking for `]]'"));
6891 else if (cond_token
!= COND_ERROR
)
6893 if (etext
= error_token_from_token (cond_token
))
6895 parser_error (cond_lineno
, _("syntax error in conditional expression: unexpected token `%s'"), etext
);
6899 parser_error (cond_lineno
, _("syntax error in conditional expression"));
6906 return (cond_or ());
6915 if (cond_token
== OR_OR
)
6918 l
= make_cond_node (COND_OR
, (WORD_DESC
*)NULL
, l
, r
);
6929 if (cond_token
== AND_AND
)
6932 l
= make_cond_node (COND_AND
, (WORD_DESC
*)NULL
, l
, r
);
6938 cond_skip_newlines ()
6940 while ((cond_token
= read_token (READ
)) == '\n')
6942 if (SHOULD_PROMPT ())
6945 return (cond_token
);
6948 #define COND_RETURN_ERROR() \
6949 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6955 COND_COM
*term
, *tleft
, *tright
;
6956 int tok
, lineno
, local_extglob
;
6959 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6960 word that should be the first argument of a binary operator. Start by
6961 skipping newlines, since this is a compound command. */
6962 tok
= cond_skip_newlines ();
6963 lineno
= line_number
;
6964 if (tok
== COND_END
)
6966 COND_RETURN_ERROR ();
6968 else if (tok
== '(')
6970 term
= cond_expr ();
6971 if (cond_token
!= ')')
6974 dispose_cond_node (term
); /* ( */
6975 if (etext
= error_token_from_token (cond_token
))
6977 parser_error (lineno
, _("unexpected token `%s', expected `)'"), etext
);
6981 parser_error (lineno
, _("expected `)'"));
6982 COND_RETURN_ERROR ();
6984 term
= make_cond_node (COND_EXPR
, (WORD_DESC
*)NULL
, term
, (COND_COM
*)NULL
);
6985 (void)cond_skip_newlines ();
6987 else if (tok
== BANG
|| (tok
== WORD
&& (yylval
.word
->word
[0] == '!' && yylval
.word
->word
[1] == '\0')))
6990 dispose_word (yylval
.word
); /* not needed */
6991 term
= cond_term ();
6993 term
->flags
^= CMD_INVERT_RETURN
;
6995 else if (tok
== WORD
&& yylval
.word
->word
[0] == '-' && yylval
.word
->word
[1] && yylval
.word
->word
[2] == 0 && test_unop (yylval
.word
->word
))
6998 tok
= read_token (READ
);
7001 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7002 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
7007 if (etext
= error_token_from_token (tok
))
7009 parser_error (line_number
, _("unexpected argument `%s' to conditional unary operator"), etext
);
7013 parser_error (line_number
, _("unexpected argument to conditional unary operator"));
7014 COND_RETURN_ERROR ();
7017 (void)cond_skip_newlines ();
7019 else if (tok
== WORD
) /* left argument to binary operator */
7022 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7025 /* tok = cond_skip_newlines (); ? */
7026 tok
= read_token (READ
);
7027 if (tok
== WORD
&& test_binop (yylval
.word
->word
))
7030 if (op
->word
[0] == '=' && (op
->word
[1] == '\0' || (op
->word
[1] == '=' && op
->word
[2] == '\0')))
7031 parser_state
|= PST_EXTPAT
;
7032 else if (op
->word
[0] == '!' && op
->word
[1] == '=' && op
->word
[2] == '\0')
7033 parser_state
|= PST_EXTPAT
;
7035 #if defined (COND_REGEXP)
7036 else if (tok
== WORD
&& STREQ (yylval
.word
->word
, "=~"))
7039 parser_state
|= PST_REGEXP
;
7042 else if (tok
== '<' || tok
== '>')
7043 op
= make_word_from_token (tok
); /* ( */
7044 /* There should be a check before blindly accepting the `)' that we have
7045 seen the opening `('. */
7046 else if (tok
== COND_END
|| tok
== AND_AND
|| tok
== OR_OR
|| tok
== ')')
7048 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
7049 the test command. Similarly for [[ x && expr ]] or
7050 [[ x || expr ]] or [[ (x) ]]. */
7051 op
= make_word ("-n");
7052 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
7058 if (etext
= error_token_from_token (tok
))
7060 parser_error (line_number
, _("unexpected token `%s', conditional binary operator expected"), etext
);
7064 parser_error (line_number
, _("conditional binary operator expected"));
7065 dispose_cond_node (tleft
);
7066 COND_RETURN_ERROR ();
7070 #if defined (EXTENDED_GLOB)
7071 local_extglob
= extended_glob
;
7072 if (parser_state
& PST_EXTPAT
)
7075 tok
= read_token (READ
);
7076 #if defined (EXTENDED_GLOB)
7077 if (parser_state
& PST_EXTPAT
)
7078 extended_glob
= local_extglob
;
7080 parser_state
&= ~(PST_REGEXP
|PST_EXTPAT
);
7084 tright
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7085 term
= make_cond_node (COND_BINARY
, op
, tleft
, tright
);
7089 if (etext
= error_token_from_token (tok
))
7091 parser_error (line_number
, _("unexpected argument `%s' to conditional binary operator"), etext
);
7095 parser_error (line_number
, _("unexpected argument to conditional binary operator"));
7096 dispose_cond_node (tleft
);
7098 COND_RETURN_ERROR ();
7101 (void)cond_skip_newlines ();
7106 parser_error (line_number
, _("unexpected token `%c' in conditional command"), tok
);
7107 else if (etext
= error_token_from_token (tok
))
7109 parser_error (line_number
, _("unexpected token `%s' in conditional command"), etext
);
7113 parser_error (line_number
, _("unexpected token %d in conditional command"), tok
);
7114 COND_RETURN_ERROR ();
7119 /* This is kind of bogus -- we slip a mini recursive-descent parser in
7120 here to handle the conditional statement syntax. */
7122 parse_cond_command ()
7126 cexp
= cond_expr ();
7127 return (make_cond_command (cexp
));
7131 #if defined (ARRAY_VARS)
7132 /* When this is called, it's guaranteed that we don't care about anything
7133 in t beyond i. We use a buffer with room for the characters we add just
7134 in case assignment() ends up doing something like parsing a command
7135 substitution that will reallocate atoken. We don't want to write beyond
7136 the end of an allocated buffer. */
7138 token_is_assignment (t
, i
)
7145 atoken
= xmalloc (i
+ 3);
7146 memcpy (atoken
, t
, i
);
7150 r
= assignment (atoken
, (parser_state
& PST_COMPASSIGN
) != 0);
7154 /* XXX - check that r == i to avoid returning false positive for
7155 t containing `=' before t[i]. */
7156 return (r
> 0 && r
== i
);
7159 /* XXX - possible changes here for `+=' */
7161 token_is_ident (t
, i
)
7170 r
= legal_identifier (t
);
7177 read_token_word (character
)
7180 /* The value for YYLVAL when a WORD is read. */
7181 WORD_DESC
*the_word
;
7183 /* Index into the token that we are building. */
7186 /* ALL_DIGITS becomes zero when we see a non-digit. */
7187 int all_digit_token
;
7189 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
7192 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
7194 int compound_assignment
;
7196 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
7199 /* Non-zero means to ignore the value of the next character, and just
7200 to add it no matter what. */
7201 int pass_next_character
;
7203 /* The current delimiting character. */
7205 int result
, peek_char
;
7206 char *ttok
, *ttrans
;
7207 int ttoklen
, ttranslen
;
7210 if (token_buffer_size
< TOKEN_DEFAULT_INITIAL_SIZE
)
7211 token
= (char *)xrealloc (token
, token_buffer_size
= TOKEN_DEFAULT_INITIAL_SIZE
);
7214 all_digit_token
= DIGIT (character
);
7215 dollar_present
= quoted
= pass_next_character
= compound_assignment
= 0;
7219 if (character
== EOF
)
7222 if (pass_next_character
)
7224 pass_next_character
= 0;
7225 goto got_escaped_character
;
7228 cd
= current_delimiter (dstack
);
7230 /* Handle backslashes. Quote lots of things when not inside of
7231 double-quotes, quote some things inside of double-quotes. */
7232 if MBTEST(character
== '\\')
7234 if (parser_state
& PST_NOEXPAND
)
7236 pass_next_character
++;
7241 peek_char
= shell_getc (0);
7243 /* Backslash-newline is ignored in all cases except
7244 when quoted with single quotes. */
7245 if MBTEST(peek_char
== '\n')
7248 goto next_character
;
7252 shell_ungetc (peek_char
);
7254 /* If the next character is to be quoted, note it now. */
7255 if MBTEST(cd
== 0 || cd
== '`' ||
7256 (cd
== '"' && peek_char
>= 0 && (sh_syntaxtab
[peek_char
] & CBSDQUOTE
)))
7257 pass_next_character
++;
7264 /* Parse a matched pair of quote characters. */
7265 if MBTEST(shellquote (character
))
7267 push_delimiter (dstack
, character
);
7268 ttok
= parse_matched_pair (character
, character
, character
, &ttoklen
, (character
== '`') ? P_COMMAND
: 0);
7269 pop_delimiter (dstack
);
7270 if (ttok
== &matched_pair_error
)
7271 return -1; /* Bail immediately. */
7272 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7273 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7274 token
[token_index
++] = character
;
7275 strcpy (token
+ token_index
, ttok
);
7276 token_index
+= ttoklen
;
7277 all_digit_token
= 0;
7278 if (character
!= '`')
7280 dollar_present
|= (character
== '"' && strchr (ttok
, '$') != 0);
7282 goto next_character
;
7286 /* When parsing a regexp as a single word inside a conditional command,
7287 we need to special-case characters special to both the shell and
7288 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
7289 if MBTEST((parser_state
& PST_REGEXP
) && (character
== '(' || character
== '|')) /*)*/
7291 if (character
== '|')
7294 push_delimiter (dstack
, character
);
7295 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7296 pop_delimiter (dstack
);
7297 if (ttok
== &matched_pair_error
)
7298 return -1; /* Bail immediately. */
7299 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7300 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7301 token
[token_index
++] = character
;
7302 strcpy (token
+ token_index
, ttok
);
7303 token_index
+= ttoklen
;
7305 dollar_present
= all_digit_token
= 0;
7306 goto next_character
;
7308 #endif /* COND_REGEXP */
7310 #ifdef EXTENDED_GLOB
7311 /* Parse a ksh-style extended pattern matching specification. */
7312 if MBTEST(extended_glob
&& PATTERN_CHAR (character
))
7314 peek_char
= shell_getc (1);
7315 if MBTEST(peek_char
== '(') /* ) */
7317 push_delimiter (dstack
, peek_char
);
7318 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7319 pop_delimiter (dstack
);
7320 if (ttok
== &matched_pair_error
)
7321 return -1; /* Bail immediately. */
7322 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7324 TOKEN_DEFAULT_GROW_SIZE
);
7325 token
[token_index
++] = character
;
7326 token
[token_index
++] = peek_char
;
7327 strcpy (token
+ token_index
, ttok
);
7328 token_index
+= ttoklen
;
7330 dollar_present
= all_digit_token
= 0;
7331 goto next_character
;
7334 shell_ungetc (peek_char
);
7336 #endif /* EXTENDED_GLOB */
7338 /* If the delimiter character is not single quote, parse some of
7339 the shell expansions that must be read as a single word. */
7340 if MBTEST(shellexp (character
))
7342 peek_char
= shell_getc (1);
7343 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
7344 if MBTEST(peek_char
== '(' ||
7345 ((peek_char
== '{' || peek_char
== '[') && character
== '$')) /* ) ] } */
7347 if (peek_char
== '{') /* } */
7348 ttok
= parse_matched_pair (cd
, '{', '}', &ttoklen
, P_FIRSTCLOSE
|P_DOLBRACE
);
7349 else if (peek_char
== '(') /* ) */
7351 /* XXX - push and pop the `(' as a delimiter for use by
7352 the command-oriented-history code. This way newlines
7353 appearing in the $(...) string get added to the
7354 history literally rather than causing a possibly-
7355 incorrect `;' to be added. ) */
7356 push_delimiter (dstack
, peek_char
);
7357 ttok
= parse_comsub (cd
, '(', ')', &ttoklen
, P_COMMAND
);
7358 pop_delimiter (dstack
);
7361 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, P_ARITH
);
7362 if (ttok
== &matched_pair_error
)
7363 return -1; /* Bail immediately. */
7364 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7366 TOKEN_DEFAULT_GROW_SIZE
);
7367 token
[token_index
++] = character
;
7368 token
[token_index
++] = peek_char
;
7369 strcpy (token
+ token_index
, ttok
);
7370 token_index
+= ttoklen
;
7373 all_digit_token
= 0;
7374 goto next_character
;
7376 /* This handles $'...' and $"..." new-style quoted strings. */
7377 #if defined (TRANSLATABLE_STRINGS)
7378 else if MBTEST(character
== '$' && (peek_char
== '\'' || peek_char
== '"'))
7380 else if MBTEST(character
== '$' && peek_char
== '\'')
7385 first_line
= line_number
;
7386 push_delimiter (dstack
, peek_char
);
7387 ttok
= parse_matched_pair (peek_char
, peek_char
, peek_char
,
7389 (peek_char
== '\'') ? P_ALLOWESC
: 0);
7390 pop_delimiter (dstack
);
7391 if (ttok
== &matched_pair_error
)
7393 if (peek_char
== '\'')
7396 ttrans
= ansiexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
7399 /* Insert the single quotes and correctly quote any
7400 embedded single quotes (allowed because P_ALLOWESC was
7401 passed to parse_matched_pair). */
7402 ttok
= sh_single_quote (ttrans
);
7404 ttranslen
= strlen (ttok
);
7407 #if defined (TRANSLATABLE_STRINGS)
7411 /* Try to locale-expand the converted string. */
7412 ttrans
= locale_expand (ttok
, 0, ttoklen
- 1, first_line
, &ttranslen
);
7415 /* Add the double quotes back (or single quotes if the user
7416 has set that option). */
7417 if (singlequote_translations
&&
7418 ((ttoklen
- 1) != ttranslen
|| STREQN (ttok
, ttrans
, ttranslen
) == 0))
7419 ttok
= sh_single_quote (ttrans
);
7421 ttok
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
7425 ttranslen
= strlen (ttrans
);
7427 #endif /* TRANSLATABLE_STRINGS */
7429 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttranslen
+ 1,
7431 TOKEN_DEFAULT_GROW_SIZE
);
7432 strcpy (token
+ token_index
, ttrans
);
7433 token_index
+= ttranslen
;
7436 all_digit_token
= 0;
7437 goto next_character
;
7439 /* This could eventually be extended to recognize all of the
7440 shell's single-character parameter expansions, and set flags.*/
7441 else if MBTEST(character
== '$' && peek_char
== '$')
7443 RESIZE_MALLOCED_BUFFER (token
, token_index
, 3,
7445 TOKEN_DEFAULT_GROW_SIZE
);
7446 token
[token_index
++] = '$';
7447 token
[token_index
++] = peek_char
;
7449 all_digit_token
= 0;
7450 goto next_character
;
7453 shell_ungetc (peek_char
);
7456 #if defined (ARRAY_VARS)
7457 /* Identify possible array subscript assignment; match [...]. If
7458 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7459 `sub' as if it were enclosed in double quotes. */
7460 else if MBTEST(character
== '[' && /* ] */
7461 ((token_index
> 0 && assignment_acceptable (last_read_token
) && token_is_ident (token
, token_index
)) ||
7462 (token_index
== 0 && (parser_state
&PST_COMPASSIGN
))))
7464 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, P_ARRAYSUB
);
7465 if (ttok
== &matched_pair_error
)
7466 return -1; /* Bail immediately. */
7467 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7469 TOKEN_DEFAULT_GROW_SIZE
);
7470 token
[token_index
++] = character
;
7471 strcpy (token
+ token_index
, ttok
);
7472 token_index
+= ttoklen
;
7474 all_digit_token
= 0;
7475 goto next_character
;
7477 /* Identify possible compound array variable assignment. */
7478 else if MBTEST(character
== '=' && token_index
> 0 && (assignment_acceptable (last_read_token
) || (parser_state
& PST_ASSIGNOK
)) && token_is_assignment (token
, token_index
))
7480 peek_char
= shell_getc (1);
7481 if MBTEST(peek_char
== '(') /* ) */
7483 ttok
= parse_compound_assignment (&ttoklen
);
7485 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 4,
7487 TOKEN_DEFAULT_GROW_SIZE
);
7489 token
[token_index
++] = '=';
7490 token
[token_index
++] = '(';
7493 strcpy (token
+ token_index
, ttok
);
7494 token_index
+= ttoklen
;
7496 token
[token_index
++] = ')';
7498 all_digit_token
= 0;
7499 compound_assignment
= 1;
7501 goto next_character
;
7503 goto got_token
; /* ksh93 seems to do this */
7507 shell_ungetc (peek_char
);
7511 /* When not parsing a multi-character word construct, shell meta-
7512 characters break words. */
7513 if MBTEST(shellbreak (character
))
7515 shell_ungetc (character
);
7520 if MBTEST(character
== CTLESC
|| character
== CTLNUL
)
7522 RESIZE_MALLOCED_BUFFER (token
, token_index
, 2, token_buffer_size
,
7523 TOKEN_DEFAULT_GROW_SIZE
);
7524 token
[token_index
++] = CTLESC
;
7527 got_escaped_character
:
7528 RESIZE_MALLOCED_BUFFER (token
, token_index
, 1, token_buffer_size
,
7529 TOKEN_DEFAULT_GROW_SIZE
);
7531 token
[token_index
++] = character
;
7533 all_digit_token
&= DIGIT (character
);
7534 dollar_present
|= character
== '$';
7537 if (character
== '\n' && SHOULD_PROMPT ())
7540 /* We want to remove quoted newlines (that is, a \<newline> pair)
7541 unless we are within single quotes or pass_next_character is
7542 set (the shell equivalent of literal-next). */
7543 cd
= current_delimiter (dstack
);
7544 character
= shell_getc (cd
!= '\'' && pass_next_character
== 0);
7545 } /* end for (;;) */
7549 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
7550 token
[token_index
] = '\0';
7552 /* Check to see what thing we should return. If the last_read_token
7553 is a `<', or a `&', or the character which ended this token is
7554 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7555 Otherwise, it is just a word, and should be returned as such. */
7556 if MBTEST(all_digit_token
&& (character
== '<' || character
== '>' ||
7557 last_read_token
== LESS_AND
||
7558 last_read_token
== GREATER_AND
))
7560 if (legal_number (token
, &lvalue
) && (int)lvalue
== lvalue
)
7562 yylval
.number
= lvalue
;
7567 /* Check for special case tokens. */
7568 result
= (last_shell_getc_is_singlebyte
) ? special_case_tokens (token
) : -1;
7573 /* Posix.2 does not allow reserved words to be aliased, so check for all
7574 of them, including special cases, before expanding the current token
7576 if MBTEST(posixly_correct
)
7577 CHECK_FOR_RESERVED_WORD (token
);
7579 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7580 inhibits alias expansion. */
7581 if (expand_aliases
&& quoted
== 0)
7583 result
= alias_expand_token (token
);
7584 if (result
== RE_READ_TOKEN
)
7585 return (RE_READ_TOKEN
);
7586 else if (result
== NO_EXPANSION
)
7587 parser_state
&= ~PST_ALEXPNEXT
;
7590 /* If not in Posix.2 mode, check for reserved words after alias
7592 if MBTEST(posixly_correct
== 0)
7594 CHECK_FOR_RESERVED_WORD (token
);
7596 the_word
= alloc_word_desc ();
7597 the_word
->word
= (char *)xmalloc (1 + token_index
);
7598 the_word
->flags
= 0;
7599 strcpy (the_word
->word
, token
);
7601 the_word
->flags
|= W_HASDOLLAR
;
7603 the_word
->flags
|= W_QUOTED
; /*(*/
7604 if (compound_assignment
&& token
[token_index
-1] == ')')
7605 the_word
->flags
|= W_COMPASSIGN
;
7606 /* A word is an assignment if it appears at the beginning of a
7607 simple command, or after another assignment word. This is
7608 context-dependent, so it cannot be handled in the grammar. */
7609 if (assignment (token
, (parser_state
& PST_COMPASSIGN
) != 0))
7611 the_word
->flags
|= W_ASSIGNMENT
;
7612 /* Don't perform word splitting on assignment statements. */
7613 if (assignment_acceptable (last_read_token
) || (parser_state
& PST_COMPASSIGN
) != 0)
7615 the_word
->flags
|= W_NOSPLIT
;
7616 if (parser_state
& PST_COMPASSIGN
)
7617 the_word
->flags
|= W_NOGLOB
; /* XXX - W_NOBRACE? */
7621 if (command_token_position (last_read_token
))
7624 b
= builtin_address_internal (token
, 0);
7625 if (b
&& (b
->flags
& ASSIGNMENT_BUILTIN
))
7626 parser_state
|= PST_ASSIGNOK
;
7627 else if (STREQ (token
, "eval") || STREQ (token
, "let"))
7628 parser_state
|= PST_ASSIGNOK
;
7631 yylval
.word
= the_word
;
7633 /* should we check that quoted == 0 as well? */
7634 if MBTEST(token
[0] == '{' && token
[token_index
-1] == '}' &&
7635 (character
== '<' || character
== '>'))
7637 /* can use token; already copied to the_word */
7638 token
[token_index
-1] = '\0';
7639 #if defined (ARRAY_VARS)
7640 if (legal_identifier (token
+1) || valid_array_reference (token
+1, 0))
7642 if (legal_identifier (token
+1))
7645 strcpy (the_word
->word
, token
+1);
7646 /* itrace("read_token_word: returning REDIR_WORD for %s", the_word->word); */
7647 yylval
.word
= the_word
; /* accommodate recursive call */
7648 return (REDIR_WORD
);
7651 /* valid_array_reference can call the parser recursively; need to
7652 make sure that yylval.word doesn't change if we are going to
7653 return WORD or ASSIGNMENT_WORD */
7654 yylval
.word
= the_word
;
7657 result
= ((the_word
->flags
& (W_ASSIGNMENT
|W_NOSPLIT
)) == (W_ASSIGNMENT
|W_NOSPLIT
))
7658 ? ASSIGNMENT_WORD
: WORD
;
7660 switch (last_read_token
)
7663 parser_state
|= PST_ALLOWOPNBRC
;
7664 function_dstart
= line_number
;
7669 if (word_top
< MAX_CASE_NEST
)
7671 word_lineno
[word_top
] = line_number
;
7672 expecting_in_token
++;
7679 /* Return 1 if TOKSYM is a token that after being read would allow
7680 a reserved word to be seen, else 0. */
7682 reserved_word_acceptable (toksym
)
7722 #if defined (COPROCESS_SUPPORT)
7723 if (last_read_token
== WORD
&& token_before_that
== COPROC
)
7726 if (last_read_token
== WORD
&& token_before_that
== FUNCTION
)
7732 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7733 TOKEN is not a shell reserved word. */
7735 find_reserved_word (tokstr
)
7739 for (i
= 0; word_token_alist
[i
].word
; i
++)
7740 if (STREQ (tokstr
, word_token_alist
[i
].word
))
7745 /* An interface to let the rest of the shell (primarily the completion
7746 system) know what the parser is expecting. */
7748 parser_in_command_position ()
7750 return (command_token_position (last_read_token
));
7754 #if defined (READLINE)
7755 /* Called after each time readline is called. This insures that whatever
7756 the new prompt string is gets propagated to readline's local prompt
7759 reset_readline_prompt ()
7763 if (prompt_string_pointer
)
7765 temp_prompt
= (*prompt_string_pointer
)
7766 ? decode_prompt_string (*prompt_string_pointer
)
7769 if (temp_prompt
== 0)
7771 temp_prompt
= (char *)xmalloc (1);
7772 temp_prompt
[0] = '\0';
7775 FREE (current_readline_prompt
);
7776 current_readline_prompt
= temp_prompt
;
7779 #endif /* READLINE */
7782 #if defined (HISTORY)
7783 /* A list of tokens which can be followed by newlines, but not by
7784 semi-colons. When concatenating multiple lines of history, the
7785 newline separator for such tokens is replaced with a space. */
7786 static const int no_semi_successors
[] = {
7787 '\n', '{', '(', ')', ';', '&', '|',
7788 CASE
, DO
, ELSE
, IF
, SEMI_SEMI
, SEMI_AND
, SEMI_SEMI_AND
, THEN
, UNTIL
,
7789 WHILE
, AND_AND
, OR_OR
, IN
,
7793 /* If we are not within a delimited expression, try to be smart
7794 about which separators can be semi-colons and which must be
7795 newlines. Returns the string that should be added into the
7796 history entry. LINE is the line we're about to add; it helps
7797 make some more intelligent decisions in certain cases. */
7799 history_delimiting_chars (line
)
7802 static int last_was_heredoc
= 0; /* was the last entry the start of a here document? */
7805 if ((parser_state
& PST_HEREDOC
) == 0)
7806 last_was_heredoc
= 0;
7808 if (dstack
.delimiter_depth
!= 0)
7811 /* We look for current_command_line_count == 2 because we are looking to
7812 add the first line of the body of the here document (the second line
7813 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7814 variable to note when we think we added the first line of a here doc
7815 (the one with a "<<" somewhere in it) */
7816 if (parser_state
& PST_HEREDOC
)
7818 if (last_was_heredoc
)
7820 last_was_heredoc
= 0;
7823 return (here_doc_first_line
? "\n" : "");
7826 if (parser_state
& PST_COMPASSIGN
)
7829 /* First, handle some special cases. */
7831 /* If we just read `()', assume it's a function definition, and don't
7832 add a semicolon. If the token before the `)' was not `(', and we're
7833 not in the midst of parsing a case statement, assume it's a
7834 parenthesized command and add the semicolon. */
7836 if (token_before_that
== ')')
7838 if (two_tokens_ago
== '(') /*)*/ /* function def */
7840 /* This does not work for subshells inside case statement
7841 command lists. It's a suboptimal solution. */
7842 else if (parser_state
& PST_CASESTMT
) /* case statement pattern */
7845 return "; "; /* (...) subshell */
7847 else if (token_before_that
== WORD
&& two_tokens_ago
== FUNCTION
)
7848 return " "; /* function def using `function name' without `()' */
7850 /* If we're not in a here document, but we think we're about to parse one,
7851 and we would otherwise return a `;', return a newline to delimit the
7852 line with the here-doc delimiter */
7853 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && last_read_token
== '\n' && strstr (line
, "<<"))
7855 last_was_heredoc
= 1;
7858 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && need_here_doc
> 0)
7860 else if (token_before_that
== WORD
&& two_tokens_ago
== FOR
)
7862 /* Tricky. `for i\nin ...' should not have a semicolon, but
7863 `for i\ndo ...' should. We do what we can. */
7864 for (i
= shell_input_line_index
; whitespace (shell_input_line
[i
]); i
++)
7866 if (shell_input_line
[i
] && shell_input_line
[i
] == 'i' && shell_input_line
[i
+1] == 'n')
7870 else if (two_tokens_ago
== CASE
&& token_before_that
== WORD
&& (parser_state
& PST_CASESTMT
))
7873 for (i
= 0; no_semi_successors
[i
]; i
++)
7875 if (token_before_that
== no_semi_successors
[i
])
7879 /* Assume that by this point we are reading lines in a multi-line command.
7880 If we have multiple consecutive blank lines we want to return only one
7882 if (line_isblank (line
))
7883 return (current_command_line_count
> 1 && last_read_token
== '\n' && token_before_that
!= '\n') ? "; " : "";
7887 #endif /* HISTORY */
7889 /* Issue a prompt, or prepare to issue a prompt when the next character
7892 prompt_again (force
)
7897 if (interactive
== 0 || expanding_alias ()) /* XXX */
7900 ps1_prompt
= get_string_value ("PS1");
7901 ps2_prompt
= get_string_value ("PS2");
7903 ps0_prompt
= get_string_value ("PS0");
7905 if (!prompt_string_pointer
)
7906 prompt_string_pointer
= &ps1_prompt
;
7908 temp_prompt
= *prompt_string_pointer
7909 ? decode_prompt_string (*prompt_string_pointer
)
7912 if (temp_prompt
== 0)
7914 temp_prompt
= (char *)xmalloc (1);
7915 temp_prompt
[0] = '\0';
7918 current_prompt_string
= *prompt_string_pointer
;
7919 prompt_string_pointer
= &ps2_prompt
;
7921 #if defined (READLINE)
7922 if (!no_line_editing
)
7924 FREE (current_readline_prompt
);
7925 current_readline_prompt
= temp_prompt
;
7928 #endif /* READLINE */
7930 FREE (current_decoded_prompt
);
7931 current_decoded_prompt
= temp_prompt
;
7936 get_current_prompt_level ()
7938 return ((current_prompt_string
&& current_prompt_string
== ps2_prompt
) ? 2 : 1);
7942 set_current_prompt_level (x
)
7945 prompt_string_pointer
= (x
== 2) ? &ps2_prompt
: &ps1_prompt
;
7946 current_prompt_string
= *prompt_string_pointer
;
7952 fprintf (stderr
, "%s", current_decoded_prompt
);
7956 #if defined (HISTORY)
7957 /* The history library increments the history offset as soon as it stores
7958 the first line of a potentially multi-line command, so we compensate
7959 here by returning one fewer when appropriate. */
7961 prompt_history_number (pmt
)
7966 ret
= history_number ();
7970 if (pmt
== ps1_prompt
) /* are we expanding $PS1? */
7972 else if (pmt
== ps2_prompt
&& command_oriented_history
== 0)
7973 return ret
; /* not command oriented history */
7974 else if (pmt
== ps2_prompt
&& command_oriented_history
&& current_command_first_line_saved
)
7977 return ret
- 1; /* PS0, PS4, ${var@P}, PS2 other cases */
7981 /* Return a string which will be printed as a prompt. The string
7982 may contain special characters which are decoded as follows:
7985 \d the date in Day Mon Date format
7986 \e escape (ascii 033)
7987 \h the hostname up to the first `.'
7989 \j the number of active jobs
7990 \l the basename of the shell's tty device name
7993 \s the name of the shell
7994 \t the time in 24-hour hh:mm:ss format
7995 \T the time in 12-hour hh:mm:ss format
7996 \@ the time in 12-hour hh:mm am/pm format
7997 \A the time in 24-hour hh:mm format
7998 \D{fmt} the result of passing FMT to strftime(3)
8000 \v the version of bash (e.g., 2.00)
8001 \V the release of bash, version + patchlevel (e.g., 2.00.0)
8002 \w the current working directory
8003 \W the last element of $PWD
8004 \! the history number of this command
8005 \# the command number of this command
8006 \$ a $ or a # if you are root
8007 \nnn character code nnn in octal
8009 \[ begin a sequence of non-printing chars
8010 \] end a sequence of non-printing chars
8012 #define PROMPT_GROWTH 48
8014 decode_prompt_string (string
)
8018 char *result
, *t
, *orig_string
;
8019 struct dstack save_dstack
;
8020 int last_exit_value
, last_comsub_pid
;
8021 #if defined (PROMPT_STRING_DECODE)
8023 size_t result_index
;
8025 char *temp
, *t_host
, octal_string
[4];
8031 result
= (char *)xmalloc (result_size
= PROMPT_GROWTH
);
8032 result
[result_index
= 0] = 0;
8033 temp
= (char *)NULL
;
8034 orig_string
= string
;
8036 while (c
= *string
++)
8038 if (posixly_correct
&& c
== '!')
8042 temp
= savestring ("!");
8047 #if !defined (HISTORY)
8048 temp
= savestring ("1");
8050 temp
= itos (prompt_history_number (orig_string
));
8051 #endif /* HISTORY */
8052 string
--; /* add_string increments string again. */
8070 strncpy (octal_string
, string
, 3);
8071 octal_string
[3] = '\0';
8073 n
= read_octal (octal_string
);
8074 temp
= (char *)xmalloc (3);
8076 if (n
== CTLESC
|| n
== CTLNUL
)
8093 for (c
= 0; n
!= -1 && c
< 3 && ISOCTAL (*string
); c
++)
8096 c
= 0; /* tested at add_string: */
8104 /* Make the current time/date into a string. */
8105 (void) time (&the_time
);
8106 #if defined (HAVE_TZSET)
8107 sv_tz ("TZ"); /* XXX -- just make sure */
8109 tm
= localtime (&the_time
);
8112 n
= strftime (timebuf
, sizeof (timebuf
), "%a %b %d", tm
);
8114 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M:%S", tm
);
8116 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M:%S", tm
);
8118 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M %p", tm
);
8120 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M", tm
);
8125 timebuf
[sizeof(timebuf
) - 1] = '\0';
8127 temp
= savestring (timebuf
);
8130 case 'D': /* strftime format */
8131 if (string
[1] != '{') /* } */
8134 (void) time (&the_time
);
8135 tm
= localtime (&the_time
);
8136 string
+= 2; /* skip { */
8137 timefmt
= xmalloc (strlen (string
) + 3);
8138 for (t
= timefmt
; *string
&& *string
!= '}'; )
8141 c
= *string
; /* tested at add_string */
8142 if (timefmt
[0] == '\0')
8145 timefmt
[1] = 'X'; /* locale-specific current time */
8148 n
= strftime (timebuf
, sizeof (timebuf
), timefmt
, tm
);
8154 timebuf
[sizeof(timebuf
) - 1] = '\0';
8156 if (promptvars
|| posixly_correct
)
8157 /* Make sure that expand_prompt_string is called with a
8158 second argument of Q_DOUBLE_QUOTES if we use this
8160 temp
= sh_backslash_quote_for_double_quotes (timebuf
, 0);
8162 temp
= savestring (timebuf
);
8166 temp
= (char *)xmalloc (3);
8167 temp
[0] = no_line_editing
? '\n' : '\r';
8168 temp
[1] = no_line_editing
? '\0' : '\n';
8173 temp
= base_pathname (shell_name
);
8174 /* Try to quote anything the user can set in the file system */
8175 if (promptvars
|| posixly_correct
)
8178 t
= sh_strvis (temp
);
8179 temp
= sh_backslash_quote_for_double_quotes (t
, 0);
8183 temp
= sh_strvis (temp
);
8188 temp
= (char *)xmalloc (16);
8190 strcpy (temp
, dist_version
);
8192 sprintf (temp
, "%s.%d", dist_version
, patch_level
);
8198 /* Use the value of PWD because it is much more efficient. */
8199 char t_string
[PATH_MAX
];
8202 temp
= get_string_value ("PWD");
8206 if (getcwd (t_string
, sizeof(t_string
)) == 0)
8212 tlen
= strlen (t_string
);
8216 tlen
= sizeof (t_string
) - 1;
8217 strncpy (t_string
, temp
, tlen
);
8219 t_string
[tlen
] = '\0';
8221 #if defined (MACOSX)
8222 /* Convert from "fs" format to "input" format */
8223 temp
= fnx_fromfs (t_string
, strlen (t_string
));
8224 if (temp
!= t_string
)
8225 strcpy (t_string
, temp
);
8228 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
8229 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
8230 /* Abbreviate \W as ~ if $PWD == $HOME */
8231 if (c
== 'W' && (((t
= get_string_value ("HOME")) == 0) || STREQ (t
, t_string
) == 0))
8233 if (ROOT_PATH (t_string
) == 0 && DOUBLE_SLASH_ROOT (t_string
) == 0)
8235 t
= strrchr (t_string
, '/');
8237 memmove (t_string
, t
+ 1, strlen (t
)); /* strlen(t) to copy NULL */
8241 #undef DOUBLE_SLASH_ROOT
8244 /* polite_directory_format is guaranteed to return a string
8245 no longer than PATH_MAX - 1 characters. */
8246 temp
= polite_directory_format (t_string
);
8247 if (temp
!= t_string
)
8248 strcpy (t_string
, temp
);
8251 temp
= trim_pathname (t_string
, PATH_MAX
- 1);
8252 /* If we're going to be expanding the prompt string later,
8253 quote the directory name. */
8254 if (promptvars
|| posixly_correct
)
8255 /* Make sure that expand_prompt_string is called with a
8256 second argument of Q_DOUBLE_QUOTES if we use this
8260 t
= sh_strvis (t_string
);
8261 temp
= sh_backslash_quote_for_double_quotes (t
, 0);
8265 temp
= sh_strvis (t_string
);
8271 if (current_user
.user_name
== 0)
8272 get_current_user_info ();
8273 temp
= savestring (current_user
.user_name
);
8278 t_host
= savestring (current_host_name
);
8279 if (c
== 'h' && (t
= (char *)strchr (t_host
, '.')))
8281 if (promptvars
|| posixly_correct
)
8282 /* Make sure that expand_prompt_string is called with a
8283 second argument of Q_DOUBLE_QUOTES if we use this
8285 temp
= sh_backslash_quote_for_double_quotes (t_host
, 0);
8287 temp
= savestring (t_host
);
8292 n
= current_command_number
;
8293 /* If we have already incremented current_command_number (PS4,
8294 ${var@P}), compensate */
8295 if (orig_string
!= ps0_prompt
&& orig_string
!= ps1_prompt
&& orig_string
!= ps2_prompt
)
8301 #if !defined (HISTORY)
8302 temp
= savestring ("1");
8304 temp
= itos (prompt_history_number (orig_string
));
8305 #endif /* HISTORY */
8309 t
= temp
= (char *)xmalloc (3);
8310 if ((promptvars
|| posixly_correct
) && (current_user
.euid
!= 0))
8312 *t
++ = current_user
.euid
== 0 ? '#' : '$';
8317 temp
= itos (count_all_jobs ());
8321 #if defined (HAVE_TTYNAME)
8322 temp
= (char *)ttyname (fileno (stdin
));
8323 t
= temp
? base_pathname (temp
) : "tty";
8324 temp
= savestring (t
);
8326 temp
= savestring ("tty");
8327 #endif /* !HAVE_TTYNAME */
8330 #if defined (READLINE)
8333 if (no_line_editing
)
8338 temp
= (char *)xmalloc (3);
8339 n
= (c
== '[') ? RL_PROMPT_START_IGNORE
: RL_PROMPT_END_IGNORE
;
8341 if (n
== CTLESC
|| n
== CTLNUL
)
8346 #endif /* READLINE */
8352 temp
= (char *)xmalloc (2);
8359 else /* (c == '\\') */
8366 temp
= (char *)xmalloc (3);
8375 sub_append_string (temp
, result
, &result_index
, &result_size
);
8376 temp
= (char *)NULL
; /* Freed in sub_append_string (). */
8377 result
[result_index
] = '\0';
8383 RESIZE_MALLOCED_BUFFER (result
, result_index
, 3, result_size
, PROMPT_GROWTH
);
8384 /* dequote_string should take care of removing this if we are not
8385 performing the rest of the word expansions. */
8386 if (c
== CTLESC
|| c
== CTLNUL
)
8387 result
[result_index
++] = CTLESC
;
8388 result
[result_index
++] = c
;
8389 result
[result_index
] = '\0';
8392 #else /* !PROMPT_STRING_DECODE */
8393 result
= savestring (string
);
8394 #endif /* !PROMPT_STRING_DECODE */
8396 /* Save the delimiter stack and point `dstack' to temp space so any
8397 command substitutions in the prompt string won't result in screwing
8398 up the parser's quoting state. */
8399 save_dstack
= dstack
;
8400 dstack
= temp_dstack
;
8401 dstack
.delimiter_depth
= 0;
8403 /* Perform variable and parameter expansion and command substitution on
8404 the prompt string. */
8405 if (promptvars
|| posixly_correct
)
8407 last_exit_value
= last_command_exit_value
;
8408 last_comsub_pid
= last_command_subst_pid
;
8409 list
= expand_prompt_string (result
, Q_DOUBLE_QUOTES
, 0);
8411 result
= string_list (list
);
8412 dispose_words (list
);
8413 last_command_exit_value
= last_exit_value
;
8414 last_command_subst_pid
= last_comsub_pid
;
8418 t
= dequote_string (result
);
8423 dstack
= save_dstack
;
8428 /************************************************
8432 ************************************************/
8434 /* Report a syntax error, and restart the parser. Call here for fatal
8440 if ((parser_state
& PST_NOERROR
) == 0)
8441 report_syntax_error ((char *)NULL
);
8447 error_token_from_token (tok
)
8452 if (t
= find_token_in_alist (tok
, word_token_alist
, 0))
8455 if (t
= find_token_in_alist (tok
, other_token_alist
, 0))
8459 /* This stuff is dicy and needs closer inspection */
8460 switch (current_token
)
8463 case ASSIGNMENT_WORD
:
8465 t
= savestring (yylval
.word
->word
);
8468 t
= itos (yylval
.number
);
8471 if (yylval
.word_list
)
8472 t
= string_list (yylval
.word_list
);
8474 case ARITH_FOR_EXPRS
:
8475 if (yylval
.word_list
)
8476 t
= string_list_internal (yylval
.word_list
, " ; ");
8479 t
= (char *)NULL
; /* punt */
8487 error_token_from_text ()
8492 t
= shell_input_line
;
8493 i
= shell_input_line_index
;
8497 if (i
&& t
[i
] == '\0')
8500 while (i
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8506 while (i
&& (member (t
[i
], " \n\t;|&") == 0))
8509 while (i
!= token_end
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8512 /* Return our idea of the offending token. */
8513 if (token_end
|| (i
== 0 && token_end
== 0))
8516 msg
= substring (t
, i
, token_end
);
8517 else /* one-character token */
8519 msg
= (char *)xmalloc (2);
8529 print_offending_line ()
8534 msg
= savestring (shell_input_line
);
8535 token_end
= strlen (msg
);
8536 while (token_end
&& msg
[token_end
- 1] == '\n')
8537 msg
[--token_end
] = '\0';
8539 parser_error (line_number
, "`%s'", msg
);
8543 /* Report a syntax error with line numbers, etc.
8544 Call here for recoverable errors. If you have a message to print,
8545 then place it in MESSAGE, otherwise pass NULL and this will figure
8546 out an appropriate message for you. */
8548 report_syntax_error (message
)
8555 parser_error (line_number
, "%s", message
);
8556 if (interactive
&& EOF_Reached
)
8558 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8559 set_pipestatus_from_exit (last_command_exit_value
);
8563 /* If the line of input we're reading is not null, try to find the
8564 objectionable token. First, try to figure out what token the
8565 parser's complaining about by looking at current_token. */
8566 if (current_token
!= 0 && EOF_Reached
== 0 && (msg
= error_token_from_token (current_token
)))
8568 if (ansic_shouldquote (msg
))
8570 p
= ansic_quote (msg
, 0, NULL
);
8574 parser_error (line_number
, _("syntax error near unexpected token `%s'"), msg
);
8577 if (interactive
== 0)
8578 print_offending_line ();
8580 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8581 set_pipestatus_from_exit (last_command_exit_value
);
8585 /* If looking at the current token doesn't prove fruitful, try to find the
8586 offending token by analyzing the text of the input line near the current
8587 input line index and report what we find. */
8588 if (shell_input_line
&& *shell_input_line
)
8590 msg
= error_token_from_text ();
8593 parser_error (line_number
, _("syntax error near `%s'"), msg
);
8597 /* If not interactive, print the line containing the error. */
8598 if (interactive
== 0)
8599 print_offending_line ();
8603 if (EOF_Reached
&& shell_eof_token
&& current_token
!= shell_eof_token
)
8604 parser_error (line_number
, _("unexpected EOF while looking for matching `%c'"), shell_eof_token
);
8607 msg
= EOF_Reached
? _("syntax error: unexpected end of file") : _("syntax error");
8608 parser_error (line_number
, "%s", msg
);
8611 /* When the shell is interactive, this file uses EOF_Reached
8612 only for error reporting. Other mechanisms are used to
8613 decide whether or not to exit. */
8614 if (interactive
&& EOF_Reached
)
8618 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8619 set_pipestatus_from_exit (last_command_exit_value
);
8622 /* ??? Needed function. ??? We have to be able to discard the constructs
8623 created during parsing. In the case of error, we want to return
8624 allocated objects to the memory pool. In the case of no error, we want
8625 to throw away the information about where the allocated objects live.
8626 (dispose_command () will actually free the command.) */
8628 discard_parser_constructs (error_p
)
8633 /************************************************
8637 ************************************************/
8639 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8641 /* A flag denoting whether or not ignoreeof is set. */
8644 /* The number of times that we have encountered an EOF character without
8645 another character intervening. When this gets above the limit, the
8646 shell terminates. */
8647 int eof_encountered
= 0;
8649 /* The limit for eof_encountered. */
8650 int eof_encountered_limit
= 10;
8652 /* If we have EOF as the only input unit, this user wants to leave
8653 the shell. If the shell is not interactive, then just leave.
8654 Otherwise, if ignoreeof is set, and we haven't done this the
8655 required number of times in a row, print a message. */
8657 handle_eof_input_unit ()
8661 /* shell.c may use this to decide whether or not to write out the
8662 history, among other things. We use it only for error reporting
8667 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8670 if (eof_encountered
< eof_encountered_limit
)
8672 fprintf (stderr
, _("Use \"%s\" to leave the shell.\n"),
8673 login_shell
? "logout" : "exit");
8675 /* Reset the parsing state. */
8676 last_read_token
= current_token
= '\n';
8677 /* Reset the prompt string to be $PS1. */
8678 prompt_string_pointer
= (char **)NULL
;
8684 /* In this case EOF should exit the shell. Do it now. */
8687 last_shell_builtin
= this_shell_builtin
;
8688 this_shell_builtin
= exit_builtin
;
8689 exit_builtin ((WORD_LIST
*)NULL
);
8693 /* We don't write history files, etc., for non-interactive shells. */
8698 /************************************************
8700 * STRING PARSING FUNCTIONS *
8702 ************************************************/
8704 /* It's very important that these two functions treat the characters
8705 between ( and ) identically. */
8707 static WORD_LIST parse_string_error
;
8709 /* Take a string and run it through the shell parser, returning the
8710 resultant word list. Used by compound array assignment. */
8712 parse_string_to_word_list (s
, flags
, whom
)
8718 int tok
, orig_current_token
, orig_line_number
;
8719 int orig_parser_state
;
8720 sh_parser_state_t ps
;
8723 orig_line_number
= line_number
;
8724 save_parser_state (&ps
);
8726 #if defined (HISTORY)
8727 bash_history_disable ();
8731 if (ea
= expanding_alias ())
8732 parser_save_alias ();
8734 /* WORD to avoid parsing reserved words as themselves and just parse them as
8736 last_read_token
= WORD
;
8738 current_command_line_count
= 0;
8739 echo_input_at_read
= expand_aliases
= 0;
8741 with_input_from_string (s
, whom
);
8742 wl
= (WORD_LIST
*)NULL
;
8746 orig_parser_state
= parser_state
; /* XXX - not needed? */
8747 /* State flags we don't want to persist into compound assignments. */
8748 parser_state
&= ~PST_NOEXPAND
; /* parse_comsub sentinel */
8749 /* State flags we want to set for this run through the tokenizer. */
8750 parser_state
|= PST_COMPASSIGN
|PST_REPARSE
|PST_STRING
;
8753 while ((tok
= read_token (READ
)) != yacc_EOF
)
8755 if (tok
== '\n' && *bash_input
.location
.string
== '\0')
8757 if (tok
== '\n') /* Allow newlines in compound assignments */
8759 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8761 line_number
= orig_line_number
+ line_number
- 1;
8762 orig_current_token
= current_token
;
8763 current_token
= tok
;
8764 yyerror (NULL
); /* does the right thing */
8765 current_token
= orig_current_token
;
8768 wl
= &parse_string_error
;
8771 wl
= make_word_list (yylval
.word
, wl
);
8774 last_read_token
= '\n';
8778 parser_restore_alias ();
8780 restore_parser_state (&ps
);
8783 parser_state
= orig_parser_state
; /* XXX - not needed? */
8785 if (wl
== &parse_string_error
)
8787 set_exit_status (EXECUTION_FAILURE
);
8788 if (interactive_shell
== 0 && posixly_correct
)
8789 jump_to_top_level (FORCE_EOF
);
8791 jump_to_top_level (DISCARD
);
8794 return (REVERSE_LIST (wl
, WORD_LIST
*));
8798 parse_compound_assignment (retlenp
)
8802 int tok
, orig_line_number
, assignok
;
8803 sh_parser_state_t ps
;
8806 orig_line_number
= line_number
;
8807 save_parser_state (&ps
);
8809 /* WORD to avoid parsing reserved words as themselves and just parse them as
8810 WORDs. Plus it means we won't be in a command position and so alias
8811 expansion won't happen. */
8812 last_read_token
= WORD
;
8814 token
= (char *)NULL
;
8815 token_buffer_size
= 0;
8816 wl
= (WORD_LIST
*)NULL
; /* ( */
8818 assignok
= parser_state
&PST_ASSIGNOK
; /* XXX */
8820 /* State flags we don't want to persist into compound assignments. */
8821 parser_state
&= ~(PST_NOEXPAND
|PST_CONDCMD
|PST_CONDEXPR
|PST_REGEXP
|PST_EXTPAT
);
8822 /* State flags we want to set for this run through the tokenizer. */
8823 parser_state
|= PST_COMPASSIGN
;
8825 esacs_needed_count
= expecting_in_token
= 0;
8827 while ((tok
= read_token (READ
)) != ')')
8829 if (tok
== '\n') /* Allow newlines in compound assignments */
8831 if (SHOULD_PROMPT ())
8835 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8837 current_token
= tok
; /* for error reporting */
8838 if (tok
== yacc_EOF
) /* ( */
8839 parser_error (orig_line_number
, _("unexpected EOF while looking for matching `)'"));
8841 yyerror(NULL
); /* does the right thing */
8844 wl
= &parse_string_error
;
8847 wl
= make_word_list (yylval
.word
, wl
);
8850 restore_parser_state (&ps
);
8852 if (wl
== &parse_string_error
)
8854 set_exit_status (EXECUTION_FAILURE
);
8855 last_read_token
= '\n'; /* XXX */
8856 if (interactive_shell
== 0 && posixly_correct
)
8857 jump_to_top_level (FORCE_EOF
);
8859 jump_to_top_level (DISCARD
);
8864 rl
= REVERSE_LIST (wl
, WORD_LIST
*);
8865 ret
= string_list (rl
);
8872 *retlenp
= (ret
&& *ret
) ? strlen (ret
) : 0;
8875 parser_state
|= PST_ASSIGNOK
;
8880 /************************************************
8882 * SAVING AND RESTORING PARTIAL PARSE STATE *
8884 ************************************************/
8887 save_parser_state (ps
)
8888 sh_parser_state_t
*ps
;
8891 ps
= (sh_parser_state_t
*)xmalloc (sizeof (sh_parser_state_t
));
8893 return ((sh_parser_state_t
*)NULL
);
8895 ps
->parser_state
= parser_state
;
8896 ps
->token_state
= save_token_state ();
8898 ps
->input_line_terminator
= shell_input_line_terminator
;
8899 ps
->eof_encountered
= eof_encountered
;
8900 ps
->eol_lookahead
= eol_ungetc_lookahead
;
8902 ps
->prompt_string_pointer
= prompt_string_pointer
;
8904 ps
->current_command_line_count
= current_command_line_count
;
8906 #if defined (HISTORY)
8907 ps
->remember_on_history
= remember_on_history
;
8908 # if defined (BANG_HISTORY)
8909 ps
->history_expansion_inhibited
= history_expansion_inhibited
;
8913 ps
->last_command_exit_value
= last_command_exit_value
;
8914 #if defined (ARRAY_VARS)
8915 ps
->pipestatus
= save_pipestatus_array ();
8918 ps
->last_shell_builtin
= last_shell_builtin
;
8919 ps
->this_shell_builtin
= this_shell_builtin
;
8921 ps
->expand_aliases
= expand_aliases
;
8922 ps
->echo_input_at_read
= echo_input_at_read
;
8923 ps
->need_here_doc
= need_here_doc
;
8924 ps
->here_doc_first_line
= here_doc_first_line
;
8926 ps
->esacs_needed
= esacs_needed_count
;
8927 ps
->expecting_in
= expecting_in_token
;
8929 if (need_here_doc
== 0)
8930 ps
->redir_stack
[0] = 0;
8932 memcpy (ps
->redir_stack
, redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
8934 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
8935 ps
->pushed_strings
= pushed_string_list
;
8938 ps
->eof_token
= shell_eof_token
;
8940 ps
->token_buffer_size
= token_buffer_size
;
8941 /* Force reallocation on next call to read_token_word */
8943 token_buffer_size
= 0;
8949 restore_parser_state (ps
)
8950 sh_parser_state_t
*ps
;
8957 parser_state
= ps
->parser_state
;
8958 if (ps
->token_state
)
8960 restore_token_state (ps
->token_state
);
8961 free (ps
->token_state
);
8964 shell_input_line_terminator
= ps
->input_line_terminator
;
8965 eof_encountered
= ps
->eof_encountered
;
8966 eol_ungetc_lookahead
= ps
->eol_lookahead
;
8968 prompt_string_pointer
= ps
->prompt_string_pointer
;
8970 current_command_line_count
= ps
->current_command_line_count
;
8972 #if defined (HISTORY)
8973 remember_on_history
= ps
->remember_on_history
;
8974 # if defined (BANG_HISTORY)
8975 history_expansion_inhibited
= ps
->history_expansion_inhibited
;
8979 last_command_exit_value
= ps
->last_command_exit_value
;
8980 #if defined (ARRAY_VARS)
8981 restore_pipestatus_array (ps
->pipestatus
);
8984 last_shell_builtin
= ps
->last_shell_builtin
;
8985 this_shell_builtin
= ps
->this_shell_builtin
;
8987 expand_aliases
= ps
->expand_aliases
;
8988 echo_input_at_read
= ps
->echo_input_at_read
;
8989 need_here_doc
= ps
->need_here_doc
;
8990 here_doc_first_line
= ps
->here_doc_first_line
;
8992 esacs_needed_count
= ps
->esacs_needed
;
8993 expecting_in_token
= ps
->expecting_in
;
8996 for (i
= 0; i
< HEREDOC_MAX
; i
++)
8997 redir_stack
[i
] = ps
->redir_stack
[i
];
8999 if (need_here_doc
== 0)
9002 memcpy (redir_stack
, ps
->redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
9005 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
9006 pushed_string_list
= (STRING_SAVER
*)ps
->pushed_strings
;
9011 token_buffer_size
= ps
->token_buffer_size
;
9012 shell_eof_token
= ps
->eof_token
;
9015 sh_input_line_state_t
*
9016 save_input_line_state (ls
)
9017 sh_input_line_state_t
*ls
;
9020 ls
= (sh_input_line_state_t
*)xmalloc (sizeof (sh_input_line_state_t
));
9022 return ((sh_input_line_state_t
*)NULL
);
9024 ls
->input_line
= shell_input_line
;
9025 ls
->input_line_size
= shell_input_line_size
;
9026 ls
->input_line_len
= shell_input_line_len
;
9027 ls
->input_line_index
= shell_input_line_index
;
9029 #if defined (HANDLE_MULTIBYTE)
9030 ls
->input_property
= shell_input_line_property
;
9031 ls
->input_propsize
= shell_input_line_propsize
;
9034 /* force reallocation */
9035 shell_input_line
= 0;
9036 shell_input_line_size
= shell_input_line_len
= shell_input_line_index
= 0;
9038 #if defined (HANDLE_MULTIBYTE)
9039 shell_input_line_property
= 0;
9040 shell_input_line_propsize
= 0;
9047 restore_input_line_state (ls
)
9048 sh_input_line_state_t
*ls
;
9050 FREE (shell_input_line
);
9051 shell_input_line
= ls
->input_line
;
9052 shell_input_line_size
= ls
->input_line_size
;
9053 shell_input_line_len
= ls
->input_line_len
;
9054 shell_input_line_index
= ls
->input_line_index
;
9056 #if defined (HANDLE_MULTIBYTE)
9057 FREE (shell_input_line_property
);
9058 shell_input_line_property
= ls
->input_property
;
9059 shell_input_line_propsize
= ls
->input_propsize
;
9063 set_line_mbstate ();
9067 /************************************************
9069 * MULTIBYTE CHARACTER HANDLING *
9071 ************************************************/
9073 #if defined (HANDLE_MULTIBYTE)
9075 /* We don't let the property buffer get larger than this unless the line is */
9076 #define MAX_PROPSIZE 32768
9082 size_t i
, previ
, len
;
9083 mbstate_t mbs
, prevs
;
9087 if (shell_input_line
== NULL
)
9089 len
= STRLEN (shell_input_line
); /* XXX - shell_input_line_len ? */
9092 if (shell_input_line_propsize
>= MAX_PROPSIZE
&& len
< MAX_PROPSIZE
>>1)
9094 free (shell_input_line_property
);
9095 shell_input_line_property
= 0;
9096 shell_input_line_propsize
= 0;
9098 if (len
+1 > shell_input_line_propsize
)
9100 shell_input_line_propsize
= len
+ 1;
9101 shell_input_line_property
= (char *)xrealloc (shell_input_line_property
, shell_input_line_propsize
);
9104 if (locale_mb_cur_max
== 1)
9106 memset (shell_input_line_property
, 1, len
);
9110 /* XXX - use whether or not we are in a UTF-8 locale to avoid calls to
9112 if (locale_utf8locale
== 0)
9113 memset (&prevs
, '\0', sizeof (mbstate_t));
9115 for (i
= previ
= 0; i
< len
; i
++)
9117 if (locale_utf8locale
== 0)
9120 c
= shell_input_line
[i
];
9124 for (j
= i
; j
< len
; j
++)
9125 shell_input_line_property
[j
] = 1;
9129 if (locale_utf8locale
)
9131 if ((unsigned char)shell_input_line
[previ
] < 128) /* i != previ */
9135 ilen
= utf8_mblen (shell_input_line
+ previ
, i
- previ
+ 1);
9136 mbclen
= (ilen
== -1) ? (size_t)-1
9137 : ((ilen
== -2) ? (size_t)-2 : (size_t)ilen
);
9141 mbclen
= mbrlen (shell_input_line
+ previ
, i
- previ
+ 1, &mbs
);
9143 if (mbclen
== 1 || mbclen
== (size_t)-1)
9148 else if (mbclen
== (size_t)-2)
9150 else if (mbclen
> 1)
9154 if (locale_utf8locale
== 0)
9160 for (j
= i
; j
< len
; j
++)
9161 shell_input_line_property
[j
] = 1;
9165 shell_input_line_property
[i
] = mbclen
;
9168 #endif /* HANDLE_MULTIBYTE */