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 174
1005 /* YYNSTATES -- Number of states. */
1006 #define YYNSTATES 349
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, 465, 467,
1061 471, 477, 483, 489, 495, 501, 507, 513, 519, 525,
1062 531, 537, 543, 549, 555, 561, 568, 575, 582, 589,
1063 596, 603, 609, 615, 621, 627, 633, 639, 645, 651,
1064 657, 663, 669, 675, 681, 687, 693, 699, 705, 711,
1065 717, 723, 729, 735, 743, 745, 747, 751, 755, 766,
1066 768, 772, 774, 776, 792, 794, 798, 800, 802, 804,
1067 806, 808, 810, 812, 814, 816, 818, 822, 827, 832,
1068 837, 842, 847, 852, 857, 864, 870, 876, 882, 890,
1069 895, 900, 905, 910, 915, 920, 925, 932, 937, 942,
1070 949, 951, 953, 955, 959, 961, 992, 999, 1003, 1009,
1071 1014, 1031, 1036, 1053, 1060, 1062, 1064, 1069, 1073, 1077,
1072 1081, 1083, 1085, 1089, 1090, 1094, 1096, 1098, 1100, 1104,
1073 1106, 1108, 1110, 1112, 1114, 1118, 1120, 1129, 1135, 1141,
1074 1142, 1149, 1153, 1155, 1157, 1164, 1166, 1173, 1177, 1178,
1075 1181, 1183, 1185, 1189, 1190, 1199, 1214, 1232, 1249, 1251,
1076 1253, 1260, 1263, 1267, 1269, 1275, 1281, 1301, 1324, 1326,
1077 1349, 1353, 1355, 1357, 1359
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 (-152)
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 328, 80, -152, -11, -1, 3, -152, -152, 15, 637,
1137 -5, 433, 149, -28, -152, 187, 684, -152, 18, 28,
1138 130, 38, 139, 50, 52, 60, 65, 74, -152, -152,
1139 -152, 89, 104, -152, -152, 97, -152, -152, 246, -152,
1140 670, -152, -152, -152, -152, -152, -152, -152, -152, -152,
1141 -152, -152, -152, 146, 211, -152, 1, 433, -152, -152,
1142 135, 484, -152, 59, 61, 90, 167, 171, 10, 71,
1143 246, 670, 144, -152, -152, -152, -152, -152, 165, -152,
1144 142, 179, 192, 140, 194, 160, 227, 245, 252, 253,
1145 260, 261, 262, 162, 269, 178, 270, 272, 273, 274,
1146 277, -152, -152, -152, -152, -152, -152, -152, -152, -152,
1147 -152, -152, -152, -152, -152, 168, 379, -152, -152, 173,
1148 244, -152, -152, -152, -152, 670, -152, -152, -152, -152,
1149 -152, 535, 535, -152, -152, -152, -152, -152, -152, -152,
1150 205, -152, 14, -152, 36, -152, -152, -152, -152, 84,
1151 -152, -152, -152, 249, 670, -152, 670, 670, -152, -152,
1152 -152, -152, -152, -152, -152, -152, -152, -152, -152, -152,
1153 -152, -152, -152, -152, -152, -152, -152, -152, -152, -152,
1154 -152, -152, -152, -152, -152, -152, -152, -152, -152, -152,
1155 -152, -152, -152, -152, 484, 484, 203, 203, 586, 586,
1156 145, -152, -152, -152, -152, -152, -152, 0, -152, 119,
1157 -152, 291, 248, 66, 88, -152, 119, -152, 296, 297,
1158 35, -152, 670, 670, 35, -152, -152, 1, 1, -152,
1159 -152, -152, 306, 484, 484, 484, 484, 484, 305, 169,
1160 -152, 7, -152, -152, 302, -152, 131, -152, 265, -152,
1161 -152, -152, -152, -152, -152, 304, 131, -152, 266, -152,
1162 -152, -152, 35, -152, 313, 317, -152, -152, -152, 225,
1163 225, 225, -152, -152, -152, -152, 206, 25, -152, -152,
1164 307, -42, 319, 276, -152, -152, -152, 95, -152, 322,
1165 283, 332, 284, -152, -152, 102, -152, -152, -152, -152,
1166 -152, -152, -152, -152, 45, 323, -152, -152, -152, 106,
1167 -152, -152, -152, -152, -152, -152, 109, -152, -152, 264,
1168 -152, -152, -152, 484, -152, -152, 333, 293, -152, -152,
1169 338, 300, -152, -152, -152, 484, 345, 303, -152, -152,
1170 346, 309, -152, -152, -152, -152, -152, -152, -152
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, 153, 0, 0, 0, 153, 153, 0, 0,
1179 0, 0, 171, 54, 55, 0, 0, 118, 0, 0,
1180 0, 0, 0, 0, 0, 0, 0, 0, 153, 4,
1181 7, 0, 0, 153, 153, 0, 56, 59, 61, 170,
1182 62, 66, 76, 70, 67, 64, 72, 3, 65, 71,
1183 73, 74, 75, 0, 155, 162, 163, 0, 5, 6,
1184 0, 0, 153, 153, 0, 153, 0, 0, 0, 54,
1185 113, 109, 0, 151, 150, 152, 167, 164, 172, 173,
1186 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1187 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1188 0, 16, 25, 40, 34, 49, 31, 43, 37, 46,
1189 28, 52, 53, 22, 19, 0, 0, 10, 11, 0,
1190 0, 1, 54, 60, 57, 63, 148, 149, 2, 153,
1191 153, 156, 157, 153, 153, 166, 165, 153, 154, 137,
1192 138, 147, 0, 153, 0, 153, 153, 153, 153, 0,
1193 153, 153, 153, 153, 104, 102, 111, 110, 119, 174,
1194 153, 18, 27, 42, 36, 51, 33, 45, 39, 48,
1195 30, 24, 21, 14, 15, 17, 26, 41, 35, 50,
1196 32, 44, 38, 47, 29, 23, 20, 12, 13, 107,
1197 108, 117, 106, 58, 0, 0, 160, 161, 0, 0,
1198 0, 153, 153, 153, 153, 153, 153, 0, 153, 0,
1199 153, 0, 0, 0, 0, 153, 0, 153, 0, 0,
1200 0, 153, 105, 112, 0, 158, 159, 169, 168, 153,
1201 153, 114, 0, 0, 0, 140, 141, 139, 0, 123,
1202 153, 0, 153, 153, 0, 8, 0, 153, 0, 87,
1203 88, 153, 153, 153, 153, 0, 0, 153, 0, 68,
1204 69, 103, 0, 100, 0, 0, 116, 142, 143, 144,
1205 145, 146, 99, 129, 131, 133, 124, 0, 97, 135,
1206 0, 0, 0, 0, 77, 9, 153, 0, 78, 0,
1207 0, 0, 0, 89, 153, 0, 90, 101, 115, 153,
1208 130, 132, 134, 98, 0, 0, 153, 79, 80, 0,
1209 153, 153, 85, 86, 91, 92, 0, 153, 153, 120,
1210 153, 136, 125, 126, 153, 153, 0, 0, 153, 153,
1211 0, 0, 153, 122, 127, 128, 0, 0, 83, 84,
1212 0, 0, 95, 96, 121, 81, 82, 93, 94
1215 /* YYPGOTO[NTERM-NUM]. */
1216 static const yytype_int16 yypgoto
[] =
1218 -152, -152, 112, -29, -14, -64, 360, -152, -8, -152,
1219 -152, -152, -152, -152, -151, -152, -152, -152, -152, -152,
1220 -152, -152, 13, -152, 136, -152, 98, -2, -152, 30,
1221 -152, -54, -26, -152, -123, 6, 78, -152
1224 /* YYDEFGOTO[NTERM-NUM]. */
1225 static const yytype_int16 yydefgoto
[] =
1227 0, 35, 246, 36, 37, 125, 38, 39, 40, 41,
1228 42, 43, 44, 45, 155, 46, 47, 48, 49, 50,
1229 51, 52, 232, 238, 239, 240, 281, 120, 139, 140,
1230 128, 76, 61, 53, 54, 141, 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 60, 71, 116, 135, 66, 67, 55, 157, 196, 197,
1239 147, 124, 305, 2, 242, 62, 278, 77, 3, 306,
1240 4, 5, 6, 7, 123, 63, 115, 72, 10, 65,
1241 64, 119, 80, 279, 303, 206, 142, 144, 2, 149,
1242 17, 68, 124, 3, 101, 4, 5, 6, 7, 133,
1243 208, 279, 138, 10, 102, 134, 123, 209, 243, 138,
1244 154, 156, 152, 136, 106, 17, 138, 280, 33, 261,
1245 153, 225, 226, 263, 2, 145, 110, 138, 111, 3,
1246 251, 4, 5, 6, 7, 280, 112, 138, 138, 10,
1247 222, 113, 223, 33, 210, 34, 193, 121, 215, 305,
1248 114, 17, 253, 194, 195, 216, 320, 198, 199, 310,
1249 143, 297, 73, 74, 75, 117, 317, 207, 138, 146,
1250 324, 213, 214, 328, 252, 124, 220, 124, 193, 33,
1251 118, 34, 58, 59, 224, 200, 138, 55, 55, 137,
1252 138, 148, 217, 211, 212, 245, 254, 138, 218, 219,
1253 229, 230, 231, 311, 138, 247, 103, 285, 138, 104,
1254 318, 138, 257, 158, 325, 107, 163, 329, 108, 164,
1255 73, 74, 75, 78, 79, 233, 234, 235, 236, 237,
1256 241, 150, 73, 74, 75, 151, 167, 105, 177, 168,
1257 159, 178, 286, 193, 193, 262, 109, 165, 126, 127,
1258 55, 55, 294, 160, 181, 161, 244, 182, 248, 273,
1259 274, 275, 154, 255, 277, 258, 154, 169, 162, 179,
1260 166, 287, 81, 82, 83, 84, 85, 264, 265, 189,
1261 86, 295, 191, 87, 88, 183, 129, 130, 201, 202,
1262 282, 283, 89, 90, 129, 130, 300, 301, 302, 289,
1263 290, 291, 292, 170, 154, 203, 204, 205, 201, 202,
1264 309, 131, 132, 267, 268, 269, 270, 271, 316, 332,
1265 230, 171, 122, 14, 15, 16, 227, 228, 172, 173,
1266 323, 18, 19, 20, 21, 22, 174, 175, 176, 23,
1267 24, 25, 26, 27, 335, 180, 184, 319, 185, 186,
1268 187, 31, 32, 188, 322, 192, 249, 250, 326, 327,
1269 221, 259, 260, 266, 272, 330, 331, 284, 334, 293,
1270 298, 299, 336, 337, 288, 296, 340, 341, 256, 1,
1271 344, 2, 333, 279, 307, 308, 3, 312, 4, 5,
1272 6, 7, 313, 315, 8, 9, 10, 314, 338, 321,
1273 11, 12, 339, 342, 13, 14, 15, 16, 17, 343,
1274 345, 347, 346, 18, 19, 20, 21, 22, 348, 70,
1275 0, 23, 24, 25, 26, 27, 276, 28, 304, 0,
1276 29, 30, 2, 31, 32, 0, 33, 3, 34, 4,
1277 5, 6, 7, 0, 0, 8, 9, 10, 0, 0,
1278 0, 11, 12, 0, 0, 13, 14, 15, 16, 17,
1279 0, 0, 0, 0, 18, 19, 20, 21, 22, 0,
1280 0, 0, 23, 24, 25, 26, 27, 0, 0, 0,
1281 0, 138, 0, 0, 31, 32, 2, 33, 0, 34,
1282 190, 3, 0, 4, 5, 6, 7, 0, 0, 8,
1283 9, 10, 0, 0, 0, 11, 12, 0, 0, 13,
1284 14, 15, 16, 17, 0, 0, 0, 0, 18, 19,
1285 20, 21, 22, 0, 0, 0, 23, 24, 25, 26,
1286 27, 0, 0, 0, 73, 74, 75, 2, 31, 32,
1287 0, 33, 3, 34, 4, 5, 6, 7, 0, 0,
1288 8, 9, 10, 0, 0, 0, 11, 12, 0, 0,
1289 13, 14, 15, 16, 17, 0, 0, 0, 0, 18,
1290 19, 20, 21, 22, 0, 0, 0, 23, 24, 25,
1291 26, 27, 0, 0, 0, 0, 138, 0, 2, 31,
1292 32, 0, 33, 3, 34, 4, 5, 6, 7, 0,
1293 0, 8, 9, 10, 0, 0, 0, 11, 12, 0,
1294 0, 13, 14, 15, 16, 17, 0, 0, 0, 0,
1295 18, 19, 20, 21, 22, 0, 0, 0, 23, 24,
1296 25, 26, 27, 0, 0, 0, 0, 0, 0, 2,
1297 31, 32, 0, 33, 3, 34, 4, 5, 6, 7,
1298 0, 0, 8, 9, 10, 0, 0, 0, 0, 0,
1299 0, 0, 13, 14, 15, 16, 17, 0, 0, 0,
1300 0, 18, 19, 20, 21, 22, 0, 0, 0, 23,
1301 24, 25, 26, 27, 0, 0, 0, 0, 138, 0,
1302 2, 31, 32, 0, 33, 3, 34, 4, 5, 6,
1303 7, 0, 0, 0, 0, 10, 0, 0, 0, 0,
1304 0, 0, 0, 69, 14, 15, 16, 17, 0, 0,
1305 0, 0, 18, 19, 20, 21, 22, 0, 0, 0,
1306 23, 24, 25, 26, 27, 0, 0, 0, 0, 0,
1307 0, 0, 31, 32, 0, 33, 0, 34, 15, 16,
1308 0, 0, 0, 0, 0, 18, 19, 20, 21, 22,
1309 0, 0, 0, 23, 24, 25, 26, 27, 0, 91,
1310 92, 93, 94, 95, 0, 31, 32, 96, 0, 0,
1311 97, 98, 0, 0, 0, 0, 0, 0, 0, 99,
1315 static const yytype_int16 yycheck
[] =
1317 2, 9, 28, 57, 6, 7, 0, 71, 131, 132,
1318 64, 40, 54, 3, 14, 26, 9, 11, 8, 61,
1319 10, 11, 12, 13, 38, 26, 28, 32, 18, 26,
1320 31, 33, 60, 26, 9, 21, 62, 63, 3, 65,
1321 30, 26, 71, 8, 26, 10, 11, 12, 13, 48,
1322 14, 26, 52, 18, 26, 54, 70, 21, 58, 52,
1323 68, 69, 52, 57, 26, 30, 52, 60, 58, 220,
1324 60, 194, 195, 224, 3, 14, 26, 52, 26, 8,
1325 14, 10, 11, 12, 13, 60, 26, 52, 52, 18,
1326 154, 26, 156, 58, 58, 60, 125, 0, 14, 54,
1327 26, 30, 14, 129, 130, 21, 61, 133, 134, 14,
1328 51, 262, 51, 52, 53, 26, 14, 143, 52, 58,
1329 14, 147, 148, 14, 58, 154, 152, 156, 157, 58,
1330 26, 60, 52, 53, 160, 137, 52, 131, 132, 4,
1331 52, 51, 58, 145, 146, 26, 58, 52, 150, 151,
1332 5, 6, 7, 58, 52, 209, 26, 26, 52, 29,
1333 58, 52, 216, 19, 58, 26, 26, 58, 29, 29,
1334 51, 52, 53, 24, 25, 201, 202, 203, 204, 205,
1335 206, 14, 51, 52, 53, 14, 26, 57, 26, 29,
1336 25, 29, 246, 222, 223, 221, 57, 57, 52, 53,
1337 194, 195, 256, 61, 26, 26, 208, 29, 210, 40,
1338 41, 42, 220, 215, 240, 217, 224, 57, 26, 57,
1339 26, 247, 35, 36, 37, 38, 39, 229, 230, 61,
1340 43, 257, 59, 46, 47, 57, 33, 34, 33, 34,
1341 242, 243, 55, 56, 33, 34, 40, 41, 42, 251,
1342 252, 253, 254, 26, 262, 50, 51, 52, 33, 34,
1343 286, 50, 51, 233, 234, 235, 236, 237, 294, 5,
1344 6, 26, 26, 27, 28, 29, 198, 199, 26, 26,
1345 306, 35, 36, 37, 38, 39, 26, 26, 26, 43,
1346 44, 45, 46, 47, 320, 26, 26, 299, 26, 26,
1347 26, 55, 56, 26, 306, 61, 15, 59, 310, 311,
1348 61, 15, 15, 7, 9, 317, 318, 15, 320, 15,
1349 7, 4, 324, 325, 59, 59, 328, 329, 216, 1,
1350 332, 3, 319, 26, 15, 59, 8, 15, 10, 11,
1351 12, 13, 59, 59, 16, 17, 18, 15, 15, 26,
1352 22, 23, 59, 15, 26, 27, 28, 29, 30, 59,
1353 15, 15, 59, 35, 36, 37, 38, 39, 59, 9,
1354 -1, 43, 44, 45, 46, 47, 240, 49, 280, -1,
1355 52, 53, 3, 55, 56, -1, 58, 8, 60, 10,
1356 11, 12, 13, -1, -1, 16, 17, 18, -1, -1,
1357 -1, 22, 23, -1, -1, 26, 27, 28, 29, 30,
1358 -1, -1, -1, -1, 35, 36, 37, 38, 39, -1,
1359 -1, -1, 43, 44, 45, 46, 47, -1, -1, -1,
1360 -1, 52, -1, -1, 55, 56, 3, 58, -1, 60,
1361 61, 8, -1, 10, 11, 12, 13, -1, -1, 16,
1362 17, 18, -1, -1, -1, 22, 23, -1, -1, 26,
1363 27, 28, 29, 30, -1, -1, -1, -1, 35, 36,
1364 37, 38, 39, -1, -1, -1, 43, 44, 45, 46,
1365 47, -1, -1, -1, 51, 52, 53, 3, 55, 56,
1366 -1, 58, 8, 60, 10, 11, 12, 13, -1, -1,
1367 16, 17, 18, -1, -1, -1, 22, 23, -1, -1,
1368 26, 27, 28, 29, 30, -1, -1, -1, -1, 35,
1369 36, 37, 38, 39, -1, -1, -1, 43, 44, 45,
1370 46, 47, -1, -1, -1, -1, 52, -1, 3, 55,
1371 56, -1, 58, 8, 60, 10, 11, 12, 13, -1,
1372 -1, 16, 17, 18, -1, -1, -1, 22, 23, -1,
1373 -1, 26, 27, 28, 29, 30, -1, -1, -1, -1,
1374 35, 36, 37, 38, 39, -1, -1, -1, 43, 44,
1375 45, 46, 47, -1, -1, -1, -1, -1, -1, 3,
1376 55, 56, -1, 58, 8, 60, 10, 11, 12, 13,
1377 -1, -1, 16, 17, 18, -1, -1, -1, -1, -1,
1378 -1, -1, 26, 27, 28, 29, 30, -1, -1, -1,
1379 -1, 35, 36, 37, 38, 39, -1, -1, -1, 43,
1380 44, 45, 46, 47, -1, -1, -1, -1, 52, -1,
1381 3, 55, 56, -1, 58, 8, 60, 10, 11, 12,
1382 13, -1, -1, -1, -1, 18, -1, -1, -1, -1,
1383 -1, -1, -1, 26, 27, 28, 29, 30, -1, -1,
1384 -1, -1, 35, 36, 37, 38, 39, -1, -1, -1,
1385 43, 44, 45, 46, 47, -1, -1, -1, -1, -1,
1386 -1, -1, 55, 56, -1, 58, -1, 60, 28, 29,
1387 -1, -1, -1, -1, -1, 35, 36, 37, 38, 39,
1388 -1, -1, -1, 43, 44, 45, 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, 52, 53,
1404 89, 94, 26, 26, 31, 26, 89, 89, 26, 26,
1405 68, 70, 32, 51, 52, 53, 93, 97, 24, 25,
1406 60, 35, 36, 37, 38, 39, 43, 46, 47, 55,
1407 56, 35, 36, 37, 38, 39, 43, 46, 47, 55,
1408 56, 26, 26, 26, 29, 57, 26, 26, 29, 57,
1409 26, 26, 26, 26, 26, 89, 94, 26, 26, 89,
1410 89, 0, 26, 66, 65, 67, 52, 53, 92, 33,
1411 34, 50, 51, 48, 54, 93, 97, 4, 52, 90,
1412 91, 97, 94, 51, 94, 14, 58, 93, 51, 94,
1413 14, 14, 52, 60, 70, 76, 70, 67, 19, 25,
1414 61, 26, 26, 26, 29, 57, 26, 26, 29, 57,
1415 26, 26, 26, 26, 26, 26, 26, 26, 29, 57,
1416 26, 26, 29, 57, 26, 26, 26, 26, 26, 61,
1417 61, 59, 61, 65, 94, 94, 96, 96, 94, 94,
1418 89, 33, 34, 50, 51, 52, 21, 94, 14, 21,
1419 58, 89, 89, 94, 94, 14, 21, 58, 89, 89,
1420 94, 61, 67, 67, 94, 96, 96, 98, 98, 5,
1421 6, 7, 84, 94, 94, 94, 94, 94, 85, 86,
1422 87, 94, 14, 58, 89, 26, 64, 93, 89, 15,
1423 59, 14, 58, 14, 58, 89, 64, 93, 89, 15,
1424 15, 76, 94, 76, 89, 89, 7, 91, 91, 91,
1425 91, 91, 9, 40, 41, 42, 86, 94, 9, 26,
1426 60, 88, 89, 89, 15, 26, 93, 94, 59, 89,
1427 89, 89, 89, 15, 93, 94, 59, 76, 7, 4,
1428 40, 41, 42, 9, 88, 54, 61, 15, 59, 94,
1429 14, 58, 15, 59, 15, 59, 94, 14, 58, 89,
1430 61, 26, 89, 94, 14, 58, 89, 89, 14, 58,
1431 89, 89, 5, 84, 89, 94, 89, 89, 15, 59,
1432 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, 64, 64,
1439 65, 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, 66, 66, 66, 67, 67, 68,
1444 68, 69, 69, 69, 69, 69, 70, 70, 70, 70,
1445 70, 70, 70, 70, 70, 70, 70, 71, 71, 71,
1446 71, 71, 71, 71, 71, 72, 72, 72, 72, 73,
1447 73, 73, 73, 73, 73, 73, 73, 74, 74, 74,
1448 75, 75, 75, 75, 76, 76, 77, 78, 78, 79,
1449 79, 79, 79, 79, 80, 80, 80, 81, 82, 83,
1450 84, 84, 84, 85, 85, 86, 86, 86, 86, 87,
1451 87, 87, 87, 87, 87, 88, 88, 89, 89, 90,
1452 90, 90, 91, 91, 91, 91, 91, 91, 92, 92,
1453 93, 93, 93, 94, 94, 95, 95, 95, 96, 96,
1454 96, 96, 96, 97, 97, 97, 97, 97, 98, 98,
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, 1, 1, 2,
1462 2, 2, 3, 3, 3, 3, 2, 3, 3, 2,
1463 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
1464 3, 2, 3, 3, 2, 3, 3, 2, 3, 3,
1465 2, 3, 3, 2, 3, 3, 2, 3, 3, 2,
1466 3, 3, 2, 2, 1, 1, 1, 1, 2, 1,
1467 2, 1, 1, 2, 1, 1, 1, 1, 5, 5,
1468 1, 1, 1, 1, 1, 1, 1, 6, 6, 7,
1469 7, 10, 10, 9, 9, 7, 7, 5, 5, 6,
1470 6, 7, 7, 10, 10, 9, 9, 6, 7, 6,
1471 5, 6, 3, 5, 1, 2, 3, 3, 3, 2,
1472 3, 3, 4, 2, 5, 7, 6, 3, 1, 3,
1473 4, 6, 5, 1, 2, 4, 4, 5, 5, 2,
1474 3, 2, 3, 2, 3, 1, 3, 2, 2, 3,
1475 3, 3, 4, 4, 4, 4, 4, 1, 1, 1,
1476 1, 1, 1, 0, 2, 1, 2, 2, 4, 4,
1477 3, 3, 1, 1, 2, 2, 2, 2, 4, 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: yacc_EOF */
2022 #line 456 "/usr/local/src/chet/src/bash/src/parse.y"
2024 /* Case of EOF seen by itself. Do ignoreeof or
2026 global_command
= (COMMAND
*)NULL
;
2027 handle_eof_input_unit ();
2030 #line 2031 "y.tab.c"
2033 case 8: /* word_list: WORD */
2034 #line 466 "/usr/local/src/chet/src/bash/src/parse.y"
2035 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
2036 #line 2037 "y.tab.c"
2039 case 9: /* word_list: word_list WORD */
2040 #line 468 "/usr/local/src/chet/src/bash/src/parse.y"
2041 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-1].word_list
)); }
2042 #line 2043 "y.tab.c"
2045 case 10: /* redirection: '>' WORD */
2046 #line 472 "/usr/local/src/chet/src/bash/src/parse.y"
2049 redir
.filename
= (yyvsp
[0].word
);
2050 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2052 #line 2053 "y.tab.c"
2055 case 11: /* redirection: '<' WORD */
2056 #line 478 "/usr/local/src/chet/src/bash/src/parse.y"
2059 redir
.filename
= (yyvsp
[0].word
);
2060 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2062 #line 2063 "y.tab.c"
2065 case 12: /* redirection: NUMBER '>' WORD */
2066 #line 484 "/usr/local/src/chet/src/bash/src/parse.y"
2068 source
.dest
= (yyvsp
[-2].number
);
2069 redir
.filename
= (yyvsp
[0].word
);
2070 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, 0);
2072 #line 2073 "y.tab.c"
2075 case 13: /* redirection: NUMBER '<' WORD */
2076 #line 490 "/usr/local/src/chet/src/bash/src/parse.y"
2078 source
.dest
= (yyvsp
[-2].number
);
2079 redir
.filename
= (yyvsp
[0].word
);
2080 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, 0);
2082 #line 2083 "y.tab.c"
2085 case 14: /* redirection: REDIR_WORD '>' WORD */
2086 #line 496 "/usr/local/src/chet/src/bash/src/parse.y"
2088 source
.filename
= (yyvsp
[-2].word
);
2089 redir
.filename
= (yyvsp
[0].word
);
2090 (yyval
.redirect
) = make_redirection (source
, r_output_direction
, redir
, REDIR_VARASSIGN
);
2092 #line 2093 "y.tab.c"
2095 case 15: /* redirection: REDIR_WORD '<' WORD */
2096 #line 502 "/usr/local/src/chet/src/bash/src/parse.y"
2098 source
.filename
= (yyvsp
[-2].word
);
2099 redir
.filename
= (yyvsp
[0].word
);
2100 (yyval
.redirect
) = make_redirection (source
, r_input_direction
, redir
, REDIR_VARASSIGN
);
2102 #line 2103 "y.tab.c"
2105 case 16: /* redirection: GREATER_GREATER WORD */
2106 #line 508 "/usr/local/src/chet/src/bash/src/parse.y"
2109 redir
.filename
= (yyvsp
[0].word
);
2110 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2112 #line 2113 "y.tab.c"
2115 case 17: /* redirection: NUMBER GREATER_GREATER WORD */
2116 #line 514 "/usr/local/src/chet/src/bash/src/parse.y"
2118 source
.dest
= (yyvsp
[-2].number
);
2119 redir
.filename
= (yyvsp
[0].word
);
2120 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, 0);
2122 #line 2123 "y.tab.c"
2125 case 18: /* redirection: REDIR_WORD GREATER_GREATER WORD */
2126 #line 520 "/usr/local/src/chet/src/bash/src/parse.y"
2128 source
.filename
= (yyvsp
[-2].word
);
2129 redir
.filename
= (yyvsp
[0].word
);
2130 (yyval
.redirect
) = make_redirection (source
, r_appending_to
, redir
, REDIR_VARASSIGN
);
2132 #line 2133 "y.tab.c"
2135 case 19: /* redirection: GREATER_BAR WORD */
2136 #line 526 "/usr/local/src/chet/src/bash/src/parse.y"
2139 redir
.filename
= (yyvsp
[0].word
);
2140 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2142 #line 2143 "y.tab.c"
2145 case 20: /* redirection: NUMBER GREATER_BAR WORD */
2146 #line 532 "/usr/local/src/chet/src/bash/src/parse.y"
2148 source
.dest
= (yyvsp
[-2].number
);
2149 redir
.filename
= (yyvsp
[0].word
);
2150 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, 0);
2152 #line 2153 "y.tab.c"
2155 case 21: /* redirection: REDIR_WORD GREATER_BAR WORD */
2156 #line 538 "/usr/local/src/chet/src/bash/src/parse.y"
2158 source
.filename
= (yyvsp
[-2].word
);
2159 redir
.filename
= (yyvsp
[0].word
);
2160 (yyval
.redirect
) = make_redirection (source
, r_output_force
, redir
, REDIR_VARASSIGN
);
2162 #line 2163 "y.tab.c"
2165 case 22: /* redirection: LESS_GREATER WORD */
2166 #line 544 "/usr/local/src/chet/src/bash/src/parse.y"
2169 redir
.filename
= (yyvsp
[0].word
);
2170 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2172 #line 2173 "y.tab.c"
2175 case 23: /* redirection: NUMBER LESS_GREATER WORD */
2176 #line 550 "/usr/local/src/chet/src/bash/src/parse.y"
2178 source
.dest
= (yyvsp
[-2].number
);
2179 redir
.filename
= (yyvsp
[0].word
);
2180 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, 0);
2182 #line 2183 "y.tab.c"
2185 case 24: /* redirection: REDIR_WORD LESS_GREATER WORD */
2186 #line 556 "/usr/local/src/chet/src/bash/src/parse.y"
2188 source
.filename
= (yyvsp
[-2].word
);
2189 redir
.filename
= (yyvsp
[0].word
);
2190 (yyval
.redirect
) = make_redirection (source
, r_input_output
, redir
, REDIR_VARASSIGN
);
2192 #line 2193 "y.tab.c"
2195 case 25: /* redirection: LESS_LESS WORD */
2196 #line 562 "/usr/local/src/chet/src/bash/src/parse.y"
2199 redir
.filename
= (yyvsp
[0].word
);
2200 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2201 push_heredoc ((yyval
.redirect
));
2203 #line 2204 "y.tab.c"
2206 case 26: /* redirection: NUMBER LESS_LESS WORD */
2207 #line 569 "/usr/local/src/chet/src/bash/src/parse.y"
2209 source
.dest
= (yyvsp
[-2].number
);
2210 redir
.filename
= (yyvsp
[0].word
);
2211 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, 0);
2212 push_heredoc ((yyval
.redirect
));
2214 #line 2215 "y.tab.c"
2217 case 27: /* redirection: REDIR_WORD LESS_LESS WORD */
2218 #line 576 "/usr/local/src/chet/src/bash/src/parse.y"
2220 source
.filename
= (yyvsp
[-2].word
);
2221 redir
.filename
= (yyvsp
[0].word
);
2222 (yyval
.redirect
) = make_redirection (source
, r_reading_until
, redir
, REDIR_VARASSIGN
);
2223 push_heredoc ((yyval
.redirect
));
2225 #line 2226 "y.tab.c"
2228 case 28: /* redirection: LESS_LESS_MINUS WORD */
2229 #line 583 "/usr/local/src/chet/src/bash/src/parse.y"
2232 redir
.filename
= (yyvsp
[0].word
);
2233 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2234 push_heredoc ((yyval
.redirect
));
2236 #line 2237 "y.tab.c"
2239 case 29: /* redirection: NUMBER LESS_LESS_MINUS WORD */
2240 #line 590 "/usr/local/src/chet/src/bash/src/parse.y"
2242 source
.dest
= (yyvsp
[-2].number
);
2243 redir
.filename
= (yyvsp
[0].word
);
2244 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, 0);
2245 push_heredoc ((yyval
.redirect
));
2247 #line 2248 "y.tab.c"
2250 case 30: /* redirection: REDIR_WORD LESS_LESS_MINUS WORD */
2251 #line 597 "/usr/local/src/chet/src/bash/src/parse.y"
2253 source
.filename
= (yyvsp
[-2].word
);
2254 redir
.filename
= (yyvsp
[0].word
);
2255 (yyval
.redirect
) = make_redirection (source
, r_deblank_reading_until
, redir
, REDIR_VARASSIGN
);
2256 push_heredoc ((yyval
.redirect
));
2258 #line 2259 "y.tab.c"
2261 case 31: /* redirection: LESS_LESS_LESS WORD */
2262 #line 604 "/usr/local/src/chet/src/bash/src/parse.y"
2265 redir
.filename
= (yyvsp
[0].word
);
2266 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2268 #line 2269 "y.tab.c"
2271 case 32: /* redirection: NUMBER LESS_LESS_LESS WORD */
2272 #line 610 "/usr/local/src/chet/src/bash/src/parse.y"
2274 source
.dest
= (yyvsp
[-2].number
);
2275 redir
.filename
= (yyvsp
[0].word
);
2276 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, 0);
2278 #line 2279 "y.tab.c"
2281 case 33: /* redirection: REDIR_WORD LESS_LESS_LESS WORD */
2282 #line 616 "/usr/local/src/chet/src/bash/src/parse.y"
2284 source
.filename
= (yyvsp
[-2].word
);
2285 redir
.filename
= (yyvsp
[0].word
);
2286 (yyval
.redirect
) = make_redirection (source
, r_reading_string
, redir
, REDIR_VARASSIGN
);
2288 #line 2289 "y.tab.c"
2291 case 34: /* redirection: LESS_AND NUMBER */
2292 #line 622 "/usr/local/src/chet/src/bash/src/parse.y"
2295 redir
.dest
= (yyvsp
[0].number
);
2296 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2298 #line 2299 "y.tab.c"
2301 case 35: /* redirection: NUMBER LESS_AND NUMBER */
2302 #line 628 "/usr/local/src/chet/src/bash/src/parse.y"
2304 source
.dest
= (yyvsp
[-2].number
);
2305 redir
.dest
= (yyvsp
[0].number
);
2306 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, 0);
2308 #line 2309 "y.tab.c"
2311 case 36: /* redirection: REDIR_WORD LESS_AND NUMBER */
2312 #line 634 "/usr/local/src/chet/src/bash/src/parse.y"
2314 source
.filename
= (yyvsp
[-2].word
);
2315 redir
.dest
= (yyvsp
[0].number
);
2316 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input
, redir
, REDIR_VARASSIGN
);
2318 #line 2319 "y.tab.c"
2321 case 37: /* redirection: GREATER_AND NUMBER */
2322 #line 640 "/usr/local/src/chet/src/bash/src/parse.y"
2325 redir
.dest
= (yyvsp
[0].number
);
2326 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2328 #line 2329 "y.tab.c"
2331 case 38: /* redirection: NUMBER GREATER_AND NUMBER */
2332 #line 646 "/usr/local/src/chet/src/bash/src/parse.y"
2334 source
.dest
= (yyvsp
[-2].number
);
2335 redir
.dest
= (yyvsp
[0].number
);
2336 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, 0);
2338 #line 2339 "y.tab.c"
2341 case 39: /* redirection: REDIR_WORD GREATER_AND NUMBER */
2342 #line 652 "/usr/local/src/chet/src/bash/src/parse.y"
2344 source
.filename
= (yyvsp
[-2].word
);
2345 redir
.dest
= (yyvsp
[0].number
);
2346 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output
, redir
, REDIR_VARASSIGN
);
2348 #line 2349 "y.tab.c"
2351 case 40: /* redirection: LESS_AND WORD */
2352 #line 658 "/usr/local/src/chet/src/bash/src/parse.y"
2355 redir
.filename
= (yyvsp
[0].word
);
2356 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2358 #line 2359 "y.tab.c"
2361 case 41: /* redirection: NUMBER LESS_AND WORD */
2362 #line 664 "/usr/local/src/chet/src/bash/src/parse.y"
2364 source
.dest
= (yyvsp
[-2].number
);
2365 redir
.filename
= (yyvsp
[0].word
);
2366 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, 0);
2368 #line 2369 "y.tab.c"
2371 case 42: /* redirection: REDIR_WORD LESS_AND WORD */
2372 #line 670 "/usr/local/src/chet/src/bash/src/parse.y"
2374 source
.filename
= (yyvsp
[-2].word
);
2375 redir
.filename
= (yyvsp
[0].word
);
2376 (yyval
.redirect
) = make_redirection (source
, r_duplicating_input_word
, redir
, REDIR_VARASSIGN
);
2378 #line 2379 "y.tab.c"
2381 case 43: /* redirection: GREATER_AND WORD */
2382 #line 676 "/usr/local/src/chet/src/bash/src/parse.y"
2385 redir
.filename
= (yyvsp
[0].word
);
2386 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2388 #line 2389 "y.tab.c"
2391 case 44: /* redirection: NUMBER GREATER_AND WORD */
2392 #line 682 "/usr/local/src/chet/src/bash/src/parse.y"
2394 source
.dest
= (yyvsp
[-2].number
);
2395 redir
.filename
= (yyvsp
[0].word
);
2396 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, 0);
2398 #line 2399 "y.tab.c"
2401 case 45: /* redirection: REDIR_WORD GREATER_AND WORD */
2402 #line 688 "/usr/local/src/chet/src/bash/src/parse.y"
2404 source
.filename
= (yyvsp
[-2].word
);
2405 redir
.filename
= (yyvsp
[0].word
);
2406 (yyval
.redirect
) = make_redirection (source
, r_duplicating_output_word
, redir
, REDIR_VARASSIGN
);
2408 #line 2409 "y.tab.c"
2411 case 46: /* redirection: GREATER_AND '-' */
2412 #line 694 "/usr/local/src/chet/src/bash/src/parse.y"
2416 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2418 #line 2419 "y.tab.c"
2421 case 47: /* redirection: NUMBER GREATER_AND '-' */
2422 #line 700 "/usr/local/src/chet/src/bash/src/parse.y"
2424 source
.dest
= (yyvsp
[-2].number
);
2426 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2428 #line 2429 "y.tab.c"
2431 case 48: /* redirection: REDIR_WORD GREATER_AND '-' */
2432 #line 706 "/usr/local/src/chet/src/bash/src/parse.y"
2434 source
.filename
= (yyvsp
[-2].word
);
2436 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2438 #line 2439 "y.tab.c"
2441 case 49: /* redirection: LESS_AND '-' */
2442 #line 712 "/usr/local/src/chet/src/bash/src/parse.y"
2446 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2448 #line 2449 "y.tab.c"
2451 case 50: /* redirection: NUMBER LESS_AND '-' */
2452 #line 718 "/usr/local/src/chet/src/bash/src/parse.y"
2454 source
.dest
= (yyvsp
[-2].number
);
2456 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, 0);
2458 #line 2459 "y.tab.c"
2461 case 51: /* redirection: REDIR_WORD LESS_AND '-' */
2462 #line 724 "/usr/local/src/chet/src/bash/src/parse.y"
2464 source
.filename
= (yyvsp
[-2].word
);
2466 (yyval
.redirect
) = make_redirection (source
, r_close_this
, redir
, REDIR_VARASSIGN
);
2468 #line 2469 "y.tab.c"
2471 case 52: /* redirection: AND_GREATER WORD */
2472 #line 730 "/usr/local/src/chet/src/bash/src/parse.y"
2475 redir
.filename
= (yyvsp
[0].word
);
2476 (yyval
.redirect
) = make_redirection (source
, r_err_and_out
, redir
, 0);
2478 #line 2479 "y.tab.c"
2481 case 53: /* redirection: AND_GREATER_GREATER WORD */
2482 #line 736 "/usr/local/src/chet/src/bash/src/parse.y"
2485 redir
.filename
= (yyvsp
[0].word
);
2486 (yyval
.redirect
) = make_redirection (source
, r_append_err_and_out
, redir
, 0);
2488 #line 2489 "y.tab.c"
2491 case 54: /* simple_command_element: WORD */
2492 #line 744 "/usr/local/src/chet/src/bash/src/parse.y"
2493 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2494 #line 2495 "y.tab.c"
2497 case 55: /* simple_command_element: ASSIGNMENT_WORD */
2498 #line 746 "/usr/local/src/chet/src/bash/src/parse.y"
2499 { (yyval
.element
).word
= (yyvsp
[0].word
); (yyval
.element
).redirect
= 0; }
2500 #line 2501 "y.tab.c"
2503 case 56: /* simple_command_element: redirection */
2504 #line 748 "/usr/local/src/chet/src/bash/src/parse.y"
2505 { (yyval
.element
).redirect
= (yyvsp
[0].redirect
); (yyval
.element
).word
= 0; }
2506 #line 2507 "y.tab.c"
2509 case 57: /* redirection_list: redirection */
2510 #line 752 "/usr/local/src/chet/src/bash/src/parse.y"
2512 (yyval
.redirect
) = (yyvsp
[0].redirect
);
2514 #line 2515 "y.tab.c"
2517 case 58: /* redirection_list: redirection_list redirection */
2518 #line 756 "/usr/local/src/chet/src/bash/src/parse.y"
2520 register REDIRECT
*t
;
2522 for (t
= (yyvsp
[-1].redirect
); t
->next
; t
= t
->next
)
2524 t
->next
= (yyvsp
[0].redirect
);
2525 (yyval
.redirect
) = (yyvsp
[-1].redirect
);
2527 #line 2528 "y.tab.c"
2530 case 59: /* simple_command: simple_command_element */
2531 #line 767 "/usr/local/src/chet/src/bash/src/parse.y"
2532 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (COMMAND
*)NULL
); }
2533 #line 2534 "y.tab.c"
2536 case 60: /* simple_command: simple_command simple_command_element */
2537 #line 769 "/usr/local/src/chet/src/bash/src/parse.y"
2538 { (yyval
.command
) = make_simple_command ((yyvsp
[0].element
), (yyvsp
[-1].command
)); }
2539 #line 2540 "y.tab.c"
2542 case 61: /* command: simple_command */
2543 #line 773 "/usr/local/src/chet/src/bash/src/parse.y"
2544 { (yyval
.command
) = clean_simple_command ((yyvsp
[0].command
)); }
2545 #line 2546 "y.tab.c"
2548 case 62: /* command: shell_command */
2549 #line 775 "/usr/local/src/chet/src/bash/src/parse.y"
2550 { (yyval
.command
) = (yyvsp
[0].command
); }
2551 #line 2552 "y.tab.c"
2554 case 63: /* command: shell_command redirection_list */
2555 #line 777 "/usr/local/src/chet/src/bash/src/parse.y"
2559 tc
= (yyvsp
[-1].command
);
2560 if (tc
&& tc
->redirects
)
2562 register REDIRECT
*t
;
2563 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2565 t
->next
= (yyvsp
[0].redirect
);
2568 tc
->redirects
= (yyvsp
[0].redirect
);
2569 (yyval
.command
) = (yyvsp
[-1].command
);
2571 #line 2572 "y.tab.c"
2574 case 64: /* command: function_def */
2575 #line 793 "/usr/local/src/chet/src/bash/src/parse.y"
2576 { (yyval
.command
) = (yyvsp
[0].command
); }
2577 #line 2578 "y.tab.c"
2580 case 65: /* command: coproc */
2581 #line 795 "/usr/local/src/chet/src/bash/src/parse.y"
2582 { (yyval
.command
) = (yyvsp
[0].command
); }
2583 #line 2584 "y.tab.c"
2586 case 66: /* shell_command: for_command */
2587 #line 799 "/usr/local/src/chet/src/bash/src/parse.y"
2588 { (yyval
.command
) = (yyvsp
[0].command
); }
2589 #line 2590 "y.tab.c"
2592 case 67: /* shell_command: case_command */
2593 #line 801 "/usr/local/src/chet/src/bash/src/parse.y"
2594 { (yyval
.command
) = (yyvsp
[0].command
); }
2595 #line 2596 "y.tab.c"
2598 case 68: /* shell_command: WHILE compound_list DO compound_list DONE */
2599 #line 803 "/usr/local/src/chet/src/bash/src/parse.y"
2600 { (yyval
.command
) = make_while_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2601 #line 2602 "y.tab.c"
2604 case 69: /* shell_command: UNTIL compound_list DO compound_list DONE */
2605 #line 805 "/usr/local/src/chet/src/bash/src/parse.y"
2606 { (yyval
.command
) = make_until_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
2607 #line 2608 "y.tab.c"
2610 case 70: /* shell_command: select_command */
2611 #line 807 "/usr/local/src/chet/src/bash/src/parse.y"
2612 { (yyval
.command
) = (yyvsp
[0].command
); }
2613 #line 2614 "y.tab.c"
2616 case 71: /* shell_command: if_command */
2617 #line 809 "/usr/local/src/chet/src/bash/src/parse.y"
2618 { (yyval
.command
) = (yyvsp
[0].command
); }
2619 #line 2620 "y.tab.c"
2622 case 72: /* shell_command: subshell */
2623 #line 811 "/usr/local/src/chet/src/bash/src/parse.y"
2624 { (yyval
.command
) = (yyvsp
[0].command
); }
2625 #line 2626 "y.tab.c"
2628 case 73: /* shell_command: group_command */
2629 #line 813 "/usr/local/src/chet/src/bash/src/parse.y"
2630 { (yyval
.command
) = (yyvsp
[0].command
); }
2631 #line 2632 "y.tab.c"
2634 case 74: /* shell_command: arith_command */
2635 #line 815 "/usr/local/src/chet/src/bash/src/parse.y"
2636 { (yyval
.command
) = (yyvsp
[0].command
); }
2637 #line 2638 "y.tab.c"
2640 case 75: /* shell_command: cond_command */
2641 #line 817 "/usr/local/src/chet/src/bash/src/parse.y"
2642 { (yyval
.command
) = (yyvsp
[0].command
); }
2643 #line 2644 "y.tab.c"
2646 case 76: /* shell_command: arith_for_command */
2647 #line 819 "/usr/local/src/chet/src/bash/src/parse.y"
2648 { (yyval
.command
) = (yyvsp
[0].command
); }
2649 #line 2650 "y.tab.c"
2652 case 77: /* for_command: FOR WORD newline_list DO compound_list DONE */
2653 #line 823 "/usr/local/src/chet/src/bash/src/parse.y"
2655 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2656 if (word_top
> 0) word_top
--;
2658 #line 2659 "y.tab.c"
2661 case 78: /* for_command: FOR WORD newline_list '{' compound_list '}' */
2662 #line 828 "/usr/local/src/chet/src/bash/src/parse.y"
2664 (yyval
.command
) = make_for_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2665 if (word_top
> 0) word_top
--;
2667 #line 2668 "y.tab.c"
2670 case 79: /* for_command: FOR WORD ';' newline_list DO compound_list DONE */
2671 #line 833 "/usr/local/src/chet/src/bash/src/parse.y"
2673 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2674 if (word_top
> 0) word_top
--;
2676 #line 2677 "y.tab.c"
2679 case 80: /* for_command: FOR WORD ';' newline_list '{' compound_list '}' */
2680 #line 838 "/usr/local/src/chet/src/bash/src/parse.y"
2682 (yyval
.command
) = make_for_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2683 if (word_top
> 0) word_top
--;
2685 #line 2686 "y.tab.c"
2688 case 81: /* for_command: FOR WORD newline_list IN word_list list_terminator newline_list DO compound_list DONE */
2689 #line 843 "/usr/local/src/chet/src/bash/src/parse.y"
2691 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2692 if (word_top
> 0) word_top
--;
2694 #line 2695 "y.tab.c"
2697 case 82: /* for_command: FOR WORD newline_list IN word_list list_terminator newline_list '{' compound_list '}' */
2698 #line 848 "/usr/local/src/chet/src/bash/src/parse.y"
2700 (yyval
.command
) = make_for_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2701 if (word_top
> 0) word_top
--;
2703 #line 2704 "y.tab.c"
2706 case 83: /* for_command: FOR WORD newline_list IN list_terminator newline_list DO compound_list DONE */
2707 #line 853 "/usr/local/src/chet/src/bash/src/parse.y"
2709 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2710 if (word_top
> 0) word_top
--;
2712 #line 2713 "y.tab.c"
2715 case 84: /* for_command: FOR WORD newline_list IN list_terminator newline_list '{' compound_list '}' */
2716 #line 858 "/usr/local/src/chet/src/bash/src/parse.y"
2718 (yyval
.command
) = make_for_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2719 if (word_top
> 0) word_top
--;
2721 #line 2722 "y.tab.c"
2724 case 85: /* arith_for_command: FOR ARITH_FOR_EXPRS list_terminator newline_list DO compound_list DONE */
2725 #line 865 "/usr/local/src/chet/src/bash/src/parse.y"
2727 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2728 if ((yyval
.command
) == 0) YYERROR
;
2729 if (word_top
> 0) word_top
--;
2731 #line 2732 "y.tab.c"
2734 case 86: /* arith_for_command: FOR ARITH_FOR_EXPRS list_terminator newline_list '{' compound_list '}' */
2735 #line 871 "/usr/local/src/chet/src/bash/src/parse.y"
2737 (yyval
.command
) = make_arith_for_command ((yyvsp
[-5].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2738 if ((yyval
.command
) == 0) YYERROR
;
2739 if (word_top
> 0) word_top
--;
2741 #line 2742 "y.tab.c"
2744 case 87: /* arith_for_command: FOR ARITH_FOR_EXPRS DO compound_list DONE */
2745 #line 877 "/usr/local/src/chet/src/bash/src/parse.y"
2747 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2748 if ((yyval
.command
) == 0) YYERROR
;
2749 if (word_top
> 0) word_top
--;
2751 #line 2752 "y.tab.c"
2754 case 88: /* arith_for_command: FOR ARITH_FOR_EXPRS '{' compound_list '}' */
2755 #line 883 "/usr/local/src/chet/src/bash/src/parse.y"
2757 (yyval
.command
) = make_arith_for_command ((yyvsp
[-3].word_list
), (yyvsp
[-1].command
), arith_for_lineno
);
2758 if ((yyval
.command
) == 0) YYERROR
;
2759 if (word_top
> 0) word_top
--;
2761 #line 2762 "y.tab.c"
2764 case 89: /* select_command: SELECT WORD newline_list DO compound_list DONE */
2765 #line 891 "/usr/local/src/chet/src/bash/src/parse.y"
2767 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2768 if (word_top
> 0) word_top
--;
2770 #line 2771 "y.tab.c"
2773 case 90: /* select_command: SELECT WORD newline_list '{' compound_list '}' */
2774 #line 896 "/usr/local/src/chet/src/bash/src/parse.y"
2776 (yyval
.command
) = make_select_command ((yyvsp
[-4].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2777 if (word_top
> 0) word_top
--;
2779 #line 2780 "y.tab.c"
2782 case 91: /* select_command: SELECT WORD ';' newline_list DO compound_list DONE */
2783 #line 901 "/usr/local/src/chet/src/bash/src/parse.y"
2785 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2786 if (word_top
> 0) word_top
--;
2788 #line 2789 "y.tab.c"
2791 case 92: /* select_command: SELECT WORD ';' newline_list '{' compound_list '}' */
2792 #line 906 "/usr/local/src/chet/src/bash/src/parse.y"
2794 (yyval
.command
) = make_select_command ((yyvsp
[-5].word
), add_string_to_list ("\"$@\"", (WORD_LIST
*)NULL
), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2795 if (word_top
> 0) word_top
--;
2797 #line 2798 "y.tab.c"
2800 case 93: /* select_command: SELECT WORD newline_list IN word_list list_terminator newline_list DO compound_list DONE */
2801 #line 911 "/usr/local/src/chet/src/bash/src/parse.y"
2803 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2804 if (word_top
> 0) word_top
--;
2806 #line 2807 "y.tab.c"
2809 case 94: /* select_command: SELECT WORD newline_list IN word_list list_terminator newline_list '{' compound_list '}' */
2810 #line 916 "/usr/local/src/chet/src/bash/src/parse.y"
2812 (yyval
.command
) = make_select_command ((yyvsp
[-8].word
), REVERSE_LIST ((yyvsp
[-5].word_list
), WORD_LIST
*), (yyvsp
[-1].command
), word_lineno
[word_top
]);
2813 if (word_top
> 0) word_top
--;
2815 #line 2816 "y.tab.c"
2818 case 95: /* select_command: SELECT WORD newline_list IN list_terminator newline_list DO compound_list DONE */
2819 #line 921 "/usr/local/src/chet/src/bash/src/parse.y"
2821 (yyval
.command
) = make_select_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2822 if (word_top
> 0) word_top
--;
2824 #line 2825 "y.tab.c"
2827 case 96: /* select_command: SELECT WORD newline_list IN list_terminator newline_list '{' compound_list '}' */
2828 #line 926 "/usr/local/src/chet/src/bash/src/parse.y"
2830 (yyval
.command
) = make_select_command ((yyvsp
[-7].word
), (WORD_LIST
*)NULL
, (yyvsp
[-1].command
), word_lineno
[word_top
]);
2831 if (word_top
> 0) word_top
--;
2833 #line 2834 "y.tab.c"
2836 case 97: /* case_command: CASE WORD newline_list IN newline_list ESAC */
2837 #line 933 "/usr/local/src/chet/src/bash/src/parse.y"
2839 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (PATTERN_LIST
*)NULL
, word_lineno
[word_top
]);
2840 if (word_top
> 0) word_top
--;
2842 #line 2843 "y.tab.c"
2845 case 98: /* case_command: CASE WORD newline_list IN case_clause_sequence newline_list ESAC */
2846 #line 938 "/usr/local/src/chet/src/bash/src/parse.y"
2848 (yyval
.command
) = make_case_command ((yyvsp
[-5].word
), (yyvsp
[-2].pattern
), word_lineno
[word_top
]);
2849 if (word_top
> 0) word_top
--;
2851 #line 2852 "y.tab.c"
2854 case 99: /* case_command: CASE WORD newline_list IN case_clause ESAC */
2855 #line 943 "/usr/local/src/chet/src/bash/src/parse.y"
2857 (yyval
.command
) = make_case_command ((yyvsp
[-4].word
), (yyvsp
[-1].pattern
), word_lineno
[word_top
]);
2858 if (word_top
> 0) word_top
--;
2860 #line 2861 "y.tab.c"
2863 case 100: /* function_def: WORD '(' ')' newline_list function_body */
2864 #line 950 "/usr/local/src/chet/src/bash/src/parse.y"
2865 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2866 #line 2867 "y.tab.c"
2869 case 101: /* function_def: FUNCTION WORD '(' ')' newline_list function_body */
2870 #line 952 "/usr/local/src/chet/src/bash/src/parse.y"
2871 { (yyval
.command
) = make_function_def ((yyvsp
[-4].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2872 #line 2873 "y.tab.c"
2875 case 102: /* function_def: FUNCTION WORD function_body */
2876 #line 954 "/usr/local/src/chet/src/bash/src/parse.y"
2877 { (yyval
.command
) = make_function_def ((yyvsp
[-1].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2878 #line 2879 "y.tab.c"
2881 case 103: /* function_def: FUNCTION WORD '\n' newline_list function_body */
2882 #line 956 "/usr/local/src/chet/src/bash/src/parse.y"
2883 { (yyval
.command
) = make_function_def ((yyvsp
[-3].word
), (yyvsp
[0].command
), function_dstart
, function_bstart
); }
2884 #line 2885 "y.tab.c"
2887 case 104: /* function_body: shell_command */
2888 #line 960 "/usr/local/src/chet/src/bash/src/parse.y"
2889 { (yyval
.command
) = (yyvsp
[0].command
); }
2890 #line 2891 "y.tab.c"
2893 case 105: /* function_body: shell_command redirection_list */
2894 #line 962 "/usr/local/src/chet/src/bash/src/parse.y"
2898 tc
= (yyvsp
[-1].command
);
2899 /* According to Posix.2 3.9.5, redirections
2900 specified after the body of a function should
2901 be attached to the function and performed when
2902 the function is executed, not as part of the
2903 function definition command. */
2904 /* XXX - I don't think it matters, but we might
2905 want to change this in the future to avoid
2906 problems differentiating between a function
2907 definition with a redirection and a function
2908 definition containing a single command with a
2909 redirection. The two are semantically equivalent,
2910 though -- the only difference is in how the
2911 command printing code displays the redirections. */
2912 if (tc
&& tc
->redirects
)
2914 register REDIRECT
*t
;
2915 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2917 t
->next
= (yyvsp
[0].redirect
);
2920 tc
->redirects
= (yyvsp
[0].redirect
);
2921 (yyval
.command
) = (yyvsp
[-1].command
);
2923 #line 2924 "y.tab.c"
2926 case 106: /* subshell: '(' compound_list ')' */
2927 #line 993 "/usr/local/src/chet/src/bash/src/parse.y"
2929 (yyval
.command
) = make_subshell_command ((yyvsp
[-1].command
));
2930 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
;
2932 #line 2933 "y.tab.c"
2935 case 107: /* comsub: DOLPAREN compound_list ')' */
2936 #line 1000 "/usr/local/src/chet/src/bash/src/parse.y"
2938 (yyval
.command
) = (yyvsp
[-1].command
);
2940 #line 2941 "y.tab.c"
2943 case 108: /* comsub: DOLPAREN newline_list ')' */
2944 #line 1004 "/usr/local/src/chet/src/bash/src/parse.y"
2946 (yyval
.command
) = (COMMAND
*)NULL
;
2948 #line 2949 "y.tab.c"
2951 case 109: /* coproc: COPROC shell_command */
2952 #line 1010 "/usr/local/src/chet/src/bash/src/parse.y"
2954 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[0].command
));
2955 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2957 #line 2958 "y.tab.c"
2960 case 110: /* coproc: COPROC shell_command redirection_list */
2961 #line 1015 "/usr/local/src/chet/src/bash/src/parse.y"
2965 tc
= (yyvsp
[-1].command
);
2966 if (tc
&& tc
->redirects
)
2968 register REDIRECT
*t
;
2969 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
2971 t
->next
= (yyvsp
[0].redirect
);
2974 tc
->redirects
= (yyvsp
[0].redirect
);
2975 (yyval
.command
) = make_coproc_command ("COPROC", (yyvsp
[-1].command
));
2976 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2978 #line 2979 "y.tab.c"
2981 case 111: /* coproc: COPROC WORD shell_command */
2982 #line 1032 "/usr/local/src/chet/src/bash/src/parse.y"
2984 (yyval
.command
) = make_coproc_command ((yyvsp
[-1].word
)->word
, (yyvsp
[0].command
));
2985 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
2987 #line 2988 "y.tab.c"
2990 case 112: /* coproc: COPROC WORD shell_command redirection_list */
2991 #line 1037 "/usr/local/src/chet/src/bash/src/parse.y"
2995 tc
= (yyvsp
[-1].command
);
2996 if (tc
&& tc
->redirects
)
2998 register REDIRECT
*t
;
2999 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
3001 t
->next
= (yyvsp
[0].redirect
);
3004 tc
->redirects
= (yyvsp
[0].redirect
);
3005 (yyval
.command
) = make_coproc_command ((yyvsp
[-2].word
)->word
, (yyvsp
[-1].command
));
3006 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
3008 #line 3009 "y.tab.c"
3011 case 113: /* coproc: COPROC simple_command */
3012 #line 1054 "/usr/local/src/chet/src/bash/src/parse.y"
3014 (yyval
.command
) = make_coproc_command ("COPROC", clean_simple_command ((yyvsp
[0].command
)));
3015 (yyval
.command
)->flags
|= CMD_WANT_SUBSHELL
|CMD_COPROC_SUBSHELL
;
3017 #line 3018 "y.tab.c"
3020 case 114: /* if_command: IF compound_list THEN compound_list FI */
3021 #line 1061 "/usr/local/src/chet/src/bash/src/parse.y"
3022 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (COMMAND
*)NULL
); }
3023 #line 3024 "y.tab.c"
3026 case 115: /* if_command: IF compound_list THEN compound_list ELSE compound_list FI */
3027 #line 1063 "/usr/local/src/chet/src/bash/src/parse.y"
3028 { (yyval
.command
) = make_if_command ((yyvsp
[-5].command
), (yyvsp
[-3].command
), (yyvsp
[-1].command
)); }
3029 #line 3030 "y.tab.c"
3032 case 116: /* if_command: IF compound_list THEN compound_list elif_clause FI */
3033 #line 1065 "/usr/local/src/chet/src/bash/src/parse.y"
3034 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[-1].command
)); }
3035 #line 3036 "y.tab.c"
3038 case 117: /* group_command: '{' compound_list '}' */
3039 #line 1070 "/usr/local/src/chet/src/bash/src/parse.y"
3040 { (yyval
.command
) = make_group_command ((yyvsp
[-1].command
)); }
3041 #line 3042 "y.tab.c"
3044 case 118: /* arith_command: ARITH_CMD */
3045 #line 1074 "/usr/local/src/chet/src/bash/src/parse.y"
3046 { (yyval
.command
) = make_arith_command ((yyvsp
[0].word_list
)); }
3047 #line 3048 "y.tab.c"
3050 case 119: /* cond_command: COND_START COND_CMD COND_END */
3051 #line 1078 "/usr/local/src/chet/src/bash/src/parse.y"
3052 { (yyval
.command
) = (yyvsp
[-1].command
); }
3053 #line 3054 "y.tab.c"
3056 case 120: /* elif_clause: ELIF compound_list THEN compound_list */
3057 #line 1082 "/usr/local/src/chet/src/bash/src/parse.y"
3058 { (yyval
.command
) = make_if_command ((yyvsp
[-2].command
), (yyvsp
[0].command
), (COMMAND
*)NULL
); }
3059 #line 3060 "y.tab.c"
3062 case 121: /* elif_clause: ELIF compound_list THEN compound_list ELSE compound_list */
3063 #line 1084 "/usr/local/src/chet/src/bash/src/parse.y"
3064 { (yyval
.command
) = make_if_command ((yyvsp
[-4].command
), (yyvsp
[-2].command
), (yyvsp
[0].command
)); }
3065 #line 3066 "y.tab.c"
3068 case 122: /* elif_clause: ELIF compound_list THEN compound_list elif_clause */
3069 #line 1086 "/usr/local/src/chet/src/bash/src/parse.y"
3070 { (yyval
.command
) = make_if_command ((yyvsp
[-3].command
), (yyvsp
[-1].command
), (yyvsp
[0].command
)); }
3071 #line 3072 "y.tab.c"
3074 case 124: /* case_clause: case_clause_sequence pattern_list */
3075 #line 1091 "/usr/local/src/chet/src/bash/src/parse.y"
3076 { (yyvsp
[0].pattern
)->next
= (yyvsp
[-1].pattern
); (yyval
.pattern
) = (yyvsp
[0].pattern
); }
3077 #line 3078 "y.tab.c"
3080 case 125: /* pattern_list: newline_list pattern ')' compound_list */
3081 #line 1095 "/usr/local/src/chet/src/bash/src/parse.y"
3082 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
3083 #line 3084 "y.tab.c"
3086 case 126: /* pattern_list: newline_list pattern ')' newline_list */
3087 #line 1097 "/usr/local/src/chet/src/bash/src/parse.y"
3088 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
3089 #line 3090 "y.tab.c"
3092 case 127: /* pattern_list: newline_list '(' pattern ')' compound_list */
3093 #line 1099 "/usr/local/src/chet/src/bash/src/parse.y"
3094 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (yyvsp
[0].command
)); }
3095 #line 3096 "y.tab.c"
3098 case 128: /* pattern_list: newline_list '(' pattern ')' newline_list */
3099 #line 1101 "/usr/local/src/chet/src/bash/src/parse.y"
3100 { (yyval
.pattern
) = make_pattern_list ((yyvsp
[-2].word_list
), (COMMAND
*)NULL
); }
3101 #line 3102 "y.tab.c"
3104 case 129: /* case_clause_sequence: pattern_list SEMI_SEMI */
3105 #line 1105 "/usr/local/src/chet/src/bash/src/parse.y"
3106 { (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3107 #line 3108 "y.tab.c"
3110 case 130: /* case_clause_sequence: case_clause_sequence pattern_list SEMI_SEMI */
3111 #line 1107 "/usr/local/src/chet/src/bash/src/parse.y"
3112 { (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3113 #line 3114 "y.tab.c"
3116 case 131: /* case_clause_sequence: pattern_list SEMI_AND */
3117 #line 1109 "/usr/local/src/chet/src/bash/src/parse.y"
3118 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3119 #line 3120 "y.tab.c"
3122 case 132: /* case_clause_sequence: case_clause_sequence pattern_list SEMI_AND */
3123 #line 1111 "/usr/local/src/chet/src/bash/src/parse.y"
3124 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_FALLTHROUGH
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3125 #line 3126 "y.tab.c"
3128 case 133: /* case_clause_sequence: pattern_list SEMI_SEMI_AND */
3129 #line 1113 "/usr/local/src/chet/src/bash/src/parse.y"
3130 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3131 #line 3132 "y.tab.c"
3134 case 134: /* case_clause_sequence: case_clause_sequence pattern_list SEMI_SEMI_AND */
3135 #line 1115 "/usr/local/src/chet/src/bash/src/parse.y"
3136 { (yyvsp
[-1].pattern
)->flags
|= CASEPAT_TESTNEXT
; (yyvsp
[-1].pattern
)->next
= (yyvsp
[-2].pattern
); (yyval
.pattern
) = (yyvsp
[-1].pattern
); }
3137 #line 3138 "y.tab.c"
3140 case 135: /* pattern: WORD */
3141 #line 1119 "/usr/local/src/chet/src/bash/src/parse.y"
3142 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (WORD_LIST
*)NULL
); }
3143 #line 3144 "y.tab.c"
3146 case 136: /* pattern: pattern '|' WORD */
3147 #line 1121 "/usr/local/src/chet/src/bash/src/parse.y"
3148 { (yyval
.word_list
) = make_word_list ((yyvsp
[0].word
), (yyvsp
[-2].word_list
)); }
3149 #line 3150 "y.tab.c"
3152 case 137: /* compound_list: newline_list list0 */
3153 #line 1130 "/usr/local/src/chet/src/bash/src/parse.y"
3155 (yyval
.command
) = (yyvsp
[0].command
);
3156 if (need_here_doc
&& last_read_token
== '\n')
3157 gather_here_documents ();
3159 #line 3160 "y.tab.c"
3162 case 138: /* compound_list: newline_list list1 */
3163 #line 1136 "/usr/local/src/chet/src/bash/src/parse.y"
3165 (yyval
.command
) = (yyvsp
[0].command
);
3167 #line 3168 "y.tab.c"
3170 case 140: /* list0: list1 '&' newline_list */
3171 #line 1143 "/usr/local/src/chet/src/bash/src/parse.y"
3173 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3174 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3176 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (COMMAND
*)NULL
, '&');
3178 #line 3179 "y.tab.c"
3181 case 142: /* list1: list1 AND_AND newline_list list1 */
3182 #line 1154 "/usr/local/src/chet/src/bash/src/parse.y"
3183 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3184 #line 3185 "y.tab.c"
3187 case 143: /* list1: list1 OR_OR newline_list list1 */
3188 #line 1156 "/usr/local/src/chet/src/bash/src/parse.y"
3189 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3190 #line 3191 "y.tab.c"
3193 case 144: /* list1: list1 '&' newline_list list1 */
3194 #line 1158 "/usr/local/src/chet/src/bash/src/parse.y"
3196 if ((yyvsp
[-3].command
)->type
== cm_connection
)
3197 (yyval
.command
) = connect_async_list ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3199 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '&');
3201 #line 3202 "y.tab.c"
3204 case 145: /* list1: list1 ';' newline_list list1 */
3205 #line 1165 "/usr/local/src/chet/src/bash/src/parse.y"
3206 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';'); }
3207 #line 3208 "y.tab.c"
3210 case 146: /* list1: list1 '\n' newline_list list1 */
3211 #line 1167 "/usr/local/src/chet/src/bash/src/parse.y"
3213 if (parser_state
& PST_CMDSUBST
)
3214 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '\n');
3216 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), ';');
3218 #line 3219 "y.tab.c"
3221 case 147: /* list1: pipeline_command */
3222 #line 1174 "/usr/local/src/chet/src/bash/src/parse.y"
3223 { (yyval
.command
) = (yyvsp
[0].command
); }
3224 #line 3225 "y.tab.c"
3227 case 150: /* list_terminator: '\n' */
3228 #line 1182 "/usr/local/src/chet/src/bash/src/parse.y"
3229 { (yyval
.number
) = '\n'; }
3230 #line 3231 "y.tab.c"
3233 case 151: /* list_terminator: ';' */
3234 #line 1184 "/usr/local/src/chet/src/bash/src/parse.y"
3235 { (yyval
.number
) = ';'; }
3236 #line 3237 "y.tab.c"
3239 case 152: /* list_terminator: yacc_EOF */
3240 #line 1186 "/usr/local/src/chet/src/bash/src/parse.y"
3241 { (yyval
.number
) = yacc_EOF
; }
3242 #line 3243 "y.tab.c"
3245 case 155: /* simple_list: simple_list1 */
3246 #line 1200 "/usr/local/src/chet/src/bash/src/parse.y"
3248 (yyval
.command
) = (yyvsp
[0].command
);
3250 gather_here_documents (); /* XXX */
3251 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3253 INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 -> simple_list"));
3254 global_command
= (yyvsp
[0].command
);
3255 eof_encountered
= 0;
3256 if (bash_input
.type
== st_string
)
3257 rewind_input_string ();
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 if ((yyvsp
[-1].command
)->type
== cm_connection
)
3268 (yyval
.command
) = connect_async_list ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3270 (yyval
.command
) = command_connect ((yyvsp
[-1].command
), (COMMAND
*)NULL
, '&');
3272 gather_here_documents (); /* XXX */
3273 if ((parser_state
& PST_CMDSUBST
) && current_token
== shell_eof_token
)
3275 INTERNAL_DEBUG (("LEGACY: parser: command substitution simple_list1 '&' -> simple_list"));
3276 global_command
= (yyvsp
[-1].command
);
3277 eof_encountered
= 0;
3278 if (bash_input
.type
== st_string
)
3279 rewind_input_string ();
3283 #line 3284 "y.tab.c"
3286 case 157: /* simple_list: simple_list1 ';' */
3287 #line 1233 "/usr/local/src/chet/src/bash/src/parse.y"
3289 (yyval
.command
) = (yyvsp
[-1].command
);
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_list1: simple_list1 AND_AND newline_list simple_list1 */
3306 #line 1250 "/usr/local/src/chet/src/bash/src/parse.y"
3307 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), AND_AND
); }
3308 #line 3309 "y.tab.c"
3311 case 159: /* simple_list1: simple_list1 OR_OR newline_list simple_list1 */
3312 #line 1252 "/usr/local/src/chet/src/bash/src/parse.y"
3313 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), OR_OR
); }
3314 #line 3315 "y.tab.c"
3317 case 160: /* simple_list1: simple_list1 '&' simple_list1 */
3318 #line 1254 "/usr/local/src/chet/src/bash/src/parse.y"
3320 if ((yyvsp
[-2].command
)->type
== cm_connection
)
3321 (yyval
.command
) = connect_async_list ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3323 (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), '&');
3325 #line 3326 "y.tab.c"
3328 case 161: /* simple_list1: simple_list1 ';' simple_list1 */
3329 #line 1261 "/usr/local/src/chet/src/bash/src/parse.y"
3330 { (yyval
.command
) = command_connect ((yyvsp
[-2].command
), (yyvsp
[0].command
), ';'); }
3331 #line 3332 "y.tab.c"
3334 case 162: /* simple_list1: pipeline_command */
3335 #line 1264 "/usr/local/src/chet/src/bash/src/parse.y"
3336 { (yyval
.command
) = (yyvsp
[0].command
); }
3337 #line 3338 "y.tab.c"
3340 case 163: /* pipeline_command: pipeline */
3341 #line 1268 "/usr/local/src/chet/src/bash/src/parse.y"
3342 { (yyval
.command
) = (yyvsp
[0].command
); }
3343 #line 3344 "y.tab.c"
3346 case 164: /* pipeline_command: BANG pipeline_command */
3347 #line 1270 "/usr/local/src/chet/src/bash/src/parse.y"
3349 if ((yyvsp
[0].command
))
3350 (yyvsp
[0].command
)->flags
^= CMD_INVERT_RETURN
; /* toggle */
3351 (yyval
.command
) = (yyvsp
[0].command
);
3353 #line 3354 "y.tab.c"
3356 case 165: /* pipeline_command: timespec pipeline_command */
3357 #line 1276 "/usr/local/src/chet/src/bash/src/parse.y"
3359 if ((yyvsp
[0].command
))
3360 (yyvsp
[0].command
)->flags
|= (yyvsp
[-1].number
);
3361 (yyval
.command
) = (yyvsp
[0].command
);
3363 #line 3364 "y.tab.c"
3366 case 166: /* pipeline_command: timespec list_terminator */
3367 #line 1282 "/usr/local/src/chet/src/bash/src/parse.y"
3371 /* Boy, this is unclean. `time' by itself can
3372 time a null command. We cheat and push a
3373 newline back if the list_terminator was a newline
3374 to avoid the double-newline problem (one to
3375 terminate this, one to terminate the command) */
3378 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3379 (yyval
.command
)->flags
|= (yyvsp
[-1].number
);
3380 /* XXX - let's cheat and push a newline back */
3381 if ((yyvsp
[0].number
) == '\n')
3382 token_to_read
= '\n';
3383 else if ((yyvsp
[0].number
) == ';')
3384 token_to_read
= ';';
3385 parser_state
&= ~PST_REDIRLIST
; /* make_simple_command sets this */
3387 #line 3388 "y.tab.c"
3390 case 167: /* pipeline_command: BANG list_terminator */
3391 #line 1302 "/usr/local/src/chet/src/bash/src/parse.y"
3395 /* This is just as unclean. Posix says that `!'
3396 by itself should be equivalent to `false'.
3398 newline back if the list_terminator was a newline
3399 to avoid the double-newline problem (one to
3400 terminate this, one to terminate the command) */
3403 (yyval
.command
) = make_simple_command (x
, (COMMAND
*)NULL
);
3404 (yyval
.command
)->flags
|= CMD_INVERT_RETURN
;
3405 /* XXX - let's cheat and push a newline back */
3406 if ((yyvsp
[0].number
) == '\n')
3407 token_to_read
= '\n';
3408 if ((yyvsp
[0].number
) == ';')
3409 token_to_read
= ';';
3410 parser_state
&= ~PST_REDIRLIST
; /* make_simple_command sets this */
3412 #line 3413 "y.tab.c"
3415 case 168: /* pipeline: pipeline '|' newline_list pipeline */
3416 #line 1325 "/usr/local/src/chet/src/bash/src/parse.y"
3417 { (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|'); }
3418 #line 3419 "y.tab.c"
3421 case 169: /* pipeline: pipeline BAR_AND newline_list pipeline */
3422 #line 1327 "/usr/local/src/chet/src/bash/src/parse.y"
3424 /* Make cmd1 |& cmd2 equivalent to cmd1 2>&1 | cmd2 */
3429 tc
= (yyvsp
[-3].command
)->type
== cm_simple
? (COMMAND
*)(yyvsp
[-3].command
)->value
.Simple
: (yyvsp
[-3].command
);
3432 r
= make_redirection (sd
, r_duplicating_output
, rd
, 0);
3435 register REDIRECT
*t
;
3436 for (t
= tc
->redirects
; t
->next
; t
= t
->next
)
3443 (yyval
.command
) = command_connect ((yyvsp
[-3].command
), (yyvsp
[0].command
), '|');
3445 #line 3446 "y.tab.c"
3448 case 170: /* pipeline: command */
3449 #line 1350 "/usr/local/src/chet/src/bash/src/parse.y"
3450 { (yyval
.command
) = (yyvsp
[0].command
); }
3451 #line 3452 "y.tab.c"
3454 case 171: /* timespec: TIME */
3455 #line 1354 "/usr/local/src/chet/src/bash/src/parse.y"
3456 { (yyval
.number
) = CMD_TIME_PIPELINE
; }
3457 #line 3458 "y.tab.c"
3460 case 172: /* timespec: TIME TIMEOPT */
3461 #line 1356 "/usr/local/src/chet/src/bash/src/parse.y"
3462 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3463 #line 3464 "y.tab.c"
3466 case 173: /* timespec: TIME TIMEIGN */
3467 #line 1358 "/usr/local/src/chet/src/bash/src/parse.y"
3468 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3469 #line 3470 "y.tab.c"
3472 case 174: /* timespec: TIME TIMEOPT TIMEIGN */
3473 #line 1360 "/usr/local/src/chet/src/bash/src/parse.y"
3474 { (yyval
.number
) = CMD_TIME_PIPELINE
|CMD_TIME_POSIX
; }
3475 #line 3476 "y.tab.c"
3479 #line 3480 "y.tab.c"
3483 /* User semantic actions sometimes alter yychar, and that requires
3484 that yytoken be updated with the new translation. We take the
3485 approach of translating immediately before every use of yytoken.
3486 One alternative is translating here after every semantic action,
3487 but that translation would be missed if the semantic action invokes
3488 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
3489 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
3490 incorrect destructor might then be invoked immediately. In the
3491 case of YYERROR or YYBACKUP, subsequent parser actions might lead
3492 to an incorrect destructor call or verbose syntax error message
3493 before the lookahead is translated. */
3494 YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t
, yyr1
[yyn
]), &yyval
, &yyloc
);
3501 /* Now 'shift' the result of the reduction. Determine what state
3502 that goes to, based on the state we popped back to and the rule
3503 number reduced by. */
3505 const int yylhs
= yyr1
[yyn
] - YYNTOKENS
;
3506 const int yyi
= yypgoto
[yylhs
] + *yyssp
;
3507 yystate
= (0 <= yyi
&& yyi
<= YYLAST
&& yycheck
[yyi
] == *yyssp
3509 : yydefgoto
[yylhs
]);
3515 /*--------------------------------------.
3516 | yyerrlab -- here on detecting error. |
3517 `--------------------------------------*/
3519 /* Make sure we have latest lookahead translation. See comments at
3520 user semantic actions for why this is necessary. */
3521 yytoken
= yychar
== YYEMPTY
? YYSYMBOL_YYEMPTY
: YYTRANSLATE (yychar
);
3522 /* If not already recovering from an error, report this error. */
3526 yyerror (YY_("syntax error"));
3529 if (yyerrstatus
== 3)
3531 /* If just tried and failed to reuse lookahead token after an
3532 error, discard it. */
3534 if (yychar
<= YYEOF
)
3536 /* Return failure if at end of input. */
3537 if (yychar
== YYEOF
)
3542 yydestruct ("Error: discarding",
3548 /* Else will try to reuse lookahead token after shifting the error
3553 /*---------------------------------------------------.
3554 | yyerrorlab -- error raised explicitly by YYERROR. |
3555 `---------------------------------------------------*/
3557 /* Pacify compilers when the user code never invokes YYERROR and the
3558 label yyerrorlab therefore never appears in user code. */
3563 /* Do not reclaim the symbols of the rule whose action triggered
3567 YY_STACK_PRINT (yyss
, yyssp
);
3572 /*-------------------------------------------------------------.
3573 | yyerrlab1 -- common code for both syntax error and YYERROR. |
3574 `-------------------------------------------------------------*/
3576 yyerrstatus
= 3; /* Each real token shifted decrements this. */
3578 /* Pop stack until we find a state that shifts the error token. */
3581 yyn
= yypact
[yystate
];
3582 if (!yypact_value_is_default (yyn
))
3584 yyn
+= YYSYMBOL_YYerror
;
3585 if (0 <= yyn
&& yyn
<= YYLAST
&& yycheck
[yyn
] == YYSYMBOL_YYerror
)
3593 /* Pop the current state because it cannot handle the error token. */
3598 yydestruct ("Error: popping",
3599 YY_ACCESSING_SYMBOL (yystate
), yyvsp
);
3602 YY_STACK_PRINT (yyss
, yyssp
);
3605 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
3607 YY_IGNORE_MAYBE_UNINITIALIZED_END
3610 /* Shift the error token. */
3611 YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn
), yyvsp
, yylsp
);
3617 /*-------------------------------------.
3618 | yyacceptlab -- YYACCEPT comes here. |
3619 `-------------------------------------*/
3625 /*-----------------------------------.
3626 | yyabortlab -- YYABORT comes here. |
3627 `-----------------------------------*/
3633 /*-----------------------------------------------------------.
3634 | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
3635 `-----------------------------------------------------------*/
3637 yyerror (YY_("memory exhausted"));
3642 /*----------------------------------------------------------.
3643 | yyreturnlab -- parsing is finished, clean up and return. |
3644 `----------------------------------------------------------*/
3646 if (yychar
!= YYEMPTY
)
3648 /* Make sure we have latest lookahead translation. See comments at
3649 user semantic actions for why this is necessary. */
3650 yytoken
= YYTRANSLATE (yychar
);
3651 yydestruct ("Cleanup: discarding lookahead",
3654 /* Do not reclaim the symbols of the rule whose action triggered
3655 this YYABORT or YYACCEPT. */
3657 YY_STACK_PRINT (yyss
, yyssp
);
3658 while (yyssp
!= yyss
)
3660 yydestruct ("Cleanup: popping",
3661 YY_ACCESSING_SYMBOL (+*yyssp
), yyvsp
);
3666 YYSTACK_FREE (yyss
);
3672 #line 1362 "/usr/local/src/chet/src/bash/src/parse.y"
3675 /* Initial size to allocate for tokens, and the
3676 amount to grow them by. */
3677 #define TOKEN_DEFAULT_INITIAL_SIZE 496
3678 #define TOKEN_DEFAULT_GROW_SIZE 512
3680 /* Should we call prompt_again? */
3681 #define SHOULD_PROMPT() \
3682 (interactive && (bash_input.type == st_stdin || bash_input.type == st_stream))
3685 # define expanding_alias() (pushed_string_list && pushed_string_list->expander)
3687 # define expanding_alias() 0
3690 /* Global var is non-zero when end of file has been reached. */
3691 int EOF_Reached
= 0;
3700 yyoutstream
= stdout
;
3701 yyerrstream
= stderr
;
3706 /* yy_getc () returns the next available character from input or EOF.
3707 yy_ungetc (c) makes `c' the next character to read.
3708 init_yy_io (get, unget, type, location) makes the function GET the
3709 installed function for getting the next character, makes UNGET the
3710 installed function for un-getting a character, sets the type of stream
3711 (either string or file) from TYPE, and makes LOCATION point to where
3712 the input is coming from. */
3714 /* Unconditionally returns end-of-file. */
3721 /* Variable containing the current get and unget functions.
3722 See ./input.h for a clearer description. */
3723 BASH_INPUT bash_input
;
3725 /* Set all of the fields in BASH_INPUT to NULL. Free bash_input.name if it
3726 is non-null, avoiding a memory leak. */
3728 initialize_bash_input ()
3730 bash_input
.type
= st_none
;
3731 FREE (bash_input
.name
);
3732 bash_input
.name
= (char *)NULL
;
3733 bash_input
.location
.file
= (FILE *)NULL
;
3734 bash_input
.location
.string
= (char *)NULL
;
3735 bash_input
.getter
= (sh_cget_func_t
*)NULL
;
3736 bash_input
.ungetter
= (sh_cunget_func_t
*)NULL
;
3739 /* Set the contents of the current bash input stream from
3740 GET, UNGET, TYPE, NAME, and LOCATION. */
3742 init_yy_io (get
, unget
, type
, name
, location
)
3743 sh_cget_func_t
*get
;
3744 sh_cunget_func_t
*unget
;
3745 enum stream_type type
;
3747 INPUT_STREAM location
;
3749 bash_input
.type
= type
;
3750 FREE (bash_input
.name
);
3751 bash_input
.name
= name
? savestring (name
) : (char *)NULL
;
3755 memcpy((char *)&bash_input
.location
.string
, (char *)&location
.string
, sizeof(location
));
3757 bash_input
.location
= location
;
3759 bash_input
.getter
= get
;
3760 bash_input
.ungetter
= unget
;
3766 return (bash_input
.name
? bash_input
.name
: "stdin");
3769 /* Call this to get the next character of input. */
3773 return (*(bash_input
.getter
)) ();
3776 /* Call this to unget C. That is, to make C the next character
3782 return (*(bash_input
.ungetter
)) (c
);
3785 #if defined (BUFFERED_INPUT)
3786 #ifdef INCLUDE_UNUSED
3788 input_file_descriptor ()
3790 switch (bash_input
.type
)
3793 return (fileno (bash_input
.location
.file
));
3795 return (bash_input
.location
.buffered_fd
);
3798 return (fileno (stdin
));
3802 #endif /* BUFFERED_INPUT */
3804 /* **************************************************************** */
3806 /* Let input be read from readline (). */
3808 /* **************************************************************** */
3810 #if defined (READLINE)
3811 char *current_readline_prompt
= (char *)NULL
;
3812 char *current_readline_line
= (char *)NULL
;
3813 int current_readline_line_index
= 0;
3818 SigHandler
*old_sigint
;
3822 if (current_readline_line
== 0)
3824 if (bash_readline_initialized
== 0)
3825 initialize_readline ();
3827 #if defined (JOB_CONTROL)
3829 give_terminal_to (shell_pgrp
, 0);
3830 #endif /* JOB_CONTROL */
3832 old_sigint
= IMPOSSIBLE_TRAP_HANDLER
;
3833 if (signal_is_ignored (SIGINT
) == 0)
3835 old_sigint
= (SigHandler
*)set_signal_handler (SIGINT
, sigint_sighandler
);
3838 sh_unset_nodelay_mode (fileno (rl_instream
)); /* just in case */
3839 current_readline_line
= readline (current_readline_prompt
?
3840 current_readline_prompt
: "");
3843 if (signal_is_ignored (SIGINT
) == 0)
3845 if (old_sigint
!= IMPOSSIBLE_TRAP_HANDLER
)
3846 set_signal_handler (SIGINT
, old_sigint
);
3850 /* Reset the prompt to the decoded value of prompt_string_pointer. */
3851 reset_readline_prompt ();
3854 if (current_readline_line
== 0)
3857 current_readline_line_index
= 0;
3858 line_len
= strlen (current_readline_line
);
3860 current_readline_line
= (char *)xrealloc (current_readline_line
, 2 + line_len
);
3861 current_readline_line
[line_len
++] = '\n';
3862 current_readline_line
[line_len
] = '\0';
3865 if (current_readline_line
[current_readline_line_index
] == 0)
3867 free (current_readline_line
);
3868 current_readline_line
= (char *)NULL
;
3869 return (yy_readline_get ());
3873 c
= current_readline_line
[current_readline_line_index
++];
3879 yy_readline_unget (c
)
3882 if (current_readline_line_index
&& current_readline_line
)
3883 current_readline_line
[--current_readline_line_index
] = c
;
3888 with_input_from_stdin ()
3890 INPUT_STREAM location
;
3892 if (bash_input
.type
!= st_stdin
&& stream_on_stack (st_stdin
) == 0)
3894 location
.string
= current_readline_line
;
3895 init_yy_io (yy_readline_get
, yy_readline_unget
,
3896 st_stdin
, "readline stdin", location
);
3900 /* Will we be collecting another input line and printing a prompt? This uses
3901 different conditions than SHOULD_PROMPT(), since readline allows a user to
3902 embed a newline in the middle of the line it collects, which the parser
3903 will interpret as a line break and command delimiter. */
3905 parser_will_prompt ()
3907 return (current_readline_line
== 0 || current_readline_line
[current_readline_line_index
] == 0);
3910 #else /* !READLINE */
3913 with_input_from_stdin ()
3915 with_input_from_stream (stdin
, "stdin");
3917 #endif /* !READLINE */
3919 /* **************************************************************** */
3921 /* Let input come from STRING. STRING is zero terminated. */
3923 /* **************************************************************** */
3928 register char *string
;
3929 register unsigned char c
;
3931 string
= bash_input
.location
.string
;
3933 /* If the string doesn't exist, or is empty, EOF found. */
3934 if (string
&& *string
)
3937 bash_input
.location
.string
= string
;
3948 *(--bash_input
.location
.string
) = c
;
3953 with_input_from_string (string
, name
)
3957 INPUT_STREAM location
;
3959 location
.string
= string
;
3960 init_yy_io (yy_string_get
, yy_string_unget
, st_string
, name
, location
);
3963 /* Count the number of characters we've consumed from bash_input.location.string
3964 and read into shell_input_line, but have not returned from shell_getc.
3965 That is the true input location. Rewind bash_input.location.string by
3966 that number of characters, so it points to the last character actually
3967 consumed by the parser. */
3969 rewind_input_string ()
3973 /* number of unconsumed characters in the input -- XXX need to take newlines
3974 into account, e.g., $(...\n) */
3975 xchars
= shell_input_line_len
- shell_input_line_index
;
3976 if (bash_input
.location
.string
[-1] == '\n')
3979 /* XXX - how to reflect bash_input.location.string back to string passed to
3980 parse_and_execute or xparse_dolparen? xparse_dolparen needs to know how
3981 far into the string we parsed. parse_and_execute knows where bash_input.
3982 location.string is, and how far from orig_string that is -- that's the
3983 number of characters the command consumed. */
3985 /* bash_input.location.string - xchars should be where we parsed to */
3986 /* need to do more validation on xchars value for sanity -- test cases. */
3987 bash_input
.location
.string
-= xchars
;
3990 /* **************************************************************** */
3992 /* Let input come from STREAM. */
3994 /* **************************************************************** */
3996 /* These two functions used to test the value of the HAVE_RESTARTABLE_SYSCALLS
3997 define, and just use getc/ungetc if it was defined, but since bash
3998 installs most of its signal handlers without the SA_RESTART flag, some
3999 signals received during a read(2) will not cause the read to be restarted.
4000 We will need to restart it ourselves. */
4008 if (bash_input
.location
.file
)
4010 /* XXX - don't need terminate_immediately; getc_with_restart checks
4011 for terminating signals itself if read returns < 0 */
4012 result
= getc_with_restart (bash_input
.location
.file
);
4021 return (ungetc_with_restart (c
, bash_input
.location
.file
));
4025 with_input_from_stream (stream
, name
)
4029 INPUT_STREAM location
;
4031 location
.file
= stream
;
4032 init_yy_io (yy_stream_get
, yy_stream_unget
, st_stream
, name
, location
);
4035 typedef struct stream_saver
{
4036 struct stream_saver
*next
;
4037 BASH_INPUT bash_input
;
4039 #if defined (BUFFERED_INPUT)
4040 BUFFERED_STREAM
*bstream
;
4041 #endif /* BUFFERED_INPUT */
4044 /* The globally known line number. */
4045 int line_number
= 0;
4047 /* The line number offset set by assigning to LINENO. Not currently used. */
4048 int line_number_base
= 0;
4050 #if defined (COND_COMMAND)
4051 static int cond_lineno
;
4052 static int cond_token
;
4055 STREAM_SAVER
*stream_list
= (STREAM_SAVER
*)NULL
;
4058 push_stream (reset_lineno
)
4061 STREAM_SAVER
*saver
= (STREAM_SAVER
*)xmalloc (sizeof (STREAM_SAVER
));
4063 xbcopy ((char *)&bash_input
, (char *)&(saver
->bash_input
), sizeof (BASH_INPUT
));
4065 #if defined (BUFFERED_INPUT)
4066 saver
->bstream
= (BUFFERED_STREAM
*)NULL
;
4067 /* If we have a buffered stream, clear out buffers[fd]. */
4068 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4069 saver
->bstream
= set_buffered_stream (bash_input
.location
.buffered_fd
,
4070 (BUFFERED_STREAM
*)NULL
);
4071 #endif /* BUFFERED_INPUT */
4073 saver
->line
= line_number
;
4074 bash_input
.name
= (char *)NULL
;
4075 saver
->next
= stream_list
;
4076 stream_list
= saver
;
4089 STREAM_SAVER
*saver
= stream_list
;
4092 stream_list
= stream_list
->next
;
4094 init_yy_io (saver
->bash_input
.getter
,
4095 saver
->bash_input
.ungetter
,
4096 saver
->bash_input
.type
,
4097 saver
->bash_input
.name
,
4098 saver
->bash_input
.location
);
4100 #if defined (BUFFERED_INPUT)
4101 /* If we have a buffered stream, restore buffers[fd]. */
4102 /* If the input file descriptor was changed while this was on the
4103 save stack, update the buffered fd to the new file descriptor and
4104 re-establish the buffer <-> bash_input fd correspondence. */
4105 if (bash_input
.type
== st_bstream
&& bash_input
.location
.buffered_fd
>= 0)
4107 if (bash_input_fd_changed
)
4109 bash_input_fd_changed
= 0;
4110 if (default_buffered_input
>= 0)
4112 bash_input
.location
.buffered_fd
= default_buffered_input
;
4113 saver
->bstream
->b_fd
= default_buffered_input
;
4114 SET_CLOSE_ON_EXEC (default_buffered_input
);
4117 /* XXX could free buffered stream returned as result here. */
4118 set_buffered_stream (bash_input
.location
.buffered_fd
, saver
->bstream
);
4120 #endif /* BUFFERED_INPUT */
4122 line_number
= saver
->line
;
4124 FREE (saver
->bash_input
.name
);
4129 /* Return 1 if a stream of type TYPE is saved on the stack. */
4131 stream_on_stack (type
)
4132 enum stream_type type
;
4134 register STREAM_SAVER
*s
;
4136 for (s
= stream_list
; s
; s
= s
->next
)
4137 if (s
->bash_input
.type
== type
)
4142 /* Save the current token state and return it in a malloced array. */
4148 ret
= (int *)xmalloc (4 * sizeof (int));
4149 ret
[0] = last_read_token
;
4150 ret
[1] = token_before_that
;
4151 ret
[2] = two_tokens_ago
;
4152 ret
[3] = current_token
;
4157 restore_token_state (ts
)
4162 last_read_token
= ts
[0];
4163 token_before_that
= ts
[1];
4164 two_tokens_ago
= ts
[2];
4165 current_token
= ts
[3];
4169 * This is used to inhibit alias expansion and reserved word recognition
4170 * inside case statement pattern lists. A `case statement pattern list' is:
4172 * everything between the `in' in a `case word in' and the next ')'
4174 * everything between a `;;' and the next `)' or `esac'
4177 #define END_OF_ALIAS 0
4180 * Pseudo-global variables used in implementing token-wise alias expansion.
4184 * Pushing and popping strings. This works together with shell_getc to
4185 * implement alias expansion on a per-token basis.
4188 #define PSH_ALIAS 0x01
4189 #define PSH_DPAREN 0x02
4190 #define PSH_SOURCE 0x04
4191 #define PSH_ARRAY 0x08
4193 typedef struct string_saver
{
4194 struct string_saver
*next
;
4195 int expand_alias
; /* Value to set expand_alias to when string is popped. */
4198 alias_t
*expander
; /* alias that caused this line to be pushed. */
4200 size_t saved_line_size
, saved_line_index
, saved_line_len
;
4201 int saved_line_terminator
;
4205 STRING_SAVER
*pushed_string_list
= (STRING_SAVER
*)NULL
;
4208 * Push the current shell_input_line onto a stack of such lines and make S
4209 * the current input. Used when expanding aliases. EXPAND is used to set
4210 * the value of expand_next_token when the string is popped, so that the
4211 * word after the alias in the original line is handled correctly when the
4212 * alias expands to multiple words. TOKEN is the token that was expanded
4213 * into S; it is saved and used to prevent infinite recursive expansion.
4216 push_string (s
, expand
, ap
)
4221 STRING_SAVER
*temp
= (STRING_SAVER
*)xmalloc (sizeof (STRING_SAVER
));
4223 temp
->expand_alias
= expand
;
4224 temp
->saved_line
= shell_input_line
;
4225 temp
->saved_line_size
= shell_input_line_size
;
4226 temp
->saved_line_len
= shell_input_line_len
;
4227 temp
->saved_line_index
= shell_input_line_index
;
4228 temp
->saved_line_terminator
= shell_input_line_terminator
;
4231 temp
->expander
= ap
;
4233 temp
->flags
= PSH_ALIAS
;
4235 temp
->next
= pushed_string_list
;
4236 pushed_string_list
= temp
;
4240 ap
->flags
|= AL_BEINGEXPANDED
;
4243 shell_input_line
= s
;
4244 shell_input_line_size
= shell_input_line_len
= STRLEN (s
);
4245 shell_input_line_index
= 0;
4246 shell_input_line_terminator
= '\0';
4248 parser_state
&= ~PST_ALEXPNEXT
; /* XXX */
4251 set_line_mbstate ();
4255 * Make the top of the pushed_string stack be the current shell input.
4256 * Only called when there is something on the stack. Called from shell_getc
4257 * when it thinks it has consumed the string generated by an alias expansion
4258 * and needs to return to the original input line.
4265 FREE (shell_input_line
);
4266 shell_input_line
= pushed_string_list
->saved_line
;
4267 shell_input_line_index
= pushed_string_list
->saved_line_index
;
4268 shell_input_line_size
= pushed_string_list
->saved_line_size
;
4269 shell_input_line_len
= pushed_string_list
->saved_line_len
;
4270 shell_input_line_terminator
= pushed_string_list
->saved_line_terminator
;
4273 if (pushed_string_list
->expand_alias
)
4274 parser_state
|= PST_ALEXPNEXT
;
4276 parser_state
&= ~PST_ALEXPNEXT
;
4279 t
= pushed_string_list
;
4280 pushed_string_list
= pushed_string_list
->next
;
4284 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4289 set_line_mbstate ();
4295 register STRING_SAVER
*t
, *t1
;
4297 for (t
= pushed_string_list
; t
; )
4300 FREE (t
->saved_line
);
4303 t
->expander
->flags
&= ~AL_BEINGEXPANDED
;
4308 pushed_string_list
= (STRING_SAVER
*)NULL
;
4312 free_pushed_string_input ()
4314 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4315 free_string_list ();
4320 parser_expanding_alias ()
4322 return (expanding_alias ());
4326 parser_save_alias ()
4328 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4329 push_string ((char *)NULL
, 0, (alias_t
*)NULL
);
4330 pushed_string_list
->flags
= PSH_SOURCE
; /* XXX - for now */
4337 parser_restore_alias ()
4339 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4340 if (pushed_string_list
)
4348 /* Before freeing AP, make sure that there aren't any cases of pointer
4349 aliasing that could cause us to reference freed memory later on. */
4351 clear_string_list_expander (ap
)
4354 register STRING_SAVER
*t
;
4356 for (t
= pushed_string_list
; t
; t
= t
->next
)
4358 if (t
->expander
&& t
->expander
== ap
)
4365 clear_shell_input_line ()
4367 if (shell_input_line
)
4368 shell_input_line
[shell_input_line_index
= 0] = '\0';
4371 /* Return a line of text, taken from wherever yylex () reads input.
4372 If there is no more input, then we return NULL. If REMOVE_QUOTED_NEWLINE
4373 is non-zero, we remove unquoted \<newline> pairs. This is used by
4374 read_secondary_line to read here documents. */
4376 read_a_line (remove_quoted_newline
)
4377 int remove_quoted_newline
;
4379 static char *line_buffer
= (char *)NULL
;
4380 static int buffer_size
= 0;
4381 int indx
, c
, peekc
, pass_next
;
4383 #if defined (READLINE)
4384 if (no_line_editing
&& SHOULD_PROMPT ())
4386 if (SHOULD_PROMPT ())
4390 pass_next
= indx
= 0;
4393 /* Allow immediate exit if interrupted during input. */
4398 /* Ignore null bytes in input. */
4402 /* If there is no more input, then we return NULL. */
4405 if (interactive
&& bash_input
.type
== st_stream
)
4408 return ((char *)NULL
);
4412 /* `+2' in case the final character in the buffer is a newline or we
4413 have to handle CTLESC or CTLNUL. */
4414 RESIZE_MALLOCED_BUFFER (line_buffer
, indx
, 2, buffer_size
, 128);
4416 /* IF REMOVE_QUOTED_NEWLINES is non-zero, we are reading a
4417 here document with an unquoted delimiter. In this case,
4418 the line will be expanded as if it were in double quotes.
4419 We allow a backslash to escape the next character, but we
4420 need to treat the backslash specially only if a backslash
4421 quoting a backslash-newline pair appears in the line. */
4424 line_buffer
[indx
++] = c
;
4427 else if (c
== '\\' && remove_quoted_newline
)
4434 continue; /* Make the unquoted \<newline> pair disappear. */
4440 line_buffer
[indx
++] = c
; /* Preserve the backslash. */
4445 /* remove_quoted_newline is non-zero if the here-document delimiter
4446 is unquoted. In this case, we will be expanding the lines and
4447 need to make sure CTLESC and CTLNUL in the input are quoted. */
4448 if (remove_quoted_newline
&& (c
== CTLESC
|| c
== CTLNUL
))
4449 line_buffer
[indx
++] = CTLESC
;
4450 line_buffer
[indx
++] = c
;
4455 line_buffer
[indx
] = '\0';
4456 return (line_buffer
);
4461 /* Return a line as in read_a_line (), but insure that the prompt is
4462 the secondary prompt. This is used to read the lines of a here
4463 document. REMOVE_QUOTED_NEWLINE is non-zero if we should remove
4464 newlines quoted with backslashes while reading the line. It is
4465 non-zero unless the delimiter of the here document was quoted. */
4467 read_secondary_line (remove_quoted_newline
)
4468 int remove_quoted_newline
;
4473 prompt_string_pointer
= &ps2_prompt
;
4474 if (SHOULD_PROMPT ())
4476 ret
= read_a_line (remove_quoted_newline
);
4477 #if defined (HISTORY)
4478 if (ret
&& remember_on_history
&& (parser_state
& PST_HEREDOC
))
4480 /* To make adding the here-document body right, we need to rely on
4481 history_delimiting_chars() returning \n for the first line of the
4482 here-document body and the null string for the second and subsequent
4483 lines, so we avoid double newlines.
4484 current_command_line_count == 2 for the first line of the body. */
4486 current_command_line_count
++;
4487 maybe_add_history (ret
);
4489 #endif /* HISTORY */
4493 /* **************************************************************** */
4497 /* **************************************************************** */
4499 /* Reserved words. These are only recognized as the first word of a
4501 STRING_INT_ALIST word_token_alist
[] = {
4510 #if defined (SELECT_COMMAND)
4511 { "select", SELECT
},
4518 { "function", FUNCTION
},
4519 #if defined (COMMAND_TIMING)
4525 #if defined (COND_COMMAND)
4526 { "[[", COND_START
},
4529 #if defined (COPROCESS_SUPPORT)
4530 { "coproc", COPROC
},
4535 /* other tokens that can be returned by read_token() */
4536 STRING_INT_ALIST other_token_alist
[] = {
4537 /* Multiple-character tokens with special values */
4542 { ">>", GREATER_GREATER
},
4543 { "<<", LESS_LESS
},
4545 { ">&", GREATER_AND
},
4546 { ";;", SEMI_SEMI
},
4548 { ";;&", SEMI_SEMI_AND
},
4549 { "<<-", LESS_LESS_MINUS
},
4550 { "<<<", LESS_LESS_LESS
},
4551 { "&>", AND_GREATER
},
4552 { "&>>", AND_GREATER_GREATER
},
4553 { "<>", LESS_GREATER
},
4554 { ">|", GREATER_BAR
},
4556 { "EOF", yacc_EOF
},
4557 /* Tokens whose value is the character itself */
4568 { "newline", '\n' },
4572 /* others not listed here:
4573 WORD look at yylval.word
4574 ASSIGNMENT_WORD look at yylval.word
4575 NUMBER look at yylval.number
4576 ARITH_CMD look at yylval.word_list
4577 ARITH_FOR_EXPRS look at yylval.word_list
4578 COND_CMD look at yylval.command
4581 /* These are used by read_token_word, but appear up here so that shell_getc
4582 can use them to decide when to add otherwise blank lines to the history. */
4584 /* The primary delimiter stack. */
4585 struct dstack dstack
= { (char *)NULL
, 0, 0 };
4587 /* A temporary delimiter stack to be used when decoding prompt strings.
4588 This is needed because command substitutions in prompt strings (e.g., PS2)
4589 can screw up the parser's quoting state. */
4590 static struct dstack temp_dstack
= { (char *)NULL
, 0, 0 };
4592 /* Macro for accessing the top delimiter on the stack. Returns the
4593 delimiter or zero if none. */
4594 #define current_delimiter(ds) \
4595 (ds.delimiter_depth ? ds.delimiters[ds.delimiter_depth - 1] : 0)
4597 #define push_delimiter(ds, character) \
4600 if (ds.delimiter_depth + 2 > ds.delimiter_space) \
4601 ds.delimiters = (char *)xrealloc \
4602 (ds.delimiters, (ds.delimiter_space += 10) * sizeof (char)); \
4603 ds.delimiters[ds.delimiter_depth] = character; \
4604 ds.delimiter_depth++; \
4608 #define pop_delimiter(ds) ds.delimiter_depth--
4610 /* Return the next shell input character. This always reads characters
4611 from shell_input_line; when that line is exhausted, it is time to
4612 read the next line. This is called by read_token when the shell is
4613 processing normal command input. */
4615 /* This implements one-character lookahead/lookbehind across physical input
4616 lines, to avoid something being lost because it's pushed back with
4617 shell_ungetc when we're at the start of a line. */
4618 static int eol_ungetc_lookahead
= 0;
4620 static int unquoted_backslash
= 0;
4623 shell_getc (remove_quoted_newline
)
4624 int remove_quoted_newline
;
4627 int c
, truncating
, last_was_backslash
;
4632 last_was_backslash
= 0;
4633 if (sigwinch_received
)
4635 sigwinch_received
= 0;
4636 get_new_window_size (0, (int *)0, (int *)0);
4639 if (eol_ungetc_lookahead
)
4641 c
= eol_ungetc_lookahead
;
4642 eol_ungetc_lookahead
= 0;
4646 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4647 /* If shell_input_line[shell_input_line_index] == 0, but there is
4648 something on the pushed list of strings, then we don't want to go
4649 off and get another line. We let the code down below handle it. */
4651 if (!shell_input_line
|| ((!shell_input_line
[shell_input_line_index
]) &&
4652 (pushed_string_list
== (STRING_SAVER
*)NULL
)))
4653 #else /* !ALIAS && !DPAREN_ARITHMETIC */
4654 if (!shell_input_line
|| !shell_input_line
[shell_input_line_index
])
4655 #endif /* !ALIAS && !DPAREN_ARITHMETIC */
4659 /* Let's not let one really really long line blow up memory allocation */
4660 if (shell_input_line
&& shell_input_line_size
>= 32768)
4662 free (shell_input_line
);
4663 shell_input_line
= 0;
4664 shell_input_line_size
= 0;
4669 /* Allow immediate exit if interrupted during input. */
4673 shell_input_line_terminator
= 0;
4675 /* If the shell is interactive, but not currently printing a prompt
4676 (interactive_shell && interactive == 0), we don't want to print
4677 notifies or cleanup the jobs -- we want to defer it until we do
4678 print the next prompt. */
4679 if (interactive_shell
== 0 || SHOULD_PROMPT())
4681 #if defined (JOB_CONTROL)
4682 /* This can cause a problem when reading a command as the result
4683 of a trap, when the trap is called from flush_child. This call
4684 had better not cause jobs to disappear from the job table in
4685 that case, or we will have big trouble. */
4686 notify_and_cleanup ();
4687 #else /* !JOB_CONTROL */
4688 cleanup_dead_jobs ();
4689 #endif /* !JOB_CONTROL */
4692 #if defined (READLINE)
4693 if (no_line_editing
&& SHOULD_PROMPT())
4695 if (SHOULD_PROMPT())
4699 if (bash_input
.type
== st_stream
)
4706 /* Allow immediate exit if interrupted during input. */
4711 /* If we get EOS while parsing a string, treat it as EOF so we
4712 don't just keep looping. Happens very rarely */
4713 if (bash_input
.type
== st_string
)
4716 shell_input_line_terminator
= EOF
;
4717 shell_input_line
[i
] = '\0';
4724 /* Theoretical overflow */
4725 /* If we can't put 256 bytes more into the buffer, allocate
4726 everything we can and fill it as full as we can. */
4727 /* XXX - we ignore rest of line using `truncating' flag */
4728 if (shell_input_line_size
> (SIZE_MAX
- 256))
4732 n
= SIZE_MAX
- i
; /* how much more can we put into the buffer? */
4733 if (n
<= 2) /* we have to save 1 for the newline added below */
4735 if (truncating
== 0)
4736 internal_warning(_("shell_getc: shell_input_line_size (%zu) exceeds SIZE_MAX (%lu): line truncated"), shell_input_line_size
, (unsigned long)SIZE_MAX
);
4737 shell_input_line
[i
] = '\0';
4740 if (shell_input_line_size
< SIZE_MAX
)
4742 shell_input_line_size
= SIZE_MAX
;
4743 shell_input_line
= xrealloc (shell_input_line
, shell_input_line_size
);
4747 RESIZE_MALLOCED_BUFFER (shell_input_line
, i
, 2, shell_input_line_size
, 256);
4751 if (bash_input
.type
== st_stream
)
4755 shell_input_line_terminator
= EOF
;
4757 shell_input_line
[i
] = '\0';
4761 if (truncating
== 0 || c
== '\n')
4762 shell_input_line
[i
++] = c
;
4766 shell_input_line
[--i
] = '\0';
4767 current_command_line_count
++;
4771 last_was_backslash
= last_was_backslash
== 0 && c
== '\\';
4774 shell_input_line_index
= 0;
4775 shell_input_line_len
= i
; /* == strlen (shell_input_line) */
4777 set_line_mbstate ();
4779 #if defined (HISTORY)
4780 if (remember_on_history
&& shell_input_line
&& shell_input_line
[0])
4783 # if defined (BANG_HISTORY)
4784 /* If the current delimiter is a single quote, we should not be
4785 performing history expansion, even if we're on a different
4786 line from the original single quote. */
4787 if (current_delimiter (dstack
) == '\'')
4788 history_quoting_state
= '\'';
4789 else if (current_delimiter (dstack
) == '"')
4790 history_quoting_state
= '"';
4792 history_quoting_state
= 0;
4794 /* Calling with a third argument of 1 allows remember_on_history to
4795 determine whether or not the line is saved to the history list */
4796 expansions
= pre_process_line (shell_input_line
, 1, 1);
4797 # if defined (BANG_HISTORY)
4798 history_quoting_state
= 0;
4800 if (expansions
!= shell_input_line
)
4802 free (shell_input_line
);
4803 shell_input_line
= expansions
;
4804 shell_input_line_len
= shell_input_line
?
4805 strlen (shell_input_line
) : 0;
4806 if (shell_input_line_len
== 0)
4807 current_command_line_count
--;
4809 /* We have to force the xrealloc below because we don't know
4810 the true allocated size of shell_input_line anymore. */
4811 shell_input_line_size
= shell_input_line_len
;
4813 set_line_mbstate ();
4816 /* Try to do something intelligent with blank lines encountered while
4817 entering multi-line commands. XXX - this is grotesque */
4818 else if (remember_on_history
&& shell_input_line
&&
4819 shell_input_line
[0] == '\0' &&
4820 current_command_line_count
> 1)
4822 if (current_delimiter (dstack
))
4823 /* We know shell_input_line[0] == 0 and we're reading some sort of
4824 quoted string. This means we've got a line consisting of only
4825 a newline in a quoted string. We want to make sure this line
4826 gets added to the history. */
4827 maybe_add_history (shell_input_line
);
4831 hdcs
= history_delimiting_chars (shell_input_line
);
4832 if (hdcs
&& hdcs
[0] == ';')
4833 maybe_add_history (shell_input_line
);
4837 #endif /* HISTORY */
4839 if (shell_input_line
)
4841 /* Lines that signify the end of the shell's input should not be
4842 echoed. We should not echo lines while parsing command
4843 substitutions with recursive calls into the parsing engine; those
4844 should only be echoed once when we read the word. That is the
4845 reason for the test against shell_eof_token, which is set to a
4846 right paren when parsing the contents of command substitutions. */
4847 if (echo_input_at_read
&& (shell_input_line
[0] ||
4848 shell_input_line_terminator
!= EOF
) &&
4849 shell_eof_token
== 0)
4850 fprintf (stderr
, "%s\n", shell_input_line
);
4854 shell_input_line_size
= 0;
4855 prompt_string_pointer
= ¤t_prompt_string
;
4856 if (SHOULD_PROMPT ())
4861 /* Add the newline to the end of this string, iff the string does
4862 not already end in an EOF character. */
4863 if (shell_input_line_terminator
!= EOF
)
4865 if (shell_input_line_size
< SIZE_MAX
-3 && (shell_input_line_len
+3 > shell_input_line_size
))
4866 shell_input_line
= (char *)xrealloc (shell_input_line
,
4867 1 + (shell_input_line_size
+= 2));
4869 /* Don't add a newline to a string that ends with a backslash if we're
4870 going to be removing quoted newlines, since that will eat the
4871 backslash. Add another backslash instead (will be removed by
4873 if (bash_input
.type
== st_string
&& expanding_alias() == 0 && last_was_backslash
&& c
== EOF
&& remove_quoted_newline
)
4874 shell_input_line
[shell_input_line_len
] = '\\';
4876 shell_input_line
[shell_input_line_len
] = '\n';
4877 shell_input_line
[shell_input_line_len
+ 1] = '\0';
4879 #if defined (HANDLE_MULTIBYTE)
4880 /* This is kind of an abstraction violation, but there's no need to
4881 go through the entire shell_input_line again with a call to
4882 set_line_mbstate(). */
4883 EXTEND_SHELL_INPUT_LINE_PROPERTY();
4884 shell_input_line_property
[shell_input_line_len
] = 1;
4890 if (shell_input_line_index
== 0)
4891 unquoted_backslash
= 0;
4893 uc
= shell_input_line
[shell_input_line_index
];
4897 unquoted_backslash
= unquoted_backslash
== 0 && uc
== '\\';
4898 shell_input_line_index
++;
4901 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
4902 /* If UC is NULL, we have reached the end of the current input string. If
4903 pushed_string_list is non-empty, it's time to pop to the previous string
4904 because we have fully consumed the result of the last alias expansion.
4905 Do it transparently; just return the next character of the string popped
4907 /* If pushed_string_list != 0 but pushed_string_list->expander == 0 (not
4908 currently tested) and the flags value is not PSH_SOURCE, we are not
4909 parsing an alias, we have just saved one (push_string, when called by
4910 the parse_dparen code) In this case, just go on as well. The PSH_SOURCE
4911 case is handled below. */
4913 /* If we're at the end of an alias expansion add a space to make sure that
4914 the alias remains marked as being in use while we expand its last word.
4915 This makes sure that pop_string doesn't mark the alias as not in use
4916 before the string resulting from the alias expansion is tokenized and
4917 checked for alias expansion, preventing recursion. At this point, the
4918 last character in shell_input_line is the last character of the alias
4919 expansion. We test that last character to determine whether or not to
4920 return the space that will delimit the token and postpone the pop_string.
4921 This set of conditions duplicates what used to be in mk_alexpansion ()
4922 below, with the addition that we don't add a space if we're currently
4923 reading a quoted string or in a shell comment. */
4924 #ifndef OLD_ALIAS_HACK
4925 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
&&
4926 pushed_string_list
->flags
!= PSH_DPAREN
&&
4927 (parser_state
& PST_COMMENT
) == 0 &&
4928 (parser_state
& PST_ENDALIAS
) == 0 && /* only once */
4929 shell_input_line_index
> 0 &&
4930 shellblank (shell_input_line
[shell_input_line_index
-1]) == 0 &&
4931 shell_input_line
[shell_input_line_index
-1] != '\n' &&
4932 unquoted_backslash
== 0 &&
4933 shellmeta (shell_input_line
[shell_input_line_index
-1]) == 0 &&
4934 (current_delimiter (dstack
) != '\'' && current_delimiter (dstack
) != '"'))
4936 parser_state
|= PST_ENDALIAS
;
4937 /* We need to do this to make sure last_shell_getc_is_singlebyte returns
4938 true, since we are returning a single-byte space. */
4939 if (shell_input_line_index
== shell_input_line_len
&& last_shell_getc_is_singlebyte
== 0)
4942 EXTEND_SHELL_INPUT_LINE_PROPERTY();
4943 shell_input_line_property
[shell_input_line_len
++] = 1;
4944 /* extend shell_input_line to accommodate the shell_ungetc that
4945 read_token_word() will perform, since we're extending the index */
4946 RESIZE_MALLOCED_BUFFER (shell_input_line
, shell_input_line_index
, 2, shell_input_line_size
, 16);
4947 shell_input_line
[++shell_input_line_index
] = '\0'; /* XXX */
4949 shell_input_line_property
[shell_input_line_index
- 1] = 1;
4952 return ' '; /* END_ALIAS */
4957 #endif /* ALIAS || DPAREN_ARITHMETIC */
4958 /* This case works for PSH_DPAREN as well as the shell_ungets() case that uses
4960 if (uc
== 0 && pushed_string_list
&& pushed_string_list
->flags
!= PSH_SOURCE
)
4962 parser_state
&= ~PST_ENDALIAS
;
4964 uc
= shell_input_line
[shell_input_line_index
];
4966 shell_input_line_index
++;
4969 if MBTEST(uc
== '\\' && remove_quoted_newline
&& shell_input_line
[shell_input_line_index
] == '\n')
4971 if (SHOULD_PROMPT ())
4975 /* What do we do here if we're expanding an alias whose definition
4976 includes an escaped newline? If that's the last character in the
4977 alias expansion, we just pop the pushed string list (recall that
4978 we inhibit the appending of a space if newline is the last
4979 character). If it's not the last character, we need to consume the
4980 quoted newline and move to the next character in the expansion. */
4982 if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] == '\0')
4987 else if (expanding_alias () && shell_input_line
[shell_input_line_index
+1] != '\0')
4989 shell_input_line_index
++; /* skip newline */
4990 goto next_alias_char
; /* and get next character */
4997 if (uc
== 0 && shell_input_line_terminator
== EOF
)
4998 return ((shell_input_line_index
!= 0) ? '\n' : EOF
);
5000 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5001 /* We already know that we are not parsing an alias expansion because of the
5002 check for expanding_alias() above. This knows how parse_and_execute
5003 handles switching to st_string input while an alias is being expanded,
5004 hence the check for pushed_string_list without pushed_string_list->expander
5005 and the check for PSH_SOURCE as pushed_string_list->flags.
5006 parse_and_execute and parse_string both change the input type to st_string
5007 and place the string to be parsed and executed into location.string, so
5008 we should not stop reading that until the pointer is '\0'.
5009 The check for shell_input_line_terminator may be superfluous.
5011 This solves the problem of `.' inside a multi-line alias with embedded
5012 newlines executing things out of order. */
5013 if (uc
== 0 && bash_input
.type
== st_string
&& *bash_input
.location
.string
&&
5014 pushed_string_list
&& pushed_string_list
->flags
== PSH_SOURCE
&&
5015 shell_input_line_terminator
== 0)
5017 shell_input_line_index
= 0;
5025 /* Put C back into the input for the shell. This might need changes for
5026 HANDLE_MULTIBYTE around EOLs. Since we (currently) never push back a
5027 character different than we read, shell_input_line_property doesn't need
5028 to change when manipulating shell_input_line. The define for
5029 last_shell_getc_is_singlebyte should take care of it, though. */
5034 if (shell_input_line
&& shell_input_line_index
)
5035 shell_input_line
[--shell_input_line_index
] = c
;
5037 eol_ungetc_lookahead
= c
;
5040 /* Push S back into shell_input_line; updating shell_input_line_index */
5045 size_t slen
, chars_left
;
5049 if (shell_input_line
[shell_input_line_index
] == '\0')
5051 /* Easy, just overwrite shell_input_line. This is preferred because it
5052 saves on set_line_mbstate () and other overhead like push_string */
5053 if (shell_input_line_size
<= slen
)
5054 RESIZE_MALLOCED_BUFFER (shell_input_line
, shell_input_line_index
, slen
+ 1, shell_input_line_size
, 64);
5055 strcpy (shell_input_line
, s
);
5056 shell_input_line_index
= 0;
5057 shell_input_line_len
= slen
;
5058 shell_input_line_terminator
= 0;
5060 else if (shell_input_line_index
>= slen
)
5062 /* Just as easy, just back up shell_input_line_index, but it means we
5063 will re-process some characters in set_line_mbstate(). Need to
5064 watch pushing back newlines here. */
5066 shell_input_line
[--shell_input_line_index
] = s
[--slen
];
5068 else if (s
[slen
- 1] == '\n')
5070 push_string (savestring (s
), 0, (alias_t
*)NULL
);
5071 /* push_string does set_line_mbstate () */
5076 /* Harder case: pushing back input string that's longer than what we've
5077 consumed from shell_input_line so far. */
5078 INTERNAL_DEBUG (("shell_ungets: not at end of shell_input_line"));
5080 chars_left
= shell_input_line_len
- shell_input_line_index
;
5081 if (shell_input_line_size
<= (slen
+ chars_left
))
5082 RESIZE_MALLOCED_BUFFER (shell_input_line
, shell_input_line_index
, chars_left
+ slen
+ 1, shell_input_line_size
, 64);
5083 memmove (shell_input_line
+ slen
, shell_input_line
+ shell_input_line_index
, shell_input_line_len
- shell_input_line_index
);
5084 strcpy (shell_input_line
, s
);
5085 shell_input_line_index
= 0;
5086 shell_input_line_len
= strlen (shell_input_line
); /* chars_left + slen? */
5089 #if defined (HANDLE_MULTIBYTE)
5090 set_line_mbstate (); /* XXX */
5095 parser_remaining_input ()
5097 if (shell_input_line
== 0)
5099 if ((int)shell_input_line_index
< 0 || shell_input_line_index
>= shell_input_line_len
)
5100 return ""; /* XXX */
5101 return (shell_input_line
+ shell_input_line_index
);
5104 #ifdef INCLUDE_UNUSED
5105 /* Back the input pointer up by one, effectively `ungetting' a character. */
5109 if (shell_input_line
&& shell_input_line_index
)
5110 shell_input_line_index
--;
5114 /* Discard input until CHARACTER is seen, then push that character back
5115 onto the input stream. */
5117 discard_until (character
)
5122 while ((c
= shell_getc (0)) != EOF
&& c
!= character
)
5130 execute_variable_command (command
, vname
)
5131 char *command
, *vname
;
5134 sh_parser_state_t ps
;
5136 save_parser_state (&ps
);
5137 last_lastarg
= get_string_value ("_");
5139 last_lastarg
= savestring (last_lastarg
);
5141 parse_and_execute (savestring (command
), vname
, SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOOPTIMIZE
);
5143 restore_parser_state (&ps
);
5144 bind_variable ("_", last_lastarg
, 0);
5145 FREE (last_lastarg
);
5147 if (token_to_read
== '\n') /* reset_parser was called */
5155 two_tokens_ago
= token_before_that
;
5156 token_before_that
= last_read_token
;
5157 last_read_token
= current_token
;
5162 /* Place to remember the token. We try to keep the buffer
5163 at a reasonable size, but it can grow. */
5164 static char *token
= (char *)NULL
;
5166 /* Current size of the token buffer. */
5167 static size_t token_buffer_size
;
5169 /* Command to read_token () explaining what we want it to do. */
5172 #define prompt_is_ps1 \
5173 (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
5175 /* Function for yyparse to call. yylex keeps track of
5176 the last two tokens read, and calls read_token. */
5180 if (interactive
&& (current_token
== 0 || current_token
== '\n'))
5182 /* Before we print a prompt, we might have to check mailboxes.
5183 We do this only if it is time to do so. Notice that only here
5184 is the mail alarm reset; nothing takes place in check_mail ()
5185 except the checking of mail. Please don't change this. */
5186 if (prompt_is_ps1
&& parse_and_execute_level
== 0 && time_to_check_mail ())
5189 reset_mail_timer ();
5192 /* Avoid printing a prompt if we're not going to read anything, e.g.
5193 after resetting the parser with read_token (RESET). */
5194 if (token_to_read
== 0 && SHOULD_PROMPT ())
5198 two_tokens_ago
= token_before_that
;
5199 token_before_that
= last_read_token
;
5200 last_read_token
= current_token
;
5201 current_token
= read_token (READ
);
5203 if ((parser_state
& PST_EOFTOKEN
) && current_token
== shell_eof_token
)
5205 /* placeholder for any special handling. */
5206 return (current_token
);
5209 if (current_token
< 0)
5210 #if defined (YYERRCODE) && !defined (YYUNDEF)
5211 current_token
= YYERRCODE
;
5213 current_token
= YYerror
;
5216 return (current_token
);
5219 /* When non-zero, we have read the required tokens
5220 which allow ESAC to be the next one read. */
5221 static int esacs_needed_count
;
5223 /* When non-zero, we can read IN as an acceptable token, regardless of how
5224 many newlines we read. */
5225 static int expecting_in_token
;
5231 if (need_here_doc
>= HEREDOC_MAX
)
5233 last_command_exit_value
= EX_BADUSAGE
;
5235 report_syntax_error (_("maximum here-document count exceeded"));
5237 exit_shell (last_command_exit_value
);
5239 redir_stack
[need_here_doc
++] = r
;
5243 gather_here_documents ()
5248 here_doc_first_line
= 1;
5249 while (need_here_doc
> 0)
5251 parser_state
|= PST_HEREDOC
;
5252 make_here_document (redir_stack
[r
++], line_number
);
5253 parser_state
&= ~PST_HEREDOC
;
5255 redir_stack
[r
- 1] = 0; /* XXX */
5257 here_doc_first_line
= 0; /* just in case */
5260 /* When non-zero, an open-brace used to create a group is awaiting a close
5262 static int open_brace_count
;
5264 /* In the following three macros, `token' is always last_read_token */
5266 /* Are we in the middle of parsing a redirection where we are about to read
5267 a word? This is used to make sure alias expansion doesn't happen in the
5268 middle of a redirection, even though we're parsing a simple command. */
5269 #define parsing_redirection(token) \
5270 (token == '<' || token == '>' || \
5271 token == GREATER_GREATER || token == GREATER_BAR || \
5272 token == LESS_GREATER || token == LESS_LESS_MINUS || \
5273 token == LESS_LESS || token == LESS_LESS_LESS || \
5274 token == LESS_AND || token == GREATER_AND || token == AND_GREATER)
5276 /* Is `token' one that will allow a WORD to be read in a command position?
5277 We can read a simple command name on which we should attempt alias expansion
5278 or we can read an assignment statement. */
5279 #define command_token_position(token) \
5280 (((token) == ASSIGNMENT_WORD) || \
5281 ((parser_state&PST_REDIRLIST) && parsing_redirection(token) == 0) || \
5282 ((token) != SEMI_SEMI && (token) != SEMI_AND && (token) != SEMI_SEMI_AND && reserved_word_acceptable(token)))
5284 /* Are we in a position where we can read an assignment statement? */
5285 #define assignment_acceptable(token) \
5286 (command_token_position(token) && ((parser_state & PST_CASEPAT) == 0))
5288 /* Check to see if TOKEN is a reserved word and return the token
5290 #define CHECK_FOR_RESERVED_WORD(tok) \
5292 if (!dollar_present && !quoted && \
5293 reserved_word_acceptable (last_read_token)) \
5296 for (i = 0; word_token_alist[i].word != (char *)NULL; i++) \
5297 if (STREQ (tok, word_token_alist[i].word)) \
5299 if ((parser_state & PST_CASEPAT) && (word_token_alist[i].token != ESAC)) \
5301 if (word_token_alist[i].token == TIME && time_command_acceptable () == 0) \
5303 if ((parser_state & PST_CASEPAT) && last_read_token == '|' && word_token_alist[i].token == ESAC) \
5304 break; /* Posix grammar rule 4 */ \
5305 if ((parser_state & PST_CASEPAT) && last_read_token == '(' && word_token_alist[i].token == ESAC) /*)*/ \
5306 break; /* phantom Posix grammar rule 4 */ \
5307 if (word_token_alist[i].token == ESAC) { \
5308 parser_state &= ~(PST_CASEPAT|PST_CASESTMT); \
5309 esacs_needed_count--; \
5310 } else if (word_token_alist[i].token == CASE) \
5311 parser_state |= PST_CASESTMT; \
5312 else if (word_token_alist[i].token == COND_END) \
5313 parser_state &= ~(PST_CONDCMD|PST_CONDEXPR); \
5314 else if (word_token_alist[i].token == COND_START) \
5315 parser_state |= PST_CONDCMD; \
5316 else if (word_token_alist[i].token == '{') \
5317 open_brace_count++; \
5318 else if (word_token_alist[i].token == '}' && open_brace_count) \
5319 open_brace_count--; \
5320 return (word_token_alist[i].token); \
5327 /* OK, we have a token. Let's try to alias expand it, if (and only if)
5330 It is eligible for expansion if EXPAND_ALIASES is set, and
5331 the token is unquoted and the last token read was a command
5332 separator (or expand_next_token is set), and we are currently
5333 processing an alias (pushed_string_list is non-empty) and this
5334 token is not the same as the current or any previously
5337 Special cases that disqualify:
5338 In a pattern list in a case statement (parser_state & PST_CASEPAT). */
5348 r
= xmalloc (l
+ 2);
5350 #ifdef OLD_ALIAS_HACK
5351 /* If the last character in the alias is a newline, don't add a trailing
5352 space to the expansion. Works with shell_getc above. */
5353 /* Need to do something about the case where the alias expansion contains
5354 an unmatched quoted string, since appending this space affects the
5355 subsequent output. */
5356 if (l
> 0 && r
[l
- 1] != ' ' && r
[l
- 1] != '\n' && shellmeta(r
[l
- 1]) == 0)
5364 alias_expand_token (tokstr
)
5371 if (((parser_state
& PST_ALEXPNEXT
) || command_token_position (last_read_token
)) &&
5372 (parser_state
& PST_CASEPAT
) == 0)
5374 if ((parser_state
& PST_ALEXPNEXT
) || assignment_acceptable (last_read_token
))
5377 ap
= find_alias (tokstr
);
5379 /* Currently expanding this token. */
5380 if (ap
&& (ap
->flags
& AL_BEINGEXPANDED
))
5381 return (NO_EXPANSION
);
5383 #ifdef OLD_ALIAS_HACK
5384 /* mk_alexpansion puts an extra space on the end of the alias expansion,
5385 so the lookahead by the parser works right (the alias needs to remain
5386 `in use' while parsing its last word to avoid alias recursion for
5387 something like "alias echo=echo"). If this gets changed, make sure
5388 the code in shell_getc that deals with reaching the end of an
5389 expanded alias is changed with it. */
5391 expanded
= ap
? mk_alexpansion (ap
->value
) : (char *)NULL
;
5395 push_string (expanded
, ap
->flags
& AL_EXPANDNEXT
, ap
);
5396 return (RE_READ_TOKEN
);
5399 /* This is an eligible token that does not have an expansion. */
5400 return (NO_EXPANSION
);
5402 return (NO_EXPANSION
);
5407 time_command_acceptable ()
5409 #if defined (COMMAND_TIMING)
5412 if (posixly_correct
&& shell_compatibility_level
> 41)
5414 /* Quick check of the rest of the line to find the next token. If it
5415 begins with a `-', Posix says to not return `time' as the token.
5416 This was interp 267. */
5417 i
= shell_input_line_index
;
5418 while (i
< shell_input_line_len
&& (shell_input_line
[i
] == ' ' || shell_input_line
[i
] == '\t'))
5420 if (shell_input_line
[i
] == '-')
5424 switch (last_read_token
)
5429 if (token_before_that
== '|')
5444 case ')': /* only valid in case statement */
5445 case BANG
: /* ! time pipeline */
5446 case TIME
: /* time time pipeline */
5447 case TIMEOPT
: /* time -p time pipeline */
5448 case TIMEIGN
: /* time -p -- ... */
5455 #endif /* COMMAND_TIMING */
5458 /* Handle special cases of token recognition:
5459 IN is recognized if the last token was WORD and the token
5460 before that was FOR or CASE or SELECT.
5462 DO is recognized if the last token was WORD and the token
5463 before that was FOR or SELECT.
5465 ESAC is recognized if the last token caused `esacs_needed_count'
5468 `{' is recognized if the last token as WORD and the token
5469 before that was FUNCTION, or if we just parsed an arithmetic
5472 `}' is recognized if there is an unclosed `{' present.
5474 `-p' is returned as TIMEOPT if the last read token was TIME.
5475 `--' is returned as TIMEIGN if the last read token was TIME or TIMEOPT.
5477 ']]' is returned as COND_END if the parser is currently parsing
5478 a conditional expression ((parser_state & PST_CONDEXPR) != 0)
5480 `time' is returned as TIME if and only if it is immediately
5481 preceded by one of `;', `\n', `||', `&&', or `&'.
5485 special_case_tokens (tokstr
)
5488 /* Posix grammar rule 6 */
5489 if ((last_read_token
== WORD
) &&
5490 #if defined (SELECT_COMMAND)
5491 ((token_before_that
== FOR
) || (token_before_that
== CASE
) || (token_before_that
== SELECT
)) &&
5493 ((token_before_that
== FOR
) || (token_before_that
== CASE
)) &&
5495 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5497 if (token_before_that
== CASE
)
5499 parser_state
|= PST_CASEPAT
;
5500 esacs_needed_count
++;
5502 if (expecting_in_token
)
5503 expecting_in_token
--;
5507 /* XXX - leaving above code intact for now, but it should eventually be
5508 removed in favor of this clause. */
5509 /* Posix grammar rule 6 */
5510 if (expecting_in_token
&& (last_read_token
== WORD
|| last_read_token
== '\n') &&
5511 (tokstr
[0] == 'i' && tokstr
[1] == 'n' && tokstr
[2] == 0))
5513 if (parser_state
& PST_CASESTMT
)
5515 parser_state
|= PST_CASEPAT
;
5516 esacs_needed_count
++;
5518 expecting_in_token
--;
5521 /* Posix grammar rule 6, third word in FOR: for i; do command-list; done */
5522 else if (expecting_in_token
&& (last_read_token
== '\n' || last_read_token
== ';') &&
5523 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5525 expecting_in_token
--;
5529 /* for i do; command-list; done */
5530 if (last_read_token
== WORD
&&
5531 #if defined (SELECT_COMMAND)
5532 (token_before_that
== FOR
|| token_before_that
== SELECT
) &&
5534 (token_before_that
== FOR
) &&
5536 (tokstr
[0] == 'd' && tokstr
[1] == 'o' && tokstr
[2] == '\0'))
5538 if (expecting_in_token
)
5539 expecting_in_token
--;
5543 /* Ditto for ESAC in the CASE case.
5544 Specifically, this handles "case word in esac", which is a legal
5545 construct, certainly because someone will pass an empty arg to the
5546 case construct, and we don't want it to barf. Of course, we should
5547 insist that the case construct has at least one pattern in it, but
5548 the designers disagree. */
5549 if (esacs_needed_count
)
5551 if (last_read_token
== IN
&& STREQ (tokstr
, "esac"))
5553 esacs_needed_count
--;
5554 parser_state
&= ~PST_CASEPAT
;
5559 /* The start of a shell function definition. */
5560 if (parser_state
& PST_ALLOWOPNBRC
)
5562 parser_state
&= ~PST_ALLOWOPNBRC
;
5563 if (tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5566 function_bstart
= line_number
;
5567 return ('{'); /* } */
5571 /* We allow a `do' after a for ((...)) without an intervening
5573 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == 'd' && tokstr
[1] == 'o' && !tokstr
[2])
5575 if (last_read_token
== ARITH_FOR_EXPRS
&& tokstr
[0] == '{' && tokstr
[1] == '\0') /* } */
5578 return ('{'); /* } */
5581 if (open_brace_count
&& reserved_word_acceptable (last_read_token
) && tokstr
[0] == '}' && !tokstr
[1])
5583 open_brace_count
--; /* { */
5587 #if defined (COMMAND_TIMING)
5588 /* Handle -p after `time'. */
5589 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == 'p' && !tokstr
[2])
5591 /* Handle -- after `time'. */
5592 if (last_read_token
== TIME
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5594 /* Handle -- after `time -p'. */
5595 if (last_read_token
== TIMEOPT
&& tokstr
[0] == '-' && tokstr
[1] == '-' && !tokstr
[2])
5599 #if defined (COND_COMMAND) /* [[ */
5600 if ((parser_state
& PST_CONDEXPR
) && tokstr
[0] == ']' && tokstr
[1] == ']' && tokstr
[2] == '\0')
5607 /* Called from shell.c when Control-C is typed at top level. Or
5608 by the error rule at top level. */
5612 dstack
.delimiter_depth
= 0; /* No delimiters found so far. */
5613 open_brace_count
= 0;
5615 #if defined (EXTENDED_GLOB)
5616 /* Reset to global value of extended glob */
5617 if (parser_state
& (PST_EXTPAT
|PST_CMDSUBST
))
5618 extended_glob
= extglob_flag
;
5620 if (parser_state
& (PST_CMDSUBST
|PST_STRING
))
5621 expand_aliases
= expaliases_flag
;
5624 here_doc_first_line
= 0;
5626 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
5627 if (pushed_string_list
)
5628 free_string_list ();
5629 #endif /* ALIAS || DPAREN_ARITHMETIC */
5631 /* This is where we resynchronize to the next newline on error/reset */
5632 if (shell_input_line
)
5634 free (shell_input_line
);
5635 shell_input_line
= (char *)NULL
;
5636 shell_input_line_size
= shell_input_line_index
= 0;
5639 FREE (word_desc_to_read
);
5640 word_desc_to_read
= (WORD_DESC
*)NULL
;
5642 eol_ungetc_lookahead
= 0;
5644 /* added post-bash-5.1 */
5647 esacs_needed_count
= expecting_in_token
= 0;
5649 current_token
= '\n'; /* XXX */
5650 last_read_token
= '\n';
5651 token_to_read
= '\n';
5655 reset_readahead_token ()
5657 if (token_to_read
== '\n')
5661 /* Read the next token. Command can be READ (normal operation) or
5662 RESET (to normalize state). */
5664 read_token (command
)
5667 int character
; /* Current character. */
5668 int peek_char
; /* Temporary look-ahead character. */
5669 int result
; /* The thing to return. */
5671 if (command
== RESET
)
5679 result
= token_to_read
;
5680 if (token_to_read
== WORD
|| token_to_read
== ASSIGNMENT_WORD
)
5682 yylval
.word
= word_desc_to_read
;
5683 word_desc_to_read
= (WORD_DESC
*)NULL
;
5689 #if defined (COND_COMMAND)
5690 if ((parser_state
& (PST_CONDCMD
|PST_CONDEXPR
)) == PST_CONDCMD
)
5692 cond_lineno
= line_number
;
5693 parser_state
|= PST_CONDEXPR
;
5694 yylval
.command
= parse_cond_command ();
5695 if (cond_token
!= COND_END
)
5700 token_to_read
= COND_END
;
5701 parser_state
&= ~(PST_CONDEXPR
|PST_CONDCMD
);
5707 /* This is a place to jump back to once we have successfully expanded a
5708 token with an alias and pushed the string with push_string () */
5712 /* Read a single word from input. Start by skipping blanks. */
5713 while ((character
= shell_getc (1)) != EOF
&& shellblank (character
))
5716 if (character
== EOF
)
5722 /* If we hit the end of the string and we're not expanding an alias (e.g.,
5723 we are eval'ing a string that is an incomplete command), return EOF */
5724 if (character
== '\0' && bash_input
.type
== st_string
&& expanding_alias() == 0)
5726 INTERNAL_DEBUG (("shell_getc: bash_input.location.string = `%s'", bash_input
.location
.string
));
5731 if MBTEST(character
== '#' && (!interactive
|| interactive_comments
))
5733 /* A comment. Discard until EOL or EOF, and then return a newline. */
5734 parser_state
|= PST_COMMENT
;
5735 discard_until ('\n');
5737 parser_state
&= ~PST_COMMENT
;
5738 character
= '\n'; /* this will take the next if statement and return. */
5741 if MBTEST(character
== '\n')
5743 /* If we're about to return an unquoted newline, we can go and collect
5744 the text of any pending here document. */
5746 gather_here_documents ();
5749 parser_state
&= ~PST_ALEXPNEXT
;
5752 parser_state
&= ~PST_ASSIGNOK
;
5757 if (parser_state
& PST_REGEXP
)
5760 /* Shell meta-characters. */
5761 if MBTEST(shellmeta (character
))
5764 /* Turn off alias tokenization iff this character sequence would
5765 not leave us ready to read a command. */
5766 if (character
== '<' || character
== '>')
5767 parser_state
&= ~PST_ALEXPNEXT
;
5770 parser_state
&= ~PST_ASSIGNOK
;
5772 /* If we are parsing a command substitution and we have read a character
5773 that marks the end of it, don't bother to skip over quoted newlines
5774 when we read the next token. We're just interested in a character
5775 that will turn this into a two-character token, so we let the higher
5776 layers deal with quoted newlines following the command substitution. */
5777 if ((parser_state
& PST_CMDSUBST
) && character
== shell_eof_token
)
5778 peek_char
= shell_getc (0);
5780 peek_char
= shell_getc (1);
5782 if MBTEST(character
== peek_char
)
5787 /* If '<' then we could be at "<<" or at "<<-". We have to
5788 look ahead one more character. */
5789 peek_char
= shell_getc (1);
5790 if MBTEST(peek_char
== '-')
5791 return (LESS_LESS_MINUS
);
5792 else if MBTEST(peek_char
== '<')
5793 return (LESS_LESS_LESS
);
5796 shell_ungetc (peek_char
);
5801 return (GREATER_GREATER
);
5804 parser_state
|= PST_CASEPAT
;
5806 parser_state
&= ~PST_ALEXPNEXT
;
5809 peek_char
= shell_getc (1);
5810 if MBTEST(peek_char
== '&')
5811 return (SEMI_SEMI_AND
);
5814 shell_ungetc (peek_char
);
5824 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
5826 result
= parse_dparen (character
);
5834 else if MBTEST(character
== '<' && peek_char
== '&')
5836 else if MBTEST(character
== '>' && peek_char
== '&')
5837 return (GREATER_AND
);
5838 else if MBTEST(character
== '<' && peek_char
== '>')
5839 return (LESS_GREATER
);
5840 else if MBTEST(character
== '>' && peek_char
== '|')
5841 return (GREATER_BAR
);
5842 else if MBTEST(character
== '&' && peek_char
== '>')
5844 peek_char
= shell_getc (1);
5845 if MBTEST(peek_char
== '>')
5846 return (AND_GREATER_GREATER
);
5849 shell_ungetc (peek_char
);
5850 return (AND_GREATER
);
5853 else if MBTEST(character
== '|' && peek_char
== '&')
5855 else if MBTEST(character
== ';' && peek_char
== '&')
5857 parser_state
|= PST_CASEPAT
;
5859 parser_state
&= ~PST_ALEXPNEXT
;
5864 shell_ungetc (peek_char
);
5866 /* If we look like we are reading the start of a function
5867 definition, then let the reader know about it so that
5868 we will do the right thing with `{'. */
5869 if MBTEST(character
== ')' && last_read_token
== '(' && token_before_that
== WORD
)
5871 parser_state
|= PST_ALLOWOPNBRC
;
5873 parser_state
&= ~PST_ALEXPNEXT
;
5875 function_dstart
= line_number
;
5878 /* case pattern lists may be preceded by an optional left paren. If
5879 we're not trying to parse a case pattern list, the left paren
5880 indicates a subshell. */
5881 if MBTEST(character
== '(' && (parser_state
& PST_CASEPAT
) == 0) /* ) */
5882 parser_state
|= PST_SUBSHELL
;
5884 else if MBTEST((parser_state
& PST_CASEPAT
) && character
== ')')
5885 parser_state
&= ~PST_CASEPAT
;
5887 else if MBTEST((parser_state
& PST_SUBSHELL
) && character
== ')')
5888 parser_state
&= ~PST_SUBSHELL
;
5890 #if defined (PROCESS_SUBSTITUTION)
5891 /* Check for the constructs which introduce process substitution.
5892 Shells running in `posix mode' don't do process substitution. */
5893 if MBTEST((character
!= '>' && character
!= '<') || peek_char
!= '(') /*)*/
5894 #endif /* PROCESS_SUBSTITUTION */
5898 /* Hack <&- (close stdin) case. Also <&N- (dup and close). */
5899 if MBTEST(character
== '-' && (last_read_token
== LESS_AND
|| last_read_token
== GREATER_AND
))
5903 /* Okay, if we got this far, we have to read a word. Read one,
5904 and then check it against the known ones. */
5905 result
= read_token_word (character
);
5907 if (result
== RE_READ_TOKEN
)
5914 * Match a $(...) or other grouping construct. This has to handle embedded
5915 * quoted strings ('', ``, "") and nested constructs. It also must handle
5916 * reprompting the user, if necessary, after reading a newline, and returning
5917 * correct error values if it reads EOF.
5919 #define P_FIRSTCLOSE 0x0001
5920 #define P_ALLOWESC 0x0002
5921 #define P_DQUOTE 0x0004
5922 #define P_COMMAND 0x0008 /* parsing a command, so look for comments */
5923 #define P_BACKQUOTE 0x0010 /* parsing a backquoted command substitution */
5924 #define P_ARRAYSUB 0x0020 /* parsing a [...] array subscript for assignment */
5925 #define P_DOLBRACE 0x0040 /* parsing a ${...} construct */
5926 #define P_ARITH 0x0080 /* parsing a $(( )) arithmetic expansion */
5928 /* Lexical state while parsing a grouping construct or $(...). */
5929 #define LEX_WASDOL 0x0001
5930 #define LEX_CKCOMMENT 0x0002
5931 #define LEX_INCOMMENT 0x0004
5932 #define LEX_PASSNEXT 0x0008
5933 #define LEX_RESWDOK 0x0010
5934 #define LEX_CKCASE 0x0020
5935 #define LEX_INCASE 0x0040
5936 #define LEX_INHEREDOC 0x0080
5937 #define LEX_HEREDELIM 0x0100 /* reading here-doc delimiter */
5938 #define LEX_STRIPDOC 0x0200 /* <<- strip tabs from here doc delim */
5939 #define LEX_QUOTEDDOC 0x0400 /* here doc with quoted delim */
5940 #define LEX_INWORD 0x0800
5941 #define LEX_GTLT 0x1000
5942 #define LEX_CKESAC 0x2000 /* check esac after in -- for later */
5943 #define LEX_CASEWD 0x4000 /* word after case */
5944 #define LEX_PATLIST 0x8000 /* case statement pattern list */
5946 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
5948 #define CHECK_NESTRET_ERROR() \
5950 if (nestret == &matched_pair_error) \
5953 return &matched_pair_error; \
5957 #define APPEND_NESTRET() \
5961 RESIZE_MALLOCED_BUFFER (ret, retind, nestlen, retsize, 64); \
5962 strcpy (ret + retind, nestret); \
5963 retind += nestlen; \
5967 static char matched_pair_error
;
5970 parse_matched_pair (qc
, open
, close
, lenp
, flags
)
5971 int qc
; /* `"' if this construct is within double quotes */
5975 int count
, ch
, prevch
, tflags
;
5976 int nestlen
, ttranslen
, start_lineno
;
5977 char *ret
, *nestret
, *ttrans
;
5978 int retind
, retsize
, rflags
;
5981 dolbrace_state
= (flags
& P_DOLBRACE
) ? DOLBRACE_PARAM
: 0;
5983 /*itrace("parse_matched_pair[%d]: open = %c close = %c flags = %d", line_number, open, close, flags);*/
5987 if ((flags
& P_COMMAND
) && qc
!= '`' && qc
!= '\'' && qc
!= '"' && (flags
& P_DQUOTE
) == 0)
5988 tflags
|= LEX_CKCOMMENT
;
5990 /* RFLAGS is the set of flags we want to pass to recursive calls. */
5991 rflags
= (qc
== '"') ? P_DQUOTE
: (flags
& P_DQUOTE
);
5993 ret
= (char *)xmalloc (retsize
= 64);
5996 start_lineno
= line_number
;
5997 ch
= EOF
; /* just in case */
6001 ch
= shell_getc (qc
!= '\'' && (tflags
& (LEX_PASSNEXT
)) == 0);
6006 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), close
);
6007 EOF_Reached
= 1; /* XXX */
6008 return (&matched_pair_error
);
6011 /* Possible reprompting. */
6012 if MBTEST(ch
== '\n' && SHOULD_PROMPT ())
6015 /* Don't bother counting parens or doing anything else if in a comment
6016 or part of a case statement */
6017 if (tflags
& LEX_INCOMMENT
)
6019 /* Add this character. */
6020 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6023 if MBTEST(ch
== '\n')
6024 tflags
&= ~LEX_INCOMMENT
;
6029 /* Not exactly right yet, should handle shell metacharacters, too. If
6030 any changes are made to this test, make analogous changes to subst.c:
6031 extract_delimited_string(). */
6032 else if MBTEST((tflags
& LEX_CKCOMMENT
) && (tflags
& LEX_INCOMMENT
) == 0 && ch
== '#' && (retind
== 0 || ret
[retind
-1] == '\n' || shellblank (ret
[retind
- 1])))
6033 tflags
|= LEX_INCOMMENT
;
6035 if (tflags
& LEX_PASSNEXT
) /* last char was backslash */
6037 tflags
&= ~LEX_PASSNEXT
;
6038 /* XXX - PST_NOEXPAND? */
6039 if MBTEST(qc
!= '\'' && ch
== '\n') /* double-quoted \<newline> disappears. */
6042 retind
--; /* swallow previously-added backslash */
6046 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6047 if MBTEST(ch
== CTLESC
)
6048 ret
[retind
++] = CTLESC
;
6052 /* If we're reparsing the input (e.g., from parse_string_to_word_list),
6053 we've already prepended CTLESC to single-quoted results of $'...'.
6054 We may want to do this for other CTLESC-quoted characters in
6056 else if MBTEST((parser_state
& PST_REPARSE
) && open
== '\'' && (ch
== CTLESC
|| ch
== CTLNUL
))
6058 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6062 else if MBTEST(ch
== CTLESC
|| ch
== CTLNUL
) /* special shell escapes */
6064 RESIZE_MALLOCED_BUFFER (ret
, retind
, 2, retsize
, 64);
6065 ret
[retind
++] = CTLESC
;
6069 else if MBTEST(ch
== close
) /* ending delimiter */
6071 /* handle nested ${...} specially. */
6072 else if MBTEST(open
!= close
&& (tflags
& LEX_WASDOL
) && open
== '{' && ch
== open
) /* } */
6074 else if MBTEST(((flags
& P_FIRSTCLOSE
) == 0) && ch
== open
) /* nested begin */
6077 /* Add this character. */
6078 RESIZE_MALLOCED_BUFFER (ret
, retind
, 1, retsize
, 64);
6081 /* If we just read the ending character, don't bother continuing. */
6085 if (open
== '\'') /* '' inside grouping construct */
6087 if MBTEST((flags
& P_ALLOWESC
) && ch
== '\\')
6088 tflags
|= LEX_PASSNEXT
;
6092 if MBTEST(ch
== '\\') /* backslashes */
6093 tflags
|= LEX_PASSNEXT
;
6095 /* Based on which dolstate is currently in (param, op, or word),
6096 decide what the op is. We're really only concerned if it's % or
6097 #, so we can turn on a flag that says whether or not we should
6098 treat single quotes as special when inside a double-quoted
6099 ${...}. This logic must agree with subst.c:extract_dollar_brace_string
6100 since they share the same defines. */
6101 /* FLAG POSIX INTERP 221 */
6102 if (flags
& P_DOLBRACE
)
6104 /* ${param%[%]word} */
6105 if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '%' && retind
> 1)
6106 dolbrace_state
= DOLBRACE_QUOTE
;
6107 /* ${param#[#]word} */
6108 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '#' && retind
> 1)
6109 dolbrace_state
= DOLBRACE_QUOTE
;
6110 /* ${param/[/]pat/rep} */
6111 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '/' && retind
> 1)
6112 dolbrace_state
= DOLBRACE_QUOTE2
; /* XXX */
6113 /* ${param^[^]pat} */
6114 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== '^' && retind
> 1)
6115 dolbrace_state
= DOLBRACE_QUOTE
;
6116 /* ${param,[,]pat} */
6117 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& ch
== ',' && retind
> 1)
6118 dolbrace_state
= DOLBRACE_QUOTE
;
6119 else if MBTEST(dolbrace_state
== DOLBRACE_PARAM
&& strchr ("#%^,~:-=?+/", ch
) != 0)
6120 dolbrace_state
= DOLBRACE_OP
;
6121 else if MBTEST(dolbrace_state
== DOLBRACE_OP
&& strchr ("#%^,~:-=?+/", ch
) == 0)
6122 dolbrace_state
= DOLBRACE_WORD
;
6125 /* The big hammer. Single quotes aren't special in double quotes. The
6126 problem is that Posix used to say the single quotes are semi-special:
6127 within a double-quoted ${...} construct "an even number of
6128 unescaped double-quotes or single-quotes, if any, shall occur." */
6129 /* This was changed in Austin Group Interp 221 */
6130 if MBTEST(posixly_correct
&& shell_compatibility_level
> 41 && dolbrace_state
!= DOLBRACE_QUOTE
&& dolbrace_state
!= DOLBRACE_QUOTE2
&& (flags
& P_DQUOTE
) && (flags
& P_DOLBRACE
) && ch
== '\'')
6133 /* Could also check open == '`' if we want to parse grouping constructs
6134 inside old-style command substitution. */
6135 if (open
!= close
) /* a grouping construct */
6137 if MBTEST(shellquote (ch
))
6139 /* '', ``, or "" inside $(...) or other grouping construct. */
6140 push_delimiter (dstack
, ch
);
6141 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'') /* $'...' inside group */
6142 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, P_ALLOWESC
|rflags
);
6144 nestret
= parse_matched_pair (ch
, ch
, ch
, &nestlen
, rflags
);
6145 pop_delimiter (dstack
);
6146 CHECK_NESTRET_ERROR ();
6148 if MBTEST((tflags
& LEX_WASDOL
) && ch
== '\'' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0 || dolbrace_state
== DOLBRACE_QUOTE
|| dolbrace_state
== DOLBRACE_QUOTE2
))
6150 /* Translate $'...' here. */
6152 ttrans
= ansiexpand (nestret
, 0, nestlen
- 1, &ttranslen
);
6155 /* If we're parsing a double-quoted brace expansion and we are
6156 not in a place where single quotes are treated specially,
6157 make sure we single-quote the results of the ansi
6158 expansion because quote removal should remove them later */
6159 /* FLAG POSIX INTERP 221 */
6160 if ((shell_compatibility_level
> 42) && (rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_QUOTE2
|| dolbrace_state
== DOLBRACE_QUOTE
) && (flags
& P_DOLBRACE
))
6162 nestret
= sh_single_quote (ttrans
);
6164 nestlen
= strlen (nestret
);
6166 #if 0 /* TAG:bash-5.3 */
6167 /* This single-quotes PARAM in ${PARAM OP WORD} when PARAM
6168 contains a $'...' even when extended_quote is set. */
6169 else if ((rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_PARAM
) && (flags
& P_DOLBRACE
))
6171 nestret
= sh_single_quote (ttrans
);
6173 nestlen
= strlen (nestret
);
6176 else if ((rflags
& P_DQUOTE
) == 0)
6178 nestret
= sh_single_quote (ttrans
);
6180 nestlen
= strlen (nestret
);
6184 /* Should we quote CTLESC here? */
6186 nestlen
= ttranslen
;
6188 retind
-= 2; /* back up before the $' */
6190 #if defined (TRANSLATABLE_STRINGS)
6191 else if MBTEST((tflags
& LEX_WASDOL
) && ch
== '"' && (extended_quote
|| (rflags
& P_DQUOTE
) == 0))
6193 /* Locale expand $"..." here. */
6195 ttrans
= locale_expand (nestret
, 0, nestlen
- 1, start_lineno
, &ttranslen
);
6198 /* If we're supposed to single-quote translated strings,
6199 check whether the translated result is different from
6200 the original and single-quote the string if it is. */
6201 if (singlequote_translations
&&
6202 ((nestlen
- 1) != ttranslen
|| STREQN (nestret
, ttrans
, ttranslen
) == 0))
6204 if ((rflags
& P_DQUOTE
) == 0)
6205 nestret
= sh_single_quote (ttrans
);
6206 else if ((rflags
& P_DQUOTE
) && (dolbrace_state
== DOLBRACE_QUOTE2
) && (flags
& P_DOLBRACE
))
6207 nestret
= sh_single_quote (ttrans
);
6209 /* single quotes aren't special, use backslash instead */
6210 nestret
= sh_backslash_quote_for_double_quotes (ttrans
, 0);
6213 nestret
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
6215 nestlen
= strlen (nestret
);
6216 retind
-= 2; /* back up before the $" */
6218 #endif /* TRANSLATABLE_STRINGS */
6223 else if ((flags
& (P_ARRAYSUB
|P_DOLBRACE
)) && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6224 goto parse_dollar_word
;
6225 else if ((flags
& P_ARITH
) && (tflags
& LEX_WASDOL
) && ch
== '(') /*)*/
6226 /* $() inside $(( ))/$[ ] */
6227 goto parse_dollar_word
;
6228 #if defined (PROCESS_SUBSTITUTION)
6229 /* XXX - technically this should only be recognized at the start of
6231 else if ((flags
& (P_ARRAYSUB
|P_DOLBRACE
)) && (tflags
& LEX_GTLT
) && (ch
== '(')) /* ) */
6232 goto parse_dollar_word
;
6235 /* Parse an old-style command substitution within double quotes as a
6237 /* XXX - sh and ksh93 don't do this - XXX */
6238 else if MBTEST(open
== '"' && ch
== '`')
6240 nestret
= parse_matched_pair (0, '`', '`', &nestlen
, rflags
);
6242 CHECK_NESTRET_ERROR ();
6247 else if MBTEST(open
!= '`' && (tflags
& LEX_WASDOL
) && (ch
== '(' || ch
== '{' || ch
== '[')) /* ) } ] */
6248 /* check for $(), $[], or ${} inside quoted string. */
6251 if (open
== ch
) /* undo previous increment */
6253 if (ch
== '(') /* ) */
6254 nestret
= parse_comsub (0, '(', ')', &nestlen
, (rflags
|P_COMMAND
) & ~P_DQUOTE
);
6255 else if (ch
== '{') /* } */
6256 nestret
= parse_matched_pair (0, '{', '}', &nestlen
, P_FIRSTCLOSE
|P_DOLBRACE
|rflags
);
6257 else if (ch
== '[') /* ] */
6258 nestret
= parse_matched_pair (0, '[', ']', &nestlen
, rflags
|P_ARITH
);
6260 CHECK_NESTRET_ERROR ();
6265 #if defined (PROCESS_SUBSTITUTION)
6266 if MBTEST((ch
== '<' || ch
== '>') && (tflags
& LEX_GTLT
) == 0)
6269 tflags
&= ~LEX_GTLT
;
6271 if MBTEST(ch
== '$' && (tflags
& LEX_WASDOL
) == 0)
6272 tflags
|= LEX_WASDOL
;
6274 tflags
&= ~LEX_WASDOL
;
6280 /*itrace("parse_matched_pair[%d]: returning %s", line_number, ret);*/
6292 fprintf (stderr
, "%d -> ", f
);
6296 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
6298 if (f
& LEX_CKCOMMENT
)
6300 f
&= ~LEX_CKCOMMENT
;
6301 fprintf (stderr
, "LEX_CKCOMMENT%s", f
? "|" : "");
6303 if (f
& LEX_INCOMMENT
)
6305 f
&= ~LEX_INCOMMENT
;
6306 fprintf (stderr
, "LEX_INCOMMENT%s", f
? "|" : "");
6308 if (f
& LEX_PASSNEXT
)
6311 fprintf (stderr
, "LEX_PASSNEXT%s", f
? "|" : "");
6313 if (f
& LEX_RESWDOK
)
6316 fprintf (stderr
, "LEX_RESWDOK%s", f
? "|" : "");
6321 fprintf (stderr
, "LEX_CKCASE%s", f
? "|" : "");
6326 fprintf (stderr
, "LEX_CKESAC%s", f
? "|" : "");
6331 fprintf (stderr
, "LEX_INCASE%s", f
? "|" : "");
6336 fprintf (stderr
, "LEX_CASEWD%s", f
? "|" : "");
6338 if (f
& LEX_PATLIST
)
6341 fprintf (stderr
, "LEX_PATLIST%s", f
? "|" : "");
6343 if (f
& LEX_INHEREDOC
)
6345 f
&= ~LEX_INHEREDOC
;
6346 fprintf (stderr
, "LEX_INHEREDOC%s", f
? "|" : "");
6348 if (f
& LEX_HEREDELIM
)
6350 f
&= ~LEX_HEREDELIM
;
6351 fprintf (stderr
, "LEX_HEREDELIM%s", f
? "|" : "");
6353 if (f
& LEX_STRIPDOC
)
6356 fprintf (stderr
, "LEX_WASDOL%s", f
? "|" : "");
6358 if (f
& LEX_QUOTEDDOC
)
6360 f
&= ~LEX_QUOTEDDOC
;
6361 fprintf (stderr
, "LEX_QUOTEDDOC%s", f
? "|" : "");
6366 fprintf (stderr
, "LEX_INWORD%s", f
? "|" : "");
6369 fprintf (stderr
, "\n");
6374 /* Parse a $(...) command substitution. This reads input from the current
6377 parse_comsub (qc
, open
, close
, lenp
, flags
)
6378 int qc
; /* `"' if this construct is within double quotes */
6383 int start_lineno
, local_extglob
, was_extpat
;
6386 sh_parser_state_t ps
;
6387 STRING_SAVER
*saved_strings
;
6388 COMMAND
*saved_global
, *parsed_command
;
6390 /* Posix interp 217 says arithmetic expressions have precedence, so
6391 assume $(( introduces arithmetic expansion and parse accordingly. */
6392 if (open
== '(') /*)*/
6394 peekc
= shell_getc (1);
6395 shell_ungetc (peekc
);
6396 if (peekc
== '(') /*)*/
6397 return (parse_matched_pair (qc
, open
, close
, lenp
, P_ARITH
));
6400 /*itrace("parse_comsub: qc = `%c' open = %c close = %c", qc, open, close);*/
6402 /*debug_parser(1);*/
6403 start_lineno
= line_number
;
6405 save_parser_state (&ps
);
6407 was_extpat
= (parser_state
& PST_EXTPAT
);
6409 /* State flags we don't want to persist into command substitutions. */
6410 parser_state
&= ~(PST_REGEXP
|PST_EXTPAT
|PST_CONDCMD
|PST_CONDEXPR
|PST_COMPASSIGN
);
6411 /* Could do PST_CASESTMT too, but that also affects history. Setting
6412 expecting_in_token below should take care of the parsing requirements.
6413 Unsetting PST_REDIRLIST isn't strictly necessary because of how we set
6414 token_to_read below, but we do it anyway. */
6415 parser_state
&= ~(PST_CASEPAT
|PST_ALEXPNEXT
|PST_SUBSHELL
|PST_REDIRLIST
);
6416 /* State flags we want to set for this run through the parser. */
6417 parser_state
|= PST_CMDSUBST
|PST_EOFTOKEN
|PST_NOEXPAND
;
6419 /* leave pushed_string_list alone, since we might need to consume characters
6420 from it to satisfy this command substitution (in some perverse case). */
6421 shell_eof_token
= close
;
6423 saved_global
= global_command
; /* might not be necessary */
6424 global_command
= (COMMAND
*)NULL
;
6426 /* These are reset by reset_parser() */
6428 esacs_needed_count
= expecting_in_token
= 0;
6430 /* We want to expand aliases on this pass if we're in posix mode, since the
6431 standard says you have to take aliases into account when looking for the
6432 terminating right paren. Otherwise, we defer until execution time for
6433 backwards compatibility. */
6435 expand_aliases
= posixly_correct
!= 0;
6436 #if defined (EXTENDED_GLOB)
6437 /* If (parser_state & PST_EXTPAT), we're parsing an extended pattern for a
6438 conditional command and have already set extended_glob appropriately. */
6439 if (shell_compatibility_level
<= 51 && was_extpat
== 0)
6441 local_extglob
= extended_glob
;
6446 current_token
= '\n'; /* XXX */
6447 token_to_read
= DOLPAREN
; /* let's trick the parser */
6451 if (need_here_doc
> 0)
6453 internal_warning ("command substitution: %d unterminated here-document%s", need_here_doc
, (need_here_doc
== 1) ? "" : "s");
6454 gather_here_documents (); /* XXX check compatibility level? */
6457 #if defined (EXTENDED_GLOB)
6458 if (shell_compatibility_level
<= 51 && was_extpat
== 0)
6459 extended_glob
= local_extglob
;
6462 parsed_command
= global_command
;
6466 shell_eof_token
= ps
.eof_token
;
6467 expand_aliases
= ps
.expand_aliases
;
6469 /* yyparse() has already called yyerror() and reset_parser() */
6470 return (&matched_pair_error
);
6474 /* parser_error (start_lineno, _("could not parse command substitution")); */
6475 /* Non-interactive shells exit on parse error in a command substitution. */
6476 if (last_command_exit_value
== 0)
6477 last_command_exit_value
= EXECUTION_FAILURE
;
6478 set_exit_status (last_command_exit_value
);
6479 if (interactive_shell
== 0)
6480 jump_to_top_level (FORCE_EOF
); /* This is like reader_loop() */
6483 shell_eof_token
= ps
.eof_token
;
6484 expand_aliases
= ps
.expand_aliases
;
6486 jump_to_top_level (DISCARD
); /* XXX - return (&matched_pair_error)? */
6490 if (current_token
!= shell_eof_token
)
6492 INTERNAL_DEBUG(("current_token (%d) != shell_eof_token (%c)", current_token
, shell_eof_token
));
6493 token_to_read
= current_token
;
6495 /* If we get here we can check eof_encountered and if it's 1 but the
6496 previous EOF_Reached test didn't succeed, we can assume that the shell
6497 is interactive and ignoreeof is set. We might want to restore the
6498 parser state in this case. */
6499 shell_eof_token
= ps
.eof_token
;
6500 expand_aliases
= ps
.expand_aliases
;
6502 return (&matched_pair_error
);
6505 /* We don't want to restore the old pushed string list, since we might have
6506 used it to consume additional input from an alias while parsing this
6507 command substitution. */
6508 saved_strings
= pushed_string_list
;
6509 restore_parser_state (&ps
);
6510 pushed_string_list
= saved_strings
;
6512 tcmd
= print_comsub (parsed_command
); /* returns static memory */
6513 retlen
= strlen (tcmd
);
6514 if (tcmd
[0] == '(') /* ) need a space to prevent arithmetic expansion */
6516 ret
= xmalloc (retlen
+ 2);
6517 if (tcmd
[0] == '(') /* ) */
6520 strcpy (ret
+ 1, tcmd
);
6524 ret
[retlen
++] = ')';
6527 dispose_command (parsed_command
);
6528 global_command
= saved_global
;
6533 /*itrace("parse_comsub:%d: returning `%s'", line_number, ret);*/
6537 /* Recursively call the parser to parse a $(...) command substitution. This is
6538 called by the word expansion code and so does not have to reset as much
6539 parser state before calling yyparse(). */
6541 xparse_dolparen (base
, string
, indp
, flags
)
6547 sh_parser_state_t ps
;
6548 sh_input_line_state_t ls
;
6549 int orig_ind
, nc
, sflags
, start_lineno
, local_extglob
;
6550 char *ret
, *ep
, *ostring
;
6552 /*debug_parser(1);*/
6555 start_lineno
= line_number
;
6559 if (flags
& SX_NOALLOC
)
6560 return (char *)NULL
;
6567 /*itrace("xparse_dolparen: size = %d shell_input_line = `%s' string=`%s'", shell_input_line_size, shell_input_line, string);*/
6569 sflags
= SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOFREE
;
6570 if (flags
& SX_NOLONGJMP
)
6571 sflags
|= SEVAL_NOLONGJMP
;
6573 save_parser_state (&ps
);
6574 save_input_line_state (&ls
);
6576 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
6577 pushed_string_list
= (STRING_SAVER
*)NULL
;
6580 parser_state
|= PST_CMDSUBST
|PST_EOFTOKEN
; /* allow instant ')' */ /*(*/
6581 shell_eof_token
= ')';
6582 if (flags
& SX_COMPLETE
)
6583 parser_state
|= PST_NOERROR
;
6585 /* Don't expand aliases on this pass at all. Either parse_comsub() does it
6586 at parse time, in which case this string already has aliases expanded,
6587 or command_substitute() does it in the child process executing the
6588 command substitution and we want to defer it completely until then. The
6589 old value will be restored by restore_parser_state(). */
6591 #if defined (EXTENDED_GLOB)
6592 local_extglob
= extended_glob
;
6595 token_to_read
= DOLPAREN
; /* let's trick the parser */
6597 nc
= parse_string (string
, "command substitution", sflags
, (COMMAND
**)NULL
, &ep
);
6599 /* Should we save and restore the bison/yacc lookahead token (yychar) here?
6600 Or only if it's not YYEMPTY? */
6601 if (current_token
== shell_eof_token
)
6602 yyclearin
; /* might want to clear lookahead token unconditionally */
6604 reset_parser (); /* resets extended_glob too */
6605 /* reset_parser() clears shell_input_line and associated variables, including
6606 parser_state, so we want to reset things, then restore what we need. */
6607 restore_input_line_state (&ls
);
6608 restore_parser_state (&ps
);
6610 #if defined (EXTENDED_GLOB)
6611 extended_glob
= local_extglob
;
6615 /* If parse_string returns < 0, we need to jump to top level with the
6616 negative of the return value. We abandon the rest of this input line
6620 clear_shell_input_line (); /* XXX */
6621 if (bash_input
.type
!= st_string
) /* paranoia */
6622 parser_state
&= ~(PST_CMDSUBST
|PST_EOFTOKEN
);
6623 if ((flags
& SX_NOLONGJMP
) == 0)
6624 jump_to_top_level (-nc
); /* XXX */
6627 /* Need to find how many characters parse_string() consumed, update
6628 *indp, if flags != 0, copy the portion of the string parsed into RET
6629 and return it. If flags & 1 (SX_NOALLOC) we can return NULL. */
6636 itrace("xparse_dolparen:%d: ep[-1] != RPAREN (%d), ep = `%s'", line_number
, ep
[-1], ep
);
6639 while (ep
> ostring
&& ep
[-1] == '\n') ep
--;
6643 *indp
= ep
- base
- 1;
6647 if (base
[*indp
] != ')')
6648 itrace("xparse_dolparen:%d: base[%d] != RPAREN (%d), base = `%s'", line_number
, *indp
, base
[*indp
], base
);
6649 if (*indp
< orig_ind
)
6650 itrace("xparse_dolparen:%d: *indp (%d) < orig_ind (%d), orig_string = `%s'", line_number
, *indp
, orig_ind
, ostring
);
6653 if (base
[*indp
] != ')' && (flags
& SX_NOLONGJMP
) == 0)
6656 if ((flags
& SX_NOERROR
) == 0)
6657 parser_error (start_lineno
, _("unexpected EOF while looking for matching `%c'"), ')');
6658 jump_to_top_level (DISCARD
);
6661 if (flags
& SX_NOALLOC
)
6662 return (char *)NULL
;
6670 ret
= substring (ostring
, 0, nc
- 1);
6675 /* Recursively call the parser to parse the string from a $(...) command
6676 substitution to a COMMAND *. This is called from command_substitute() and
6677 has the same parser state constraints as xparse_dolparen(). */
6679 parse_string_to_command (string
, flags
)
6683 sh_parser_state_t ps
;
6684 sh_input_line_state_t ls
;
6691 return (COMMAND
*)NULL
;
6694 slen
= STRLEN (string
);
6696 /*itrace("parse_string_to_command: size = %d shell_input_line = `%s' string=`%s'", shell_input_line_size, shell_input_line, string);*/
6698 sflags
= SEVAL_NONINT
|SEVAL_NOHIST
|SEVAL_NOFREE
;
6699 if (flags
& SX_NOLONGJMP
)
6700 sflags
|= SEVAL_NOLONGJMP
;
6702 save_parser_state (&ps
);
6703 save_input_line_state (&ls
);
6705 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
6706 pushed_string_list
= (STRING_SAVER
*)NULL
;
6708 if (flags
& SX_COMPLETE
)
6709 parser_state
|= PST_NOERROR
;
6711 parser_state
|= PST_STRING
;
6715 nc
= parse_string (string
, "command substitution", sflags
, &cmd
, &ep
);
6718 /* reset_parser() clears shell_input_line and associated variables, including
6719 parser_state, so we want to reset things, then restore what we need. */
6720 restore_input_line_state (&ls
);
6721 restore_parser_state (&ps
);
6723 /* If parse_string returns < 0, we need to jump to top level with the
6724 negative of the return value. We abandon the rest of this input line
6728 clear_shell_input_line (); /* XXX */
6729 if ((flags
& SX_NOLONGJMP
) == 0)
6730 jump_to_top_level (-nc
); /* XXX */
6733 /* Need to check how many characters parse_string() consumed, make sure it's
6734 the entire string. */
6737 dispose_command (cmd
);
6738 return (COMMAND
*)NULL
;
6744 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
6745 /* Parse a double-paren construct. It can be either an arithmetic
6746 command, an arithmetic `for' command, or a nested subshell. Returns
6747 the parsed token, -1 on error, or -2 if we didn't do anything and
6748 should just go on. */
6757 #if defined (ARITH_FOR_COMMAND)
6758 if (last_read_token
== FOR
)
6760 if (word_top
< MAX_CASE_NEST
)
6762 arith_for_lineno
= word_lineno
[word_top
] = line_number
;
6763 cmdtyp
= parse_arith_cmd (&wval
, 0);
6766 wd
= alloc_word_desc ();
6768 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6769 return (ARITH_FOR_EXPRS
);
6772 return -1; /* ERROR */
6776 #if defined (DPAREN_ARITHMETIC)
6777 if (reserved_word_acceptable (last_read_token
))
6779 sline
= line_number
;
6781 cmdtyp
= parse_arith_cmd (&wval
, 0);
6782 if (cmdtyp
== 1) /* arithmetic command */
6784 wd
= alloc_word_desc ();
6786 wd
->flags
= W_QUOTED
|W_NOSPLIT
|W_NOGLOB
|W_NOTILDE
|W_NOPROCSUB
;
6787 yylval
.word_list
= make_word_list (wd
, (WORD_LIST
*)NULL
);
6790 else if (cmdtyp
== 0) /* nested subshell */
6792 push_string (wval
, 0, (alias_t
*)NULL
);
6793 pushed_string_list
->flags
= PSH_DPAREN
;
6794 if ((parser_state
& PST_CASEPAT
) == 0)
6795 parser_state
|= PST_SUBSHELL
;
6803 return -2; /* XXX */
6806 /* We've seen a `(('. Look for the matching `))'. If we get it, return 1.
6807 If not, assume it's a nested subshell for backwards compatibility and
6808 return 0. In any case, put the characters we've consumed into a locally-
6809 allocated buffer and make *ep point to that buffer. Return -1 on an
6810 error, for example EOF. */
6812 parse_arith_cmd (ep
, adddq
)
6816 int exp_lineno
, rval
, c
;
6817 char *ttok
, *tokstr
;
6820 exp_lineno
= line_number
;
6821 ttok
= parse_matched_pair (0, '(', ')', &ttoklen
, P_ARITH
);
6823 if (ttok
== &matched_pair_error
)
6825 /* Check that the next character is the closing right paren. If
6826 not, this is a syntax error. ( */
6831 tokstr
= (char *)xmalloc (ttoklen
+ 4);
6833 /* if ADDDQ != 0 then (( ... )) -> "..." */
6834 if (rval
== 1 && adddq
) /* arith cmd, add double quotes */
6837 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6838 tokstr
[ttoklen
] = '"';
6839 tokstr
[ttoklen
+1] = '\0';
6841 else if (rval
== 1) /* arith cmd, don't add double quotes */
6843 strncpy (tokstr
, ttok
, ttoklen
- 1);
6844 tokstr
[ttoklen
-1] = '\0';
6846 else /* nested subshell */
6849 strncpy (tokstr
+ 1, ttok
, ttoklen
- 1);
6850 tokstr
[ttoklen
] = ')';
6851 tokstr
[ttoklen
+1] = c
;
6852 tokstr
[ttoklen
+2] = '\0';
6859 #endif /* DPAREN_ARITHMETIC || ARITH_FOR_COMMAND */
6861 #if defined (COND_COMMAND)
6867 if (EOF_Reached
&& cond_token
!= COND_ERROR
) /* [[ */
6868 parser_error (cond_lineno
, _("unexpected EOF while looking for `]]'"));
6869 else if (cond_token
!= COND_ERROR
)
6871 if (etext
= error_token_from_token (cond_token
))
6873 parser_error (cond_lineno
, _("syntax error in conditional expression: unexpected token `%s'"), etext
);
6877 parser_error (cond_lineno
, _("syntax error in conditional expression"));
6884 return (cond_or ());
6893 if (cond_token
== OR_OR
)
6896 l
= make_cond_node (COND_OR
, (WORD_DESC
*)NULL
, l
, r
);
6907 if (cond_token
== AND_AND
)
6910 l
= make_cond_node (COND_AND
, (WORD_DESC
*)NULL
, l
, r
);
6916 cond_skip_newlines ()
6918 while ((cond_token
= read_token (READ
)) == '\n')
6920 if (SHOULD_PROMPT ())
6923 return (cond_token
);
6926 #define COND_RETURN_ERROR() \
6927 do { cond_token = COND_ERROR; return ((COND_COM *)NULL); } while (0)
6933 COND_COM
*term
, *tleft
, *tright
;
6934 int tok
, lineno
, local_extglob
;
6937 /* Read a token. It can be a left paren, a `!', a unary operator, or a
6938 word that should be the first argument of a binary operator. Start by
6939 skipping newlines, since this is a compound command. */
6940 tok
= cond_skip_newlines ();
6941 lineno
= line_number
;
6942 if (tok
== COND_END
)
6944 COND_RETURN_ERROR ();
6946 else if (tok
== '(')
6948 term
= cond_expr ();
6949 if (cond_token
!= ')')
6952 dispose_cond_node (term
); /* ( */
6953 if (etext
= error_token_from_token (cond_token
))
6955 parser_error (lineno
, _("unexpected token `%s', expected `)'"), etext
);
6959 parser_error (lineno
, _("expected `)'"));
6960 COND_RETURN_ERROR ();
6962 term
= make_cond_node (COND_EXPR
, (WORD_DESC
*)NULL
, term
, (COND_COM
*)NULL
);
6963 (void)cond_skip_newlines ();
6965 else if (tok
== BANG
|| (tok
== WORD
&& (yylval
.word
->word
[0] == '!' && yylval
.word
->word
[1] == '\0')))
6968 dispose_word (yylval
.word
); /* not needed */
6969 term
= cond_term ();
6971 term
->flags
^= CMD_INVERT_RETURN
;
6973 else if (tok
== WORD
&& yylval
.word
->word
[0] == '-' && yylval
.word
->word
[1] && yylval
.word
->word
[2] == 0 && test_unop (yylval
.word
->word
))
6976 tok
= read_token (READ
);
6979 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
6980 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
6985 if (etext
= error_token_from_token (tok
))
6987 parser_error (line_number
, _("unexpected argument `%s' to conditional unary operator"), etext
);
6991 parser_error (line_number
, _("unexpected argument to conditional unary operator"));
6992 COND_RETURN_ERROR ();
6995 (void)cond_skip_newlines ();
6997 else if (tok
== WORD
) /* left argument to binary operator */
7000 tleft
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7003 /* tok = cond_skip_newlines (); ? */
7004 tok
= read_token (READ
);
7005 if (tok
== WORD
&& test_binop (yylval
.word
->word
))
7008 if (op
->word
[0] == '=' && (op
->word
[1] == '\0' || (op
->word
[1] == '=' && op
->word
[2] == '\0')))
7009 parser_state
|= PST_EXTPAT
;
7010 else if (op
->word
[0] == '!' && op
->word
[1] == '=' && op
->word
[2] == '\0')
7011 parser_state
|= PST_EXTPAT
;
7013 #if defined (COND_REGEXP)
7014 else if (tok
== WORD
&& STREQ (yylval
.word
->word
, "=~"))
7017 parser_state
|= PST_REGEXP
;
7020 else if (tok
== '<' || tok
== '>')
7021 op
= make_word_from_token (tok
); /* ( */
7022 /* There should be a check before blindly accepting the `)' that we have
7023 seen the opening `('. */
7024 else if (tok
== COND_END
|| tok
== AND_AND
|| tok
== OR_OR
|| tok
== ')')
7026 /* Special case. [[ x ]] is equivalent to [[ -n x ]], just like
7027 the test command. Similarly for [[ x && expr ]] or
7028 [[ x || expr ]] or [[ (x) ]]. */
7029 op
= make_word ("-n");
7030 term
= make_cond_node (COND_UNARY
, op
, tleft
, (COND_COM
*)NULL
);
7036 if (etext
= error_token_from_token (tok
))
7038 parser_error (line_number
, _("unexpected token `%s', conditional binary operator expected"), etext
);
7042 parser_error (line_number
, _("conditional binary operator expected"));
7043 dispose_cond_node (tleft
);
7044 COND_RETURN_ERROR ();
7048 #if defined (EXTENDED_GLOB)
7049 local_extglob
= extended_glob
;
7050 if (parser_state
& PST_EXTPAT
)
7053 tok
= read_token (READ
);
7054 #if defined (EXTENDED_GLOB)
7055 if (parser_state
& PST_EXTPAT
)
7056 extended_glob
= local_extglob
;
7058 parser_state
&= ~(PST_REGEXP
|PST_EXTPAT
);
7062 tright
= make_cond_node (COND_TERM
, yylval
.word
, (COND_COM
*)NULL
, (COND_COM
*)NULL
);
7063 term
= make_cond_node (COND_BINARY
, op
, tleft
, tright
);
7067 if (etext
= error_token_from_token (tok
))
7069 parser_error (line_number
, _("unexpected argument `%s' to conditional binary operator"), etext
);
7073 parser_error (line_number
, _("unexpected argument to conditional binary operator"));
7074 dispose_cond_node (tleft
);
7076 COND_RETURN_ERROR ();
7079 (void)cond_skip_newlines ();
7084 parser_error (line_number
, _("unexpected token `%c' in conditional command"), tok
);
7085 else if (etext
= error_token_from_token (tok
))
7087 parser_error (line_number
, _("unexpected token `%s' in conditional command"), etext
);
7091 parser_error (line_number
, _("unexpected token %d in conditional command"), tok
);
7092 COND_RETURN_ERROR ();
7097 /* This is kind of bogus -- we slip a mini recursive-descent parser in
7098 here to handle the conditional statement syntax. */
7100 parse_cond_command ()
7104 cexp
= cond_expr ();
7105 return (make_cond_command (cexp
));
7109 #if defined (ARRAY_VARS)
7110 /* When this is called, it's guaranteed that we don't care about anything
7111 in t beyond i. We use a buffer with room for the characters we add just
7112 in case assignment() ends up doing something like parsing a command
7113 substitution that will reallocate atoken. We don't want to write beyond
7114 the end of an allocated buffer. */
7116 token_is_assignment (t
, i
)
7123 atoken
= xmalloc (i
+ 3);
7124 memcpy (atoken
, t
, i
);
7128 r
= assignment (atoken
, (parser_state
& PST_COMPASSIGN
) != 0);
7132 /* XXX - check that r == i to avoid returning false positive for
7133 t containing `=' before t[i]. */
7134 return (r
> 0 && r
== i
);
7137 /* XXX - possible changes here for `+=' */
7139 token_is_ident (t
, i
)
7148 r
= legal_identifier (t
);
7155 read_token_word (character
)
7158 /* The value for YYLVAL when a WORD is read. */
7159 WORD_DESC
*the_word
;
7161 /* Index into the token that we are building. */
7164 /* ALL_DIGITS becomes zero when we see a non-digit. */
7165 int all_digit_token
;
7167 /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
7170 /* COMPOUND_ASSIGNMENT becomes non-zero if we are parsing a compound
7172 int compound_assignment
;
7174 /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
7177 /* Non-zero means to ignore the value of the next character, and just
7178 to add it no matter what. */
7179 int pass_next_character
;
7181 /* The current delimiting character. */
7183 int result
, peek_char
;
7184 char *ttok
, *ttrans
;
7185 int ttoklen
, ttranslen
;
7188 if (token_buffer_size
< TOKEN_DEFAULT_INITIAL_SIZE
)
7189 token
= (char *)xrealloc (token
, token_buffer_size
= TOKEN_DEFAULT_INITIAL_SIZE
);
7192 all_digit_token
= DIGIT (character
);
7193 dollar_present
= quoted
= pass_next_character
= compound_assignment
= 0;
7197 if (character
== EOF
)
7200 if (pass_next_character
)
7202 pass_next_character
= 0;
7203 goto got_escaped_character
;
7206 cd
= current_delimiter (dstack
);
7208 /* Handle backslashes. Quote lots of things when not inside of
7209 double-quotes, quote some things inside of double-quotes. */
7210 if MBTEST(character
== '\\')
7212 if (parser_state
& PST_NOEXPAND
)
7214 pass_next_character
++;
7219 peek_char
= shell_getc (0);
7221 /* Backslash-newline is ignored in all cases except
7222 when quoted with single quotes. */
7223 if MBTEST(peek_char
== '\n')
7226 goto next_character
;
7230 shell_ungetc (peek_char
);
7232 /* If the next character is to be quoted, note it now. */
7233 if MBTEST(cd
== 0 || cd
== '`' ||
7234 (cd
== '"' && peek_char
>= 0 && (sh_syntaxtab
[peek_char
] & CBSDQUOTE
)))
7235 pass_next_character
++;
7242 /* Parse a matched pair of quote characters. */
7243 if MBTEST(shellquote (character
))
7245 push_delimiter (dstack
, character
);
7246 ttok
= parse_matched_pair (character
, character
, character
, &ttoklen
, (character
== '`') ? P_COMMAND
: 0);
7247 pop_delimiter (dstack
);
7248 if (ttok
== &matched_pair_error
)
7249 return -1; /* Bail immediately. */
7250 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7251 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7252 token
[token_index
++] = character
;
7253 strcpy (token
+ token_index
, ttok
);
7254 token_index
+= ttoklen
;
7255 all_digit_token
= 0;
7256 if (character
!= '`')
7258 dollar_present
|= (character
== '"' && strchr (ttok
, '$') != 0);
7260 goto next_character
;
7264 /* When parsing a regexp as a single word inside a conditional command,
7265 we need to special-case characters special to both the shell and
7266 regular expressions. Right now, that is only '(' and '|'. */ /*)*/
7267 if MBTEST((parser_state
& PST_REGEXP
) && (character
== '(' || character
== '|')) /*)*/
7269 if (character
== '|')
7272 push_delimiter (dstack
, character
);
7273 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7274 pop_delimiter (dstack
);
7275 if (ttok
== &matched_pair_error
)
7276 return -1; /* Bail immediately. */
7277 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7278 token_buffer_size
, TOKEN_DEFAULT_GROW_SIZE
);
7279 token
[token_index
++] = character
;
7280 strcpy (token
+ token_index
, ttok
);
7281 token_index
+= ttoklen
;
7283 dollar_present
= all_digit_token
= 0;
7284 goto next_character
;
7286 #endif /* COND_REGEXP */
7288 #ifdef EXTENDED_GLOB
7289 /* Parse a ksh-style extended pattern matching specification. */
7290 if MBTEST(extended_glob
&& PATTERN_CHAR (character
))
7292 peek_char
= shell_getc (1);
7293 if MBTEST(peek_char
== '(') /* ) */
7295 push_delimiter (dstack
, peek_char
);
7296 ttok
= parse_matched_pair (cd
, '(', ')', &ttoklen
, 0);
7297 pop_delimiter (dstack
);
7298 if (ttok
== &matched_pair_error
)
7299 return -1; /* Bail immediately. */
7300 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7302 TOKEN_DEFAULT_GROW_SIZE
);
7303 token
[token_index
++] = character
;
7304 token
[token_index
++] = peek_char
;
7305 strcpy (token
+ token_index
, ttok
);
7306 token_index
+= ttoklen
;
7308 dollar_present
= all_digit_token
= 0;
7309 goto next_character
;
7312 shell_ungetc (peek_char
);
7314 #endif /* EXTENDED_GLOB */
7316 /* If the delimiter character is not single quote, parse some of
7317 the shell expansions that must be read as a single word. */
7318 if MBTEST(shellexp (character
))
7320 peek_char
= shell_getc (1);
7321 /* $(...), <(...), >(...), $((...)), ${...}, and $[...] constructs */
7322 if MBTEST(peek_char
== '(' ||
7323 ((peek_char
== '{' || peek_char
== '[') && character
== '$')) /* ) ] } */
7325 if (peek_char
== '{') /* } */
7326 ttok
= parse_matched_pair (cd
, '{', '}', &ttoklen
, P_FIRSTCLOSE
|P_DOLBRACE
);
7327 else if (peek_char
== '(') /* ) */
7329 /* XXX - push and pop the `(' as a delimiter for use by
7330 the command-oriented-history code. This way newlines
7331 appearing in the $(...) string get added to the
7332 history literally rather than causing a possibly-
7333 incorrect `;' to be added. ) */
7334 push_delimiter (dstack
, peek_char
);
7335 ttok
= parse_comsub (cd
, '(', ')', &ttoklen
, P_COMMAND
);
7336 pop_delimiter (dstack
);
7339 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, P_ARITH
);
7340 if (ttok
== &matched_pair_error
)
7341 return -1; /* Bail immediately. */
7342 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 3,
7344 TOKEN_DEFAULT_GROW_SIZE
);
7345 token
[token_index
++] = character
;
7346 token
[token_index
++] = peek_char
;
7347 strcpy (token
+ token_index
, ttok
);
7348 token_index
+= ttoklen
;
7351 all_digit_token
= 0;
7352 goto next_character
;
7354 /* This handles $'...' and $"..." new-style quoted strings. */
7355 #if defined (TRANSLATABLE_STRINGS)
7356 else if MBTEST(character
== '$' && (peek_char
== '\'' || peek_char
== '"'))
7358 else if MBTEST(character
== '$' && peek_char
== '\'')
7363 first_line
= line_number
;
7364 push_delimiter (dstack
, peek_char
);
7365 ttok
= parse_matched_pair (peek_char
, peek_char
, peek_char
,
7367 (peek_char
== '\'') ? P_ALLOWESC
: 0);
7368 pop_delimiter (dstack
);
7369 if (ttok
== &matched_pair_error
)
7371 if (peek_char
== '\'')
7374 ttrans
= ansiexpand (ttok
, 0, ttoklen
- 1, &ttranslen
);
7377 /* Insert the single quotes and correctly quote any
7378 embedded single quotes (allowed because P_ALLOWESC was
7379 passed to parse_matched_pair). */
7380 ttok
= sh_single_quote (ttrans
);
7382 ttranslen
= strlen (ttok
);
7385 #if defined (TRANSLATABLE_STRINGS)
7389 /* Try to locale-expand the converted string. */
7390 ttrans
= locale_expand (ttok
, 0, ttoklen
- 1, first_line
, &ttranslen
);
7393 /* Add the double quotes back (or single quotes if the user
7394 has set that option). */
7395 if (singlequote_translations
&&
7396 ((ttoklen
- 1) != ttranslen
|| STREQN (ttok
, ttrans
, ttranslen
) == 0))
7397 ttok
= sh_single_quote (ttrans
);
7399 ttok
= sh_mkdoublequoted (ttrans
, ttranslen
, 0);
7403 ttranslen
= strlen (ttrans
);
7405 #endif /* TRANSLATABLE_STRINGS */
7407 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttranslen
+ 1,
7409 TOKEN_DEFAULT_GROW_SIZE
);
7410 strcpy (token
+ token_index
, ttrans
);
7411 token_index
+= ttranslen
;
7414 all_digit_token
= 0;
7415 goto next_character
;
7417 /* This could eventually be extended to recognize all of the
7418 shell's single-character parameter expansions, and set flags.*/
7419 else if MBTEST(character
== '$' && peek_char
== '$')
7421 RESIZE_MALLOCED_BUFFER (token
, token_index
, 3,
7423 TOKEN_DEFAULT_GROW_SIZE
);
7424 token
[token_index
++] = '$';
7425 token
[token_index
++] = peek_char
;
7427 all_digit_token
= 0;
7428 goto next_character
;
7431 shell_ungetc (peek_char
);
7434 #if defined (ARRAY_VARS)
7435 /* Identify possible array subscript assignment; match [...]. If
7436 parser_state&PST_COMPASSIGN, we need to parse [sub]=words treating
7437 `sub' as if it were enclosed in double quotes. */
7438 else if MBTEST(character
== '[' && /* ] */
7439 ((token_index
> 0 && assignment_acceptable (last_read_token
) && token_is_ident (token
, token_index
)) ||
7440 (token_index
== 0 && (parser_state
&PST_COMPASSIGN
))))
7442 ttok
= parse_matched_pair (cd
, '[', ']', &ttoklen
, P_ARRAYSUB
);
7443 if (ttok
== &matched_pair_error
)
7444 return -1; /* Bail immediately. */
7445 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 2,
7447 TOKEN_DEFAULT_GROW_SIZE
);
7448 token
[token_index
++] = character
;
7449 strcpy (token
+ token_index
, ttok
);
7450 token_index
+= ttoklen
;
7452 all_digit_token
= 0;
7453 goto next_character
;
7455 /* Identify possible compound array variable assignment. */
7456 else if MBTEST(character
== '=' && token_index
> 0 && (assignment_acceptable (last_read_token
) || (parser_state
& PST_ASSIGNOK
)) && token_is_assignment (token
, token_index
))
7458 peek_char
= shell_getc (1);
7459 if MBTEST(peek_char
== '(') /* ) */
7461 ttok
= parse_compound_assignment (&ttoklen
);
7463 RESIZE_MALLOCED_BUFFER (token
, token_index
, ttoklen
+ 4,
7465 TOKEN_DEFAULT_GROW_SIZE
);
7467 token
[token_index
++] = '=';
7468 token
[token_index
++] = '(';
7471 strcpy (token
+ token_index
, ttok
);
7472 token_index
+= ttoklen
;
7474 token
[token_index
++] = ')';
7476 all_digit_token
= 0;
7477 compound_assignment
= 1;
7479 goto next_character
;
7481 goto got_token
; /* ksh93 seems to do this */
7485 shell_ungetc (peek_char
);
7489 /* When not parsing a multi-character word construct, shell meta-
7490 characters break words. */
7491 if MBTEST(shellbreak (character
))
7493 shell_ungetc (character
);
7498 if MBTEST(character
== CTLESC
|| character
== CTLNUL
)
7500 RESIZE_MALLOCED_BUFFER (token
, token_index
, 2, token_buffer_size
,
7501 TOKEN_DEFAULT_GROW_SIZE
);
7502 token
[token_index
++] = CTLESC
;
7505 got_escaped_character
:
7506 RESIZE_MALLOCED_BUFFER (token
, token_index
, 1, token_buffer_size
,
7507 TOKEN_DEFAULT_GROW_SIZE
);
7509 token
[token_index
++] = character
;
7511 all_digit_token
&= DIGIT (character
);
7512 dollar_present
|= character
== '$';
7515 if (character
== '\n' && SHOULD_PROMPT ())
7518 /* We want to remove quoted newlines (that is, a \<newline> pair)
7519 unless we are within single quotes or pass_next_character is
7520 set (the shell equivalent of literal-next). */
7521 cd
= current_delimiter (dstack
);
7522 character
= shell_getc (cd
!= '\'' && pass_next_character
== 0);
7523 } /* end for (;;) */
7527 /* Calls to RESIZE_MALLOCED_BUFFER ensure there is sufficient room. */
7528 token
[token_index
] = '\0';
7530 /* Check to see what thing we should return. If the last_read_token
7531 is a `<', or a `&', or the character which ended this token is
7532 a '>' or '<', then, and ONLY then, is this input token a NUMBER.
7533 Otherwise, it is just a word, and should be returned as such. */
7534 if MBTEST(all_digit_token
&& (character
== '<' || character
== '>' ||
7535 last_read_token
== LESS_AND
||
7536 last_read_token
== GREATER_AND
))
7538 if (legal_number (token
, &lvalue
) && (int)lvalue
== lvalue
)
7540 yylval
.number
= lvalue
;
7545 /* Check for special case tokens. */
7546 result
= (last_shell_getc_is_singlebyte
) ? special_case_tokens (token
) : -1;
7551 /* Posix.2 does not allow reserved words to be aliased, so check for all
7552 of them, including special cases, before expanding the current token
7554 if MBTEST(posixly_correct
)
7555 CHECK_FOR_RESERVED_WORD (token
);
7557 /* Aliases are expanded iff EXPAND_ALIASES is non-zero, and quoting
7558 inhibits alias expansion. */
7559 if (expand_aliases
&& quoted
== 0)
7561 result
= alias_expand_token (token
);
7562 if (result
== RE_READ_TOKEN
)
7563 return (RE_READ_TOKEN
);
7564 else if (result
== NO_EXPANSION
)
7565 parser_state
&= ~PST_ALEXPNEXT
;
7568 /* If not in Posix.2 mode, check for reserved words after alias
7570 if MBTEST(posixly_correct
== 0)
7572 CHECK_FOR_RESERVED_WORD (token
);
7574 the_word
= alloc_word_desc ();
7575 the_word
->word
= (char *)xmalloc (1 + token_index
);
7576 the_word
->flags
= 0;
7577 strcpy (the_word
->word
, token
);
7579 the_word
->flags
|= W_HASDOLLAR
;
7581 the_word
->flags
|= W_QUOTED
; /*(*/
7582 if (compound_assignment
&& token
[token_index
-1] == ')')
7583 the_word
->flags
|= W_COMPASSIGN
;
7584 /* A word is an assignment if it appears at the beginning of a
7585 simple command, or after another assignment word. This is
7586 context-dependent, so it cannot be handled in the grammar. */
7587 if (assignment (token
, (parser_state
& PST_COMPASSIGN
) != 0))
7589 the_word
->flags
|= W_ASSIGNMENT
;
7590 /* Don't perform word splitting on assignment statements. */
7591 if (assignment_acceptable (last_read_token
) || (parser_state
& PST_COMPASSIGN
) != 0)
7593 the_word
->flags
|= W_NOSPLIT
;
7594 if (parser_state
& PST_COMPASSIGN
)
7595 the_word
->flags
|= W_NOGLOB
; /* XXX - W_NOBRACE? */
7599 if (command_token_position (last_read_token
))
7602 b
= builtin_address_internal (token
, 0);
7603 if (b
&& (b
->flags
& ASSIGNMENT_BUILTIN
))
7604 parser_state
|= PST_ASSIGNOK
;
7605 else if (STREQ (token
, "eval") || STREQ (token
, "let"))
7606 parser_state
|= PST_ASSIGNOK
;
7609 yylval
.word
= the_word
;
7611 /* should we check that quoted == 0 as well? */
7612 if MBTEST(token
[0] == '{' && token
[token_index
-1] == '}' &&
7613 (character
== '<' || character
== '>'))
7615 /* can use token; already copied to the_word */
7616 token
[token_index
-1] = '\0';
7617 #if defined (ARRAY_VARS)
7618 if (legal_identifier (token
+1) || valid_array_reference (token
+1, 0))
7620 if (legal_identifier (token
+1))
7623 strcpy (the_word
->word
, token
+1);
7624 /* itrace("read_token_word: returning REDIR_WORD for %s", the_word->word); */
7625 yylval
.word
= the_word
; /* accommodate recursive call */
7626 return (REDIR_WORD
);
7629 /* valid_array_reference can call the parser recursively; need to
7630 make sure that yylval.word doesn't change if we are going to
7631 return WORD or ASSIGNMENT_WORD */
7632 yylval
.word
= the_word
;
7635 result
= ((the_word
->flags
& (W_ASSIGNMENT
|W_NOSPLIT
)) == (W_ASSIGNMENT
|W_NOSPLIT
))
7636 ? ASSIGNMENT_WORD
: WORD
;
7638 switch (last_read_token
)
7641 parser_state
|= PST_ALLOWOPNBRC
;
7642 function_dstart
= line_number
;
7647 if (word_top
< MAX_CASE_NEST
)
7649 word_lineno
[word_top
] = line_number
;
7650 expecting_in_token
++;
7657 /* Return 1 if TOKSYM is a token that after being read would allow
7658 a reserved word to be seen, else 0. */
7660 reserved_word_acceptable (toksym
)
7700 #if defined (COPROCESS_SUPPORT)
7701 if (last_read_token
== WORD
&& token_before_that
== COPROC
)
7704 if (last_read_token
== WORD
&& token_before_that
== FUNCTION
)
7710 /* Return the index of TOKEN in the alist of reserved words, or -1 if
7711 TOKEN is not a shell reserved word. */
7713 find_reserved_word (tokstr
)
7717 for (i
= 0; word_token_alist
[i
].word
; i
++)
7718 if (STREQ (tokstr
, word_token_alist
[i
].word
))
7723 /* An interface to let the rest of the shell (primarily the completion
7724 system) know what the parser is expecting. */
7726 parser_in_command_position ()
7728 return (command_token_position (last_read_token
));
7732 #if defined (READLINE)
7733 /* Called after each time readline is called. This insures that whatever
7734 the new prompt string is gets propagated to readline's local prompt
7737 reset_readline_prompt ()
7741 if (prompt_string_pointer
)
7743 temp_prompt
= (*prompt_string_pointer
)
7744 ? decode_prompt_string (*prompt_string_pointer
)
7747 if (temp_prompt
== 0)
7749 temp_prompt
= (char *)xmalloc (1);
7750 temp_prompt
[0] = '\0';
7753 FREE (current_readline_prompt
);
7754 current_readline_prompt
= temp_prompt
;
7757 #endif /* READLINE */
7760 #if defined (HISTORY)
7761 /* A list of tokens which can be followed by newlines, but not by
7762 semi-colons. When concatenating multiple lines of history, the
7763 newline separator for such tokens is replaced with a space. */
7764 static const int no_semi_successors
[] = {
7765 '\n', '{', '(', ')', ';', '&', '|',
7766 CASE
, DO
, ELSE
, IF
, SEMI_SEMI
, SEMI_AND
, SEMI_SEMI_AND
, THEN
, UNTIL
,
7767 WHILE
, AND_AND
, OR_OR
, IN
,
7771 /* If we are not within a delimited expression, try to be smart
7772 about which separators can be semi-colons and which must be
7773 newlines. Returns the string that should be added into the
7774 history entry. LINE is the line we're about to add; it helps
7775 make some more intelligent decisions in certain cases. */
7777 history_delimiting_chars (line
)
7780 static int last_was_heredoc
= 0; /* was the last entry the start of a here document? */
7783 if ((parser_state
& PST_HEREDOC
) == 0)
7784 last_was_heredoc
= 0;
7786 if (dstack
.delimiter_depth
!= 0)
7789 /* We look for current_command_line_count == 2 because we are looking to
7790 add the first line of the body of the here document (the second line
7791 of the command). We also keep LAST_WAS_HEREDOC as a private sentinel
7792 variable to note when we think we added the first line of a here doc
7793 (the one with a "<<" somewhere in it) */
7794 if (parser_state
& PST_HEREDOC
)
7796 if (last_was_heredoc
)
7798 last_was_heredoc
= 0;
7801 return (here_doc_first_line
? "\n" : "");
7804 if (parser_state
& PST_COMPASSIGN
)
7807 /* First, handle some special cases. */
7809 /* If we just read `()', assume it's a function definition, and don't
7810 add a semicolon. If the token before the `)' was not `(', and we're
7811 not in the midst of parsing a case statement, assume it's a
7812 parenthesized command and add the semicolon. */
7814 if (token_before_that
== ')')
7816 if (two_tokens_ago
== '(') /*)*/ /* function def */
7818 /* This does not work for subshells inside case statement
7819 command lists. It's a suboptimal solution. */
7820 else if (parser_state
& PST_CASESTMT
) /* case statement pattern */
7823 return "; "; /* (...) subshell */
7825 else if (token_before_that
== WORD
&& two_tokens_ago
== FUNCTION
)
7826 return " "; /* function def using `function name' without `()' */
7828 /* If we're not in a here document, but we think we're about to parse one,
7829 and we would otherwise return a `;', return a newline to delimit the
7830 line with the here-doc delimiter */
7831 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && last_read_token
== '\n' && strstr (line
, "<<"))
7833 last_was_heredoc
= 1;
7836 else if ((parser_state
& PST_HEREDOC
) == 0 && current_command_line_count
> 1 && need_here_doc
> 0)
7838 else if (token_before_that
== WORD
&& two_tokens_ago
== FOR
)
7840 /* Tricky. `for i\nin ...' should not have a semicolon, but
7841 `for i\ndo ...' should. We do what we can. */
7842 for (i
= shell_input_line_index
; whitespace (shell_input_line
[i
]); i
++)
7844 if (shell_input_line
[i
] && shell_input_line
[i
] == 'i' && shell_input_line
[i
+1] == 'n')
7848 else if (two_tokens_ago
== CASE
&& token_before_that
== WORD
&& (parser_state
& PST_CASESTMT
))
7851 for (i
= 0; no_semi_successors
[i
]; i
++)
7853 if (token_before_that
== no_semi_successors
[i
])
7857 /* Assume that by this point we are reading lines in a multi-line command.
7858 If we have multiple consecutive blank lines we want to return only one
7860 if (line_isblank (line
))
7861 return (current_command_line_count
> 1 && last_read_token
== '\n' && token_before_that
!= '\n') ? "; " : "";
7865 #endif /* HISTORY */
7867 /* Issue a prompt, or prepare to issue a prompt when the next character
7870 prompt_again (force
)
7875 if (interactive
== 0 || expanding_alias ()) /* XXX */
7878 ps1_prompt
= get_string_value ("PS1");
7879 ps2_prompt
= get_string_value ("PS2");
7881 ps0_prompt
= get_string_value ("PS0");
7883 if (!prompt_string_pointer
)
7884 prompt_string_pointer
= &ps1_prompt
;
7886 temp_prompt
= *prompt_string_pointer
7887 ? decode_prompt_string (*prompt_string_pointer
)
7890 if (temp_prompt
== 0)
7892 temp_prompt
= (char *)xmalloc (1);
7893 temp_prompt
[0] = '\0';
7896 current_prompt_string
= *prompt_string_pointer
;
7897 prompt_string_pointer
= &ps2_prompt
;
7899 #if defined (READLINE)
7900 if (!no_line_editing
)
7902 FREE (current_readline_prompt
);
7903 current_readline_prompt
= temp_prompt
;
7906 #endif /* READLINE */
7908 FREE (current_decoded_prompt
);
7909 current_decoded_prompt
= temp_prompt
;
7914 get_current_prompt_level ()
7916 return ((current_prompt_string
&& current_prompt_string
== ps2_prompt
) ? 2 : 1);
7920 set_current_prompt_level (x
)
7923 prompt_string_pointer
= (x
== 2) ? &ps2_prompt
: &ps1_prompt
;
7924 current_prompt_string
= *prompt_string_pointer
;
7930 fprintf (stderr
, "%s", current_decoded_prompt
);
7934 #if defined (HISTORY)
7935 /* The history library increments the history offset as soon as it stores
7936 the first line of a potentially multi-line command, so we compensate
7937 here by returning one fewer when appropriate. */
7939 prompt_history_number (pmt
)
7944 ret
= history_number ();
7948 if (pmt
== ps1_prompt
) /* are we expanding $PS1? */
7950 else if (pmt
== ps2_prompt
&& command_oriented_history
== 0)
7951 return ret
; /* not command oriented history */
7952 else if (pmt
== ps2_prompt
&& command_oriented_history
&& current_command_first_line_saved
)
7955 return ret
- 1; /* PS0, PS4, ${var@P}, PS2 other cases */
7959 /* Return a string which will be printed as a prompt. The string
7960 may contain special characters which are decoded as follows:
7963 \d the date in Day Mon Date format
7964 \e escape (ascii 033)
7965 \h the hostname up to the first `.'
7967 \j the number of active jobs
7968 \l the basename of the shell's tty device name
7971 \s the name of the shell
7972 \t the time in 24-hour hh:mm:ss format
7973 \T the time in 12-hour hh:mm:ss format
7974 \@ the time in 12-hour hh:mm am/pm format
7975 \A the time in 24-hour hh:mm format
7976 \D{fmt} the result of passing FMT to strftime(3)
7978 \v the version of bash (e.g., 2.00)
7979 \V the release of bash, version + patchlevel (e.g., 2.00.0)
7980 \w the current working directory
7981 \W the last element of $PWD
7982 \! the history number of this command
7983 \# the command number of this command
7984 \$ a $ or a # if you are root
7985 \nnn character code nnn in octal
7987 \[ begin a sequence of non-printing chars
7988 \] end a sequence of non-printing chars
7990 #define PROMPT_GROWTH 48
7992 decode_prompt_string (string
)
7996 char *result
, *t
, *orig_string
;
7997 struct dstack save_dstack
;
7998 int last_exit_value
, last_comsub_pid
;
7999 #if defined (PROMPT_STRING_DECODE)
8001 size_t result_index
;
8003 char *temp
, *t_host
, octal_string
[4];
8009 result
= (char *)xmalloc (result_size
= PROMPT_GROWTH
);
8010 result
[result_index
= 0] = 0;
8011 temp
= (char *)NULL
;
8012 orig_string
= string
;
8014 while (c
= *string
++)
8016 if (posixly_correct
&& c
== '!')
8020 temp
= savestring ("!");
8025 #if !defined (HISTORY)
8026 temp
= savestring ("1");
8028 temp
= itos (prompt_history_number (orig_string
));
8029 #endif /* HISTORY */
8030 string
--; /* add_string increments string again. */
8048 strncpy (octal_string
, string
, 3);
8049 octal_string
[3] = '\0';
8051 n
= read_octal (octal_string
);
8052 temp
= (char *)xmalloc (3);
8054 if (n
== CTLESC
|| n
== CTLNUL
)
8071 for (c
= 0; n
!= -1 && c
< 3 && ISOCTAL (*string
); c
++)
8074 c
= 0; /* tested at add_string: */
8082 /* Make the current time/date into a string. */
8083 (void) time (&the_time
);
8084 #if defined (HAVE_TZSET)
8085 sv_tz ("TZ"); /* XXX -- just make sure */
8087 tm
= localtime (&the_time
);
8090 n
= strftime (timebuf
, sizeof (timebuf
), "%a %b %d", tm
);
8092 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M:%S", tm
);
8094 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M:%S", tm
);
8096 n
= strftime (timebuf
, sizeof (timebuf
), "%I:%M %p", tm
);
8098 n
= strftime (timebuf
, sizeof (timebuf
), "%H:%M", tm
);
8103 timebuf
[sizeof(timebuf
) - 1] = '\0';
8105 temp
= savestring (timebuf
);
8108 case 'D': /* strftime format */
8109 if (string
[1] != '{') /* } */
8112 (void) time (&the_time
);
8113 tm
= localtime (&the_time
);
8114 string
+= 2; /* skip { */
8115 timefmt
= xmalloc (strlen (string
) + 3);
8116 for (t
= timefmt
; *string
&& *string
!= '}'; )
8119 c
= *string
; /* tested at add_string */
8120 if (timefmt
[0] == '\0')
8123 timefmt
[1] = 'X'; /* locale-specific current time */
8126 n
= strftime (timebuf
, sizeof (timebuf
), timefmt
, tm
);
8132 timebuf
[sizeof(timebuf
) - 1] = '\0';
8134 if (promptvars
|| posixly_correct
)
8135 /* Make sure that expand_prompt_string is called with a
8136 second argument of Q_DOUBLE_QUOTES if we use this
8138 temp
= sh_backslash_quote_for_double_quotes (timebuf
, 0);
8140 temp
= savestring (timebuf
);
8144 temp
= (char *)xmalloc (3);
8145 temp
[0] = no_line_editing
? '\n' : '\r';
8146 temp
[1] = no_line_editing
? '\0' : '\n';
8151 temp
= base_pathname (shell_name
);
8152 /* Try to quote anything the user can set in the file system */
8153 if (promptvars
|| posixly_correct
)
8156 t
= sh_strvis (temp
);
8157 temp
= sh_backslash_quote_for_double_quotes (t
, 0);
8161 temp
= sh_strvis (temp
);
8166 temp
= (char *)xmalloc (16);
8168 strcpy (temp
, dist_version
);
8170 sprintf (temp
, "%s.%d", dist_version
, patch_level
);
8176 /* Use the value of PWD because it is much more efficient. */
8177 char t_string
[PATH_MAX
];
8180 temp
= get_string_value ("PWD");
8184 if (getcwd (t_string
, sizeof(t_string
)) == 0)
8190 tlen
= strlen (t_string
);
8194 tlen
= sizeof (t_string
) - 1;
8195 strncpy (t_string
, temp
, tlen
);
8197 t_string
[tlen
] = '\0';
8199 #if defined (MACOSX)
8200 /* Convert from "fs" format to "input" format */
8201 temp
= fnx_fromfs (t_string
, strlen (t_string
));
8202 if (temp
!= t_string
)
8203 strcpy (t_string
, temp
);
8206 #define ROOT_PATH(x) ((x)[0] == '/' && (x)[1] == 0)
8207 #define DOUBLE_SLASH_ROOT(x) ((x)[0] == '/' && (x)[1] == '/' && (x)[2] == 0)
8208 /* Abbreviate \W as ~ if $PWD == $HOME */
8209 if (c
== 'W' && (((t
= get_string_value ("HOME")) == 0) || STREQ (t
, t_string
) == 0))
8211 if (ROOT_PATH (t_string
) == 0 && DOUBLE_SLASH_ROOT (t_string
) == 0)
8213 t
= strrchr (t_string
, '/');
8215 memmove (t_string
, t
+ 1, strlen (t
)); /* strlen(t) to copy NULL */
8219 #undef DOUBLE_SLASH_ROOT
8222 /* polite_directory_format is guaranteed to return a string
8223 no longer than PATH_MAX - 1 characters. */
8224 temp
= polite_directory_format (t_string
);
8225 if (temp
!= t_string
)
8226 strcpy (t_string
, temp
);
8229 temp
= trim_pathname (t_string
, PATH_MAX
- 1);
8230 /* If we're going to be expanding the prompt string later,
8231 quote the directory name. */
8232 if (promptvars
|| posixly_correct
)
8233 /* Make sure that expand_prompt_string is called with a
8234 second argument of Q_DOUBLE_QUOTES if we use this
8238 t
= sh_strvis (t_string
);
8239 temp
= sh_backslash_quote_for_double_quotes (t
, 0);
8243 temp
= sh_strvis (t_string
);
8249 if (current_user
.user_name
== 0)
8250 get_current_user_info ();
8251 temp
= savestring (current_user
.user_name
);
8256 t_host
= savestring (current_host_name
);
8257 if (c
== 'h' && (t
= (char *)strchr (t_host
, '.')))
8259 if (promptvars
|| posixly_correct
)
8260 /* Make sure that expand_prompt_string is called with a
8261 second argument of Q_DOUBLE_QUOTES if we use this
8263 temp
= sh_backslash_quote_for_double_quotes (t_host
, 0);
8265 temp
= savestring (t_host
);
8270 n
= current_command_number
;
8271 /* If we have already incremented current_command_number (PS4,
8272 ${var@P}), compensate */
8273 if (orig_string
!= ps0_prompt
&& orig_string
!= ps1_prompt
&& orig_string
!= ps2_prompt
)
8279 #if !defined (HISTORY)
8280 temp
= savestring ("1");
8282 temp
= itos (prompt_history_number (orig_string
));
8283 #endif /* HISTORY */
8287 t
= temp
= (char *)xmalloc (3);
8288 if ((promptvars
|| posixly_correct
) && (current_user
.euid
!= 0))
8290 *t
++ = current_user
.euid
== 0 ? '#' : '$';
8295 temp
= itos (count_all_jobs ());
8299 #if defined (HAVE_TTYNAME)
8300 temp
= (char *)ttyname (fileno (stdin
));
8301 t
= temp
? base_pathname (temp
) : "tty";
8302 temp
= savestring (t
);
8304 temp
= savestring ("tty");
8305 #endif /* !HAVE_TTYNAME */
8308 #if defined (READLINE)
8311 if (no_line_editing
)
8316 temp
= (char *)xmalloc (3);
8317 n
= (c
== '[') ? RL_PROMPT_START_IGNORE
: RL_PROMPT_END_IGNORE
;
8319 if (n
== CTLESC
|| n
== CTLNUL
)
8324 #endif /* READLINE */
8330 temp
= (char *)xmalloc (2);
8337 else /* (c == '\\') */
8344 temp
= (char *)xmalloc (3);
8353 sub_append_string (temp
, result
, &result_index
, &result_size
);
8354 temp
= (char *)NULL
; /* Freed in sub_append_string (). */
8355 result
[result_index
] = '\0';
8361 RESIZE_MALLOCED_BUFFER (result
, result_index
, 3, result_size
, PROMPT_GROWTH
);
8362 /* dequote_string should take care of removing this if we are not
8363 performing the rest of the word expansions. */
8364 if (c
== CTLESC
|| c
== CTLNUL
)
8365 result
[result_index
++] = CTLESC
;
8366 result
[result_index
++] = c
;
8367 result
[result_index
] = '\0';
8370 #else /* !PROMPT_STRING_DECODE */
8371 result
= savestring (string
);
8372 #endif /* !PROMPT_STRING_DECODE */
8374 /* Save the delimiter stack and point `dstack' to temp space so any
8375 command substitutions in the prompt string won't result in screwing
8376 up the parser's quoting state. */
8377 save_dstack
= dstack
;
8378 dstack
= temp_dstack
;
8379 dstack
.delimiter_depth
= 0;
8381 /* Perform variable and parameter expansion and command substitution on
8382 the prompt string. */
8383 if (promptvars
|| posixly_correct
)
8385 last_exit_value
= last_command_exit_value
;
8386 last_comsub_pid
= last_command_subst_pid
;
8387 list
= expand_prompt_string (result
, Q_DOUBLE_QUOTES
, 0);
8389 result
= string_list (list
);
8390 dispose_words (list
);
8391 last_command_exit_value
= last_exit_value
;
8392 last_command_subst_pid
= last_comsub_pid
;
8396 t
= dequote_string (result
);
8401 dstack
= save_dstack
;
8406 /************************************************
8410 ************************************************/
8412 /* Report a syntax error, and restart the parser. Call here for fatal
8418 if ((parser_state
& PST_NOERROR
) == 0)
8419 report_syntax_error ((char *)NULL
);
8425 error_token_from_token (tok
)
8430 if (t
= find_token_in_alist (tok
, word_token_alist
, 0))
8433 if (t
= find_token_in_alist (tok
, other_token_alist
, 0))
8437 /* This stuff is dicy and needs closer inspection */
8438 switch (current_token
)
8441 case ASSIGNMENT_WORD
:
8443 t
= savestring (yylval
.word
->word
);
8446 t
= itos (yylval
.number
);
8449 if (yylval
.word_list
)
8450 t
= string_list (yylval
.word_list
);
8452 case ARITH_FOR_EXPRS
:
8453 if (yylval
.word_list
)
8454 t
= string_list_internal (yylval
.word_list
, " ; ");
8457 t
= (char *)NULL
; /* punt */
8465 error_token_from_text ()
8470 t
= shell_input_line
;
8471 i
= shell_input_line_index
;
8475 if (i
&& t
[i
] == '\0')
8478 while (i
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8484 while (i
&& (member (t
[i
], " \n\t;|&") == 0))
8487 while (i
!= token_end
&& (whitespace (t
[i
]) || t
[i
] == '\n'))
8490 /* Return our idea of the offending token. */
8491 if (token_end
|| (i
== 0 && token_end
== 0))
8494 msg
= substring (t
, i
, token_end
);
8495 else /* one-character token */
8497 msg
= (char *)xmalloc (2);
8507 print_offending_line ()
8512 msg
= savestring (shell_input_line
);
8513 token_end
= strlen (msg
);
8514 while (token_end
&& msg
[token_end
- 1] == '\n')
8515 msg
[--token_end
] = '\0';
8517 parser_error (line_number
, "`%s'", msg
);
8521 /* Report a syntax error with line numbers, etc.
8522 Call here for recoverable errors. If you have a message to print,
8523 then place it in MESSAGE, otherwise pass NULL and this will figure
8524 out an appropriate message for you. */
8526 report_syntax_error (message
)
8533 parser_error (line_number
, "%s", message
);
8534 if (interactive
&& EOF_Reached
)
8536 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8537 set_pipestatus_from_exit (last_command_exit_value
);
8541 /* If the line of input we're reading is not null, try to find the
8542 objectionable token. First, try to figure out what token the
8543 parser's complaining about by looking at current_token. */
8544 if (current_token
!= 0 && EOF_Reached
== 0 && (msg
= error_token_from_token (current_token
)))
8546 if (ansic_shouldquote (msg
))
8548 p
= ansic_quote (msg
, 0, NULL
);
8552 parser_error (line_number
, _("syntax error near unexpected token `%s'"), msg
);
8555 if (interactive
== 0)
8556 print_offending_line ();
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 looking at the current token doesn't prove fruitful, try to find the
8564 offending token by analyzing the text of the input line near the current
8565 input line index and report what we find. */
8566 if (shell_input_line
&& *shell_input_line
)
8568 msg
= error_token_from_text ();
8571 parser_error (line_number
, _("syntax error near `%s'"), msg
);
8575 /* If not interactive, print the line containing the error. */
8576 if (interactive
== 0)
8577 print_offending_line ();
8581 if (EOF_Reached
&& shell_eof_token
&& current_token
!= shell_eof_token
)
8582 parser_error (line_number
, _("unexpected EOF while looking for matching `%c'"), shell_eof_token
);
8585 msg
= EOF_Reached
? _("syntax error: unexpected end of file") : _("syntax error");
8586 parser_error (line_number
, "%s", msg
);
8589 /* When the shell is interactive, this file uses EOF_Reached
8590 only for error reporting. Other mechanisms are used to
8591 decide whether or not to exit. */
8592 if (interactive
&& EOF_Reached
)
8596 last_command_exit_value
= (executing_builtin
&& parse_and_execute_level
) ? EX_BADSYNTAX
: EX_BADUSAGE
;
8597 set_pipestatus_from_exit (last_command_exit_value
);
8600 /* ??? Needed function. ??? We have to be able to discard the constructs
8601 created during parsing. In the case of error, we want to return
8602 allocated objects to the memory pool. In the case of no error, we want
8603 to throw away the information about where the allocated objects live.
8604 (dispose_command () will actually free the command.) */
8606 discard_parser_constructs (error_p
)
8611 /************************************************
8615 ************************************************/
8617 /* Do that silly `type "bye" to exit' stuff. You know, "ignoreeof". */
8619 /* A flag denoting whether or not ignoreeof is set. */
8622 /* The number of times that we have encountered an EOF character without
8623 another character intervening. When this gets above the limit, the
8624 shell terminates. */
8625 int eof_encountered
= 0;
8627 /* The limit for eof_encountered. */
8628 int eof_encountered_limit
= 10;
8630 /* If we have EOF as the only input unit, this user wants to leave
8631 the shell. If the shell is not interactive, then just leave.
8632 Otherwise, if ignoreeof is set, and we haven't done this the
8633 required number of times in a row, print a message. */
8635 handle_eof_input_unit ()
8639 /* shell.c may use this to decide whether or not to write out the
8640 history, among other things. We use it only for error reporting
8645 /* If the user wants to "ignore" eof, then let her do so, kind of. */
8648 if (eof_encountered
< eof_encountered_limit
)
8650 fprintf (stderr
, _("Use \"%s\" to leave the shell.\n"),
8651 login_shell
? "logout" : "exit");
8653 /* Reset the parsing state. */
8654 last_read_token
= current_token
= '\n';
8655 /* Reset the prompt string to be $PS1. */
8656 prompt_string_pointer
= (char **)NULL
;
8662 /* In this case EOF should exit the shell. Do it now. */
8665 last_shell_builtin
= this_shell_builtin
;
8666 this_shell_builtin
= exit_builtin
;
8667 exit_builtin ((WORD_LIST
*)NULL
);
8671 /* We don't write history files, etc., for non-interactive shells. */
8676 /************************************************
8678 * STRING PARSING FUNCTIONS *
8680 ************************************************/
8682 /* It's very important that these two functions treat the characters
8683 between ( and ) identically. */
8685 static WORD_LIST parse_string_error
;
8687 /* Take a string and run it through the shell parser, returning the
8688 resultant word list. Used by compound array assignment. */
8690 parse_string_to_word_list (s
, flags
, whom
)
8696 int tok
, orig_current_token
, orig_line_number
;
8697 int orig_parser_state
;
8698 sh_parser_state_t ps
;
8701 orig_line_number
= line_number
;
8702 save_parser_state (&ps
);
8704 #if defined (HISTORY)
8705 bash_history_disable ();
8709 if (ea
= expanding_alias ())
8710 parser_save_alias ();
8712 /* WORD to avoid parsing reserved words as themselves and just parse them as
8714 last_read_token
= WORD
;
8716 current_command_line_count
= 0;
8717 echo_input_at_read
= expand_aliases
= 0;
8719 with_input_from_string (s
, whom
);
8720 wl
= (WORD_LIST
*)NULL
;
8724 orig_parser_state
= parser_state
; /* XXX - not needed? */
8725 /* State flags we don't want to persist into compound assignments. */
8726 parser_state
&= ~PST_NOEXPAND
; /* parse_comsub sentinel */
8727 /* State flags we want to set for this run through the tokenizer. */
8728 parser_state
|= PST_COMPASSIGN
|PST_REPARSE
|PST_STRING
;
8731 while ((tok
= read_token (READ
)) != yacc_EOF
)
8733 if (tok
== '\n' && *bash_input
.location
.string
== '\0')
8735 if (tok
== '\n') /* Allow newlines in compound assignments */
8737 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8739 line_number
= orig_line_number
+ line_number
- 1;
8740 orig_current_token
= current_token
;
8741 current_token
= tok
;
8742 yyerror (NULL
); /* does the right thing */
8743 current_token
= orig_current_token
;
8746 wl
= &parse_string_error
;
8749 wl
= make_word_list (yylval
.word
, wl
);
8752 last_read_token
= '\n';
8756 parser_restore_alias ();
8758 restore_parser_state (&ps
);
8761 parser_state
= orig_parser_state
; /* XXX - not needed? */
8763 if (wl
== &parse_string_error
)
8765 set_exit_status (EXECUTION_FAILURE
);
8766 if (interactive_shell
== 0 && posixly_correct
)
8767 jump_to_top_level (FORCE_EOF
);
8769 jump_to_top_level (DISCARD
);
8772 return (REVERSE_LIST (wl
, WORD_LIST
*));
8776 parse_compound_assignment (retlenp
)
8780 int tok
, orig_line_number
, assignok
;
8781 sh_parser_state_t ps
;
8784 orig_line_number
= line_number
;
8785 save_parser_state (&ps
);
8787 /* WORD to avoid parsing reserved words as themselves and just parse them as
8788 WORDs. Plus it means we won't be in a command position and so alias
8789 expansion won't happen. */
8790 last_read_token
= WORD
;
8792 token
= (char *)NULL
;
8793 token_buffer_size
= 0;
8794 wl
= (WORD_LIST
*)NULL
; /* ( */
8796 assignok
= parser_state
&PST_ASSIGNOK
; /* XXX */
8798 /* State flags we don't want to persist into compound assignments. */
8799 parser_state
&= ~(PST_NOEXPAND
|PST_CONDCMD
|PST_CONDEXPR
|PST_REGEXP
|PST_EXTPAT
);
8800 /* State flags we want to set for this run through the tokenizer. */
8801 parser_state
|= PST_COMPASSIGN
;
8803 esacs_needed_count
= expecting_in_token
= 0;
8805 while ((tok
= read_token (READ
)) != ')')
8807 if (tok
== '\n') /* Allow newlines in compound assignments */
8809 if (SHOULD_PROMPT ())
8813 if (tok
!= WORD
&& tok
!= ASSIGNMENT_WORD
)
8815 current_token
= tok
; /* for error reporting */
8816 if (tok
== yacc_EOF
) /* ( */
8817 parser_error (orig_line_number
, _("unexpected EOF while looking for matching `)'"));
8819 yyerror(NULL
); /* does the right thing */
8822 wl
= &parse_string_error
;
8825 wl
= make_word_list (yylval
.word
, wl
);
8828 restore_parser_state (&ps
);
8830 if (wl
== &parse_string_error
)
8832 set_exit_status (EXECUTION_FAILURE
);
8833 last_read_token
= '\n'; /* XXX */
8834 if (interactive_shell
== 0 && posixly_correct
)
8835 jump_to_top_level (FORCE_EOF
);
8837 jump_to_top_level (DISCARD
);
8842 rl
= REVERSE_LIST (wl
, WORD_LIST
*);
8843 ret
= string_list (rl
);
8850 *retlenp
= (ret
&& *ret
) ? strlen (ret
) : 0;
8853 parser_state
|= PST_ASSIGNOK
;
8858 /************************************************
8860 * SAVING AND RESTORING PARTIAL PARSE STATE *
8862 ************************************************/
8865 save_parser_state (ps
)
8866 sh_parser_state_t
*ps
;
8869 ps
= (sh_parser_state_t
*)xmalloc (sizeof (sh_parser_state_t
));
8871 return ((sh_parser_state_t
*)NULL
);
8873 ps
->parser_state
= parser_state
;
8874 ps
->token_state
= save_token_state ();
8876 ps
->input_line_terminator
= shell_input_line_terminator
;
8877 ps
->eof_encountered
= eof_encountered
;
8878 ps
->eol_lookahead
= eol_ungetc_lookahead
;
8880 ps
->prompt_string_pointer
= prompt_string_pointer
;
8882 ps
->current_command_line_count
= current_command_line_count
;
8884 #if defined (HISTORY)
8885 ps
->remember_on_history
= remember_on_history
;
8886 # if defined (BANG_HISTORY)
8887 ps
->history_expansion_inhibited
= history_expansion_inhibited
;
8891 ps
->last_command_exit_value
= last_command_exit_value
;
8892 #if defined (ARRAY_VARS)
8893 ps
->pipestatus
= save_pipestatus_array ();
8896 ps
->last_shell_builtin
= last_shell_builtin
;
8897 ps
->this_shell_builtin
= this_shell_builtin
;
8899 ps
->expand_aliases
= expand_aliases
;
8900 ps
->echo_input_at_read
= echo_input_at_read
;
8901 ps
->need_here_doc
= need_here_doc
;
8902 ps
->here_doc_first_line
= here_doc_first_line
;
8904 ps
->esacs_needed
= esacs_needed_count
;
8905 ps
->expecting_in
= expecting_in_token
;
8907 if (need_here_doc
== 0)
8908 ps
->redir_stack
[0] = 0;
8910 memcpy (ps
->redir_stack
, redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
8912 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
8913 ps
->pushed_strings
= pushed_string_list
;
8916 ps
->eof_token
= shell_eof_token
;
8918 ps
->token_buffer_size
= token_buffer_size
;
8919 /* Force reallocation on next call to read_token_word */
8921 token_buffer_size
= 0;
8927 restore_parser_state (ps
)
8928 sh_parser_state_t
*ps
;
8935 parser_state
= ps
->parser_state
;
8936 if (ps
->token_state
)
8938 restore_token_state (ps
->token_state
);
8939 free (ps
->token_state
);
8942 shell_input_line_terminator
= ps
->input_line_terminator
;
8943 eof_encountered
= ps
->eof_encountered
;
8944 eol_ungetc_lookahead
= ps
->eol_lookahead
;
8946 prompt_string_pointer
= ps
->prompt_string_pointer
;
8948 current_command_line_count
= ps
->current_command_line_count
;
8950 #if defined (HISTORY)
8951 remember_on_history
= ps
->remember_on_history
;
8952 # if defined (BANG_HISTORY)
8953 history_expansion_inhibited
= ps
->history_expansion_inhibited
;
8957 last_command_exit_value
= ps
->last_command_exit_value
;
8958 #if defined (ARRAY_VARS)
8959 restore_pipestatus_array (ps
->pipestatus
);
8962 last_shell_builtin
= ps
->last_shell_builtin
;
8963 this_shell_builtin
= ps
->this_shell_builtin
;
8965 expand_aliases
= ps
->expand_aliases
;
8966 echo_input_at_read
= ps
->echo_input_at_read
;
8967 need_here_doc
= ps
->need_here_doc
;
8968 here_doc_first_line
= ps
->here_doc_first_line
;
8970 esacs_needed_count
= ps
->esacs_needed
;
8971 expecting_in_token
= ps
->expecting_in
;
8974 for (i
= 0; i
< HEREDOC_MAX
; i
++)
8975 redir_stack
[i
] = ps
->redir_stack
[i
];
8977 if (need_here_doc
== 0)
8980 memcpy (redir_stack
, ps
->redir_stack
, sizeof (redir_stack
[0]) * HEREDOC_MAX
);
8983 #if defined (ALIAS) || defined (DPAREN_ARITHMETIC)
8984 pushed_string_list
= (STRING_SAVER
*)ps
->pushed_strings
;
8989 token_buffer_size
= ps
->token_buffer_size
;
8990 shell_eof_token
= ps
->eof_token
;
8993 sh_input_line_state_t
*
8994 save_input_line_state (ls
)
8995 sh_input_line_state_t
*ls
;
8998 ls
= (sh_input_line_state_t
*)xmalloc (sizeof (sh_input_line_state_t
));
9000 return ((sh_input_line_state_t
*)NULL
);
9002 ls
->input_line
= shell_input_line
;
9003 ls
->input_line_size
= shell_input_line_size
;
9004 ls
->input_line_len
= shell_input_line_len
;
9005 ls
->input_line_index
= shell_input_line_index
;
9007 #if defined (HANDLE_MULTIBYTE)
9008 ls
->input_property
= shell_input_line_property
;
9009 ls
->input_propsize
= shell_input_line_propsize
;
9012 /* force reallocation */
9013 shell_input_line
= 0;
9014 shell_input_line_size
= shell_input_line_len
= shell_input_line_index
= 0;
9016 #if defined (HANDLE_MULTIBYTE)
9017 shell_input_line_property
= 0;
9018 shell_input_line_propsize
= 0;
9025 restore_input_line_state (ls
)
9026 sh_input_line_state_t
*ls
;
9028 FREE (shell_input_line
);
9029 shell_input_line
= ls
->input_line
;
9030 shell_input_line_size
= ls
->input_line_size
;
9031 shell_input_line_len
= ls
->input_line_len
;
9032 shell_input_line_index
= ls
->input_line_index
;
9034 #if defined (HANDLE_MULTIBYTE)
9035 FREE (shell_input_line_property
);
9036 shell_input_line_property
= ls
->input_property
;
9037 shell_input_line_propsize
= ls
->input_propsize
;
9041 set_line_mbstate ();
9045 /************************************************
9047 * MULTIBYTE CHARACTER HANDLING *
9049 ************************************************/
9051 #if defined (HANDLE_MULTIBYTE)
9053 /* We don't let the property buffer get larger than this unless the line is */
9054 #define MAX_PROPSIZE 32768
9060 size_t i
, previ
, len
;
9061 mbstate_t mbs
, prevs
;
9065 if (shell_input_line
== NULL
)
9067 len
= STRLEN (shell_input_line
); /* XXX - shell_input_line_len ? */
9070 if (shell_input_line_propsize
>= MAX_PROPSIZE
&& len
< MAX_PROPSIZE
>>1)
9072 free (shell_input_line_property
);
9073 shell_input_line_property
= 0;
9074 shell_input_line_propsize
= 0;
9076 if (len
+1 > shell_input_line_propsize
)
9078 shell_input_line_propsize
= len
+ 1;
9079 shell_input_line_property
= (char *)xrealloc (shell_input_line_property
, shell_input_line_propsize
);
9082 if (locale_mb_cur_max
== 1)
9084 memset (shell_input_line_property
, 1, len
);
9088 /* XXX - use whether or not we are in a UTF-8 locale to avoid calls to
9090 if (locale_utf8locale
== 0)
9091 memset (&prevs
, '\0', sizeof (mbstate_t));
9093 for (i
= previ
= 0; i
< len
; i
++)
9095 if (locale_utf8locale
== 0)
9098 c
= shell_input_line
[i
];
9102 for (j
= i
; j
< len
; j
++)
9103 shell_input_line_property
[j
] = 1;
9107 if (locale_utf8locale
)
9109 if ((unsigned char)shell_input_line
[previ
] < 128) /* i != previ */
9113 ilen
= utf8_mblen (shell_input_line
+ previ
, i
- previ
+ 1);
9114 mbclen
= (ilen
== -1) ? (size_t)-1
9115 : ((ilen
== -2) ? (size_t)-2 : (size_t)ilen
);
9119 mbclen
= mbrlen (shell_input_line
+ previ
, i
- previ
+ 1, &mbs
);
9121 if (mbclen
== 1 || mbclen
== (size_t)-1)
9126 else if (mbclen
== (size_t)-2)
9128 else if (mbclen
> 1)
9132 if (locale_utf8locale
== 0)
9138 for (j
= i
; j
< len
; j
++)
9139 shell_input_line_property
[j
] = 1;
9143 shell_input_line_property
[i
] = mbclen
;
9146 #endif /* HANDLE_MULTIBYTE */