From 40f4c7305a041d4214df117491593898d04d0134 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 26 Oct 2021 10:26:17 -0700 Subject: proto(rc): control structures --- sys/cmd/rc/parse.c | 709 ++++++++++++++++++++++++++++++---------------------- sys/cmd/rc/parse.h | 78 +++--- sys/cmd/rc/rc.h | 1 + sys/cmd/rc/syntax.y | 47 ++-- sys/cmd/rc/tree.c | 10 + 5 files changed, 490 insertions(+), 355 deletions(-) (limited to 'sys') diff --git a/sys/cmd/rc/parse.c b/sys/cmd/rc/parse.c index 687956b..fa3e165 100644 --- a/sys/cmd/rc/parse.c +++ b/sys/cmd/rc/parse.c @@ -111,57 +111,61 @@ enum yysymbol_kind_t YYSYMBOL_Tif = 6, /* Tif */ YYSYMBOL_Telse = 7, /* Telse */ YYSYMBOL_Tswitch = 8, /* Tswitch */ - YYSYMBOL_Ttwiddle = 9, /* Ttwiddle */ - YYSYMBOL_Tbang = 10, /* Tbang */ - YYSYMBOL_Tsubshell = 11, /* Tsubshell */ - YYSYMBOL_Tfunc = 12, /* Tfunc */ - YYSYMBOL_Tredir = 13, /* Tredir */ - YYSYMBOL_Tdup = 14, /* Tdup */ - YYSYMBOL_Tpipe = 15, /* Tpipe */ - YYSYMBOL_Tindex = 16, /* Tindex */ - YYSYMBOL_Tbasic = 17, /* Tbasic */ - YYSYMBOL_Targs = 18, /* Targs */ - YYSYMBOL_Tword = 19, /* Tword */ - YYSYMBOL_Twords = 20, /* Twords */ - YYSYMBOL_Tparen = 21, /* Tparen */ - YYSYMBOL_Tblock = 22, /* Tblock */ - YYSYMBOL_23_ = 23, /* ')' */ - YYSYMBOL_Tandand = 24, /* Tandand */ - YYSYMBOL_Toror = 25, /* Toror */ - YYSYMBOL_26_n_ = 26, /* '\n' */ - YYSYMBOL_27_ = 27, /* '^' */ - YYSYMBOL_28_ = 28, /* '$' */ - YYSYMBOL_Tcount = 29, /* Tcount */ - YYSYMBOL_Tjoin = 30, /* Tjoin */ - YYSYMBOL_31_ = 31, /* '(' */ - YYSYMBOL_32_ = 32, /* '{' */ - YYSYMBOL_33_ = 33, /* '}' */ - YYSYMBOL_34_ = 34, /* ';' */ - YYSYMBOL_35_ = 35, /* '&' */ - YYSYMBOL_36_ = 36, /* '=' */ - YYSYMBOL_37_ = 37, /* '`' */ - YYSYMBOL_YYACCEPT = 38, /* $accept */ - YYSYMBOL_rc = 39, /* rc */ - YYSYMBOL_line = 40, /* line */ - YYSYMBOL_body = 41, /* body */ - YYSYMBOL_paren = 42, /* paren */ - YYSYMBOL_block = 43, /* block */ - YYSYMBOL_cmds = 44, /* cmds */ - YYSYMBOL_cmdsln = 45, /* cmdsln */ - YYSYMBOL_ifbody = 46, /* ifbody */ - YYSYMBOL_assign = 47, /* assign */ - YYSYMBOL_redir = 48, /* redir */ - YYSYMBOL_epilog = 49, /* epilog */ - YYSYMBOL_cmd = 50, /* cmd */ - YYSYMBOL_basic = 51, /* basic */ - YYSYMBOL_atom = 52, /* atom */ - YYSYMBOL_word = 53, /* word */ - YYSYMBOL_executable = 54, /* executable */ - YYSYMBOL_nonkeyword = 55, /* nonkeyword */ - YYSYMBOL_keyword = 56, /* keyword */ - YYSYMBOL_words = 57, /* words */ - YYSYMBOL_wordsnl = 58, /* wordsnl */ - YYSYMBOL_nl = 59 /* nl */ + YYSYMBOL_Tcase = 9, /* Tcase */ + YYSYMBOL_Tcasebody = 10, /* Tcasebody */ + YYSYMBOL_Ttwiddle = 11, /* Ttwiddle */ + YYSYMBOL_Tbang = 12, /* Tbang */ + YYSYMBOL_Tsubshell = 13, /* Tsubshell */ + YYSYMBOL_Tfunc = 14, /* Tfunc */ + YYSYMBOL_Tredir = 15, /* Tredir */ + YYSYMBOL_Tdup = 16, /* Tdup */ + YYSYMBOL_Tpipe = 17, /* Tpipe */ + YYSYMBOL_Tindex = 18, /* Tindex */ + YYSYMBOL_Tbasic = 19, /* Tbasic */ + YYSYMBOL_Targs = 20, /* Targs */ + YYSYMBOL_Tword = 21, /* Tword */ + YYSYMBOL_Twords = 22, /* Twords */ + YYSYMBOL_Tparen = 23, /* Tparen */ + YYSYMBOL_Tblock = 24, /* Tblock */ + YYSYMBOL_25_ = 25, /* ')' */ + YYSYMBOL_Tandand = 26, /* Tandand */ + YYSYMBOL_Toror = 27, /* Toror */ + YYSYMBOL_28_n_ = 28, /* '\n' */ + YYSYMBOL_29_ = 29, /* '^' */ + YYSYMBOL_30_ = 30, /* '$' */ + YYSYMBOL_Tcount = 31, /* Tcount */ + YYSYMBOL_Tjoin = 32, /* Tjoin */ + YYSYMBOL_33_ = 33, /* '(' */ + YYSYMBOL_34_ = 34, /* '{' */ + YYSYMBOL_35_ = 35, /* '}' */ + YYSYMBOL_36_ = 36, /* ';' */ + YYSYMBOL_37_ = 37, /* '&' */ + YYSYMBOL_38_ = 38, /* '=' */ + YYSYMBOL_39_ = 39, /* '`' */ + YYSYMBOL_YYACCEPT = 40, /* $accept */ + YYSYMBOL_rc = 41, /* rc */ + YYSYMBOL_line = 42, /* line */ + YYSYMBOL_body = 43, /* body */ + YYSYMBOL_paren = 44, /* paren */ + YYSYMBOL_block = 45, /* block */ + YYSYMBOL_cmds = 46, /* cmds */ + YYSYMBOL_cmdsln = 47, /* cmdsln */ + YYSYMBOL_ifbody = 48, /* ifbody */ + YYSYMBOL_case = 49, /* case */ + YYSYMBOL_casebody = 50, /* casebody */ + YYSYMBOL_assign = 51, /* assign */ + YYSYMBOL_redir = 52, /* redir */ + YYSYMBOL_epilog = 53, /* epilog */ + YYSYMBOL_cmd = 54, /* cmd */ + YYSYMBOL_basic = 55, /* basic */ + YYSYMBOL_atom = 56, /* atom */ + YYSYMBOL_word = 57, /* word */ + YYSYMBOL_executable = 58, /* executable */ + YYSYMBOL_nonkeyword = 59, /* nonkeyword */ + YYSYMBOL_keyword = 60, /* keyword */ + YYSYMBOL_words = 61, /* words */ + YYSYMBOL_wordsnl = 62, /* wordsnl */ + YYSYMBOL_nl = 63 /* nl */ }; typedef enum yysymbol_kind_t yysymbol_kind_t; @@ -278,7 +282,7 @@ typedef int yytype_uint16; /* Stored state numbers (used for stacks). */ -typedef yytype_int8 yy_state_t; +typedef yytype_uint8 yy_state_t; /* State numbers in computations. */ typedef int yy_state_fast_t; @@ -487,21 +491,21 @@ union yyalloc #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ -#define YYFINAL 49 +#define YYFINAL 56 /* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 290 +#define YYLAST 478 /* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 38 +#define YYNTOKENS 40 /* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 22 +#define YYNNTS 24 /* YYNRULES -- Number of rules. */ -#define YYNRULES 63 +#define YYNRULES 73 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 96 +#define YYNSTATES 129 /* YYMAXUTOK -- Last valid token kind. */ -#define YYMAXUTOK 281 +#define YYMAXUTOK 283 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM @@ -516,18 +520,18 @@ union yyalloc static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 26, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 28, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 28, 2, 35, 2, - 31, 23, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 34, - 2, 36, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 30, 2, 37, 2, + 33, 25, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 36, + 2, 38, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 27, 2, 37, 2, 2, 2, + 2, 2, 2, 2, 29, 2, 39, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 32, 2, 33, 2, 2, 2, 2, + 2, 2, 2, 34, 2, 35, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -542,8 +546,8 @@ static const yytype_int8 yytranslate[] = 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, - 29, 30 + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 26, 27, 31, 32 }; #if YYDEBUG @@ -551,12 +555,13 @@ static const yytype_int8 yytranslate[] = static const yytype_uint8 yyrline[] = { 0, 38, 38, 39, 42, 43, 46, 47, 50, 53, - 56, 57, 60, 61, 64, 65, 68, 71, 72, 75, - 76, 79, 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 92, 93, 94, 97, 98, 101, 102, 105, - 106, 109, 110, 111, 112, 113, 114, 115, 120, 120, - 120, 120, 120, 120, 120, 120, 120, 123, 124, 127, - 128, 129, 131, 133 + 56, 57, 60, 61, 64, 65, 68, 69, 72, 73, + 74, 77, 80, 81, 84, 85, 88, 89, 90, 91, + 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, + 102, 105, 106, 107, 110, 111, 114, 115, 118, 119, + 122, 123, 124, 125, 126, 127, 128, 132, 132, 132, + 132, 132, 132, 132, 132, 132, 132, 135, 136, 139, + 140, 141, 143, 145 }; #endif @@ -573,13 +578,14 @@ static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; static const char *const yytname[] = { "\"end of file\"", "error", "\"invalid token\"", "Tfor", "Tin", - "Twhile", "Tif", "Telse", "Tswitch", "Ttwiddle", "Tbang", "Tsubshell", - "Tfunc", "Tredir", "Tdup", "Tpipe", "Tindex", "Tbasic", "Targs", "Tword", - "Twords", "Tparen", "Tblock", "')'", "Tandand", "Toror", "'\\n'", "'^'", - "'$'", "Tcount", "Tjoin", "'('", "'{'", "'}'", "';'", "'&'", "'='", - "'`'", "$accept", "rc", "line", "body", "paren", "block", "cmds", - "cmdsln", "ifbody", "assign", "redir", "epilog", "cmd", "basic", "atom", - "word", "executable", "nonkeyword", "keyword", "words", "wordsnl", "nl", YY_NULLPTR + "Twhile", "Tif", "Telse", "Tswitch", "Tcase", "Tcasebody", "Ttwiddle", + "Tbang", "Tsubshell", "Tfunc", "Tredir", "Tdup", "Tpipe", "Tindex", + "Tbasic", "Targs", "Tword", "Twords", "Tparen", "Tblock", "')'", + "Tandand", "Toror", "'\\n'", "'^'", "'$'", "Tcount", "Tjoin", "'('", + "'{'", "'}'", "';'", "'&'", "'='", "'`'", "$accept", "rc", "line", + "body", "paren", "block", "cmds", "cmdsln", "ifbody", "case", "casebody", + "assign", "redir", "epilog", "cmd", "basic", "atom", "word", + "executable", "nonkeyword", "keyword", "words", "wordsnl", "nl", YY_NULLPTR }; static const char * @@ -589,7 +595,7 @@ yysymbol_name (yysymbol_kind_t yysymbol) } #endif -#define YYPACT_NINF (-46) +#define YYPACT_NINF (-82) #define yypact_value_is_default(Yyn) \ ((Yyn) == YYPACT_NINF) @@ -603,16 +609,19 @@ yysymbol_name (yysymbol_kind_t yysymbol) STATE-NUM. */ static const yytype_int16 yypact[] = { - 22, -17, 253, 253, 197, -46, -46, 197, 197, 197, - -46, 253, -13, 45, 23, 49, 253, 253, 253, 57, - 92, 7, -46, 253, -46, 40, 40, -46, -46, -46, - -46, -46, -46, -46, -46, -46, -46, 31, -46, -46, - 44, -46, -46, 127, 37, -46, 253, 5, -46, -46, - -46, 49, -46, -46, 40, 40, -46, -46, -46, -46, - -46, -46, 31, 197, 197, 52, 225, 197, -46, -46, - -46, 31, -46, -46, -46, -46, 225, 225, 225, -46, - 31, -46, -46, 60, -46, 32, -46, 162, -46, 40, - 40, -46, -46, 31, 225, 32 + 121, -17, -2, -2, 5, 439, 439, 343, -82, -82, + 343, 343, 343, -82, 439, -23, 45, 32, 11, 439, + 439, 439, 13, 158, -14, -82, 343, 439, -82, -82, + 343, 30, 30, -82, -82, -82, -82, -82, -82, -82, + -82, -82, -82, -82, 34, -82, -82, 47, -82, -82, + 195, 41, -82, 439, 54, -82, -82, -82, 11, -82, + -82, 30, 30, -82, -82, -82, -82, -82, -82, 34, + 343, 343, 19, 44, 375, 375, 4, 343, -82, -82, + -82, 34, -82, -82, -82, -82, 375, 375, 375, -82, + 34, -82, -82, -82, -82, 29, 77, -82, 29, -82, + -82, 269, -82, 30, 30, 306, 375, -82, 25, -82, + 34, -82, 29, 375, 407, 375, 29, -82, 407, 407, + 48, 54, 29, 232, -82, -82, -82, -82, -82 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -620,141 +629,185 @@ static const yytype_int16 yypact[] = means the default is an error. */ static const yytype_int8 yydefact[] = { - 21, 0, 21, 21, 0, 17, 41, 0, 0, 0, - 59, 21, 0, 0, 0, 19, 21, 21, 21, 4, - 22, 32, 39, 21, 62, 29, 30, 49, 48, 50, - 51, 52, 53, 54, 55, 56, 37, 18, 35, 36, - 42, 45, 46, 0, 0, 12, 21, 6, 47, 1, - 3, 19, 23, 5, 28, 27, 62, 62, 62, 10, - 11, 34, 33, 0, 0, 0, 21, 0, 57, 44, - 60, 61, 9, 7, 13, 20, 21, 21, 21, 40, - 16, 8, 63, 19, 31, 14, 38, 0, 24, 25, - 26, 62, 43, 58, 21, 15 + 26, 0, 0, 0, 0, 26, 26, 0, 22, 50, + 0, 0, 0, 69, 26, 0, 0, 0, 24, 26, + 26, 26, 4, 27, 41, 48, 0, 26, 72, 72, + 0, 34, 35, 58, 57, 59, 60, 61, 62, 63, + 64, 65, 66, 46, 23, 44, 45, 51, 54, 55, + 0, 0, 12, 26, 6, 56, 1, 3, 24, 28, + 5, 33, 32, 72, 72, 72, 10, 11, 43, 42, + 0, 0, 0, 0, 26, 26, 0, 0, 67, 53, + 70, 71, 9, 7, 13, 25, 26, 26, 26, 49, + 21, 67, 72, 8, 73, 38, 24, 39, 14, 72, + 47, 0, 29, 30, 31, 0, 26, 72, 0, 52, + 68, 72, 36, 26, 26, 26, 15, 67, 26, 26, + 0, 18, 37, 0, 20, 19, 40, 17, 16 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { - -46, -46, 64, -8, -46, -5, 26, -46, -46, -46, - -14, 33, 0, -46, 16, -16, -46, 1, -46, -46, - -46, -45 + -82, -82, 75, -19, 93, -11, 18, -52, -82, -82, + -21, -82, -1, 42, 0, -82, -9, 28, -82, 2, + -82, -81, -82, -22 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { - 0, 13, 14, 44, 24, 15, 45, 46, 84, 17, - 18, 52, 47, 20, 36, 37, 21, 22, 39, 87, - 43, 66 + 0, 16, 17, 51, 28, 18, 52, 53, 97, 119, + 120, 20, 21, 59, 54, 23, 43, 110, 24, 25, + 46, 101, 50, 74 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule whose number is the opposite. If YYTABLE_NINF, syntax error. */ -static const yytype_int8 yytable[] = +static const yytype_int16 yytable[] = { - 19, 51, 25, 26, 62, 38, 61, 48, 38, 38, - 38, 76, 77, 78, 23, 65, 19, 54, 55, 11, - 56, 38, -2, 40, 41, 42, 16, 71, 1, 57, - 58, 74, 2, 3, 63, 4, 5, 51, 73, 59, - 60, 6, 16, 64, 38, 49, 94, 56, 80, 50, - 7, 8, 9, 10, 11, 56, 57, 58, 67, 12, - 68, 83, 4, 5, 38, 38, 85, 91, 38, 51, - 72, 93, 56, 4, 5, 81, 88, 89, 90, 79, - 53, 57, 58, 86, 75, 0, 0, 0, 38, 0, - 0, 59, 60, 0, 95, 27, 28, 29, 30, 31, - 32, 0, 33, 34, 35, 4, 5, 0, 0, 0, - 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, - 7, 8, 9, 10, 0, 0, 0, 0, 0, 12, - 27, 28, 29, 30, 31, 32, 0, 33, 34, 35, - 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, - 69, 0, 0, 70, 0, 7, 8, 9, 10, 0, - 0, 0, 0, 0, 12, 27, 28, 29, 30, 31, - 32, 0, 33, 34, 35, 0, 0, 0, 0, 0, - 0, 6, 0, 0, 0, 92, 0, 0, 0, 0, - 7, 8, 9, 10, 0, 0, 0, 0, 0, 12, - 27, 28, 29, 30, 31, 32, 0, 33, 34, 35, - 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, - 0, 0, 0, 0, 0, 7, 8, 9, 10, 0, - 0, 1, 0, 0, 12, 2, 3, 0, 4, 5, - 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, - 0, 82, 0, 7, 8, 9, 10, 11, 0, 1, - 0, 0, 12, 2, 3, 0, 4, 5, 0, 0, - 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, - 0, 7, 8, 9, 10, 11, 0, 0, 0, 0, - 12 + 22, 47, 48, 49, 55, 31, 32, 75, 73, 45, + 105, 14, 45, 45, 45, 70, 26, 58, 19, 22, + 61, 62, 68, 91, 71, 45, 7, 8, 45, 99, + 63, 27, 45, 77, 83, 44, 123, 19, 30, 64, + 65, 86, 87, 88, 92, 56, 63, 63, 77, 66, + 67, 69, 45, 94, 72, 64, 65, 58, 76, 114, + 57, 89, 118, 77, 96, 78, 118, 118, 100, 93, + 106, 63, 45, 45, 95, 98, 82, 108, 81, 45, + 64, 65, 84, 126, 107, 113, 102, 103, 104, 115, + 66, 67, 7, 8, 60, 58, 29, 124, 125, 90, + 85, 0, 0, 45, 0, 0, 112, 45, 0, 0, + 0, 0, 0, 116, 121, 122, 0, 0, 121, 121, + 0, -2, 0, 0, 1, 45, 2, 3, 0, 4, + 0, 0, 0, 5, 6, 0, 7, 8, 0, 0, + 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, + 0, 10, 11, 12, 13, 14, 0, 0, 0, 0, + 15, 33, 34, 35, 36, 37, 38, 39, 0, 0, + 40, 41, 42, 7, 8, 0, 0, 0, 0, 9, + 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, + 12, 13, 0, 0, 0, 0, 0, 15, 33, 34, + 35, 36, 37, 38, 39, 0, 0, 40, 41, 42, + 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, + 79, 0, 0, 80, 0, 10, 11, 12, 13, 0, + 0, 0, 0, 0, 15, 33, 34, 35, 36, 37, + 38, 39, 0, 0, 40, 41, 42, 0, 0, 0, + 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, + 127, 0, 10, 11, 12, 13, 0, 0, 128, 0, + 0, 15, 33, 34, 35, 36, 37, 38, 39, 0, + 0, 40, 41, 42, 0, 0, 0, 0, 0, 0, + 9, 0, 0, 0, 109, 0, 0, 0, 0, 10, + 11, 12, 13, 0, 0, 0, 0, 0, 15, 33, + 34, 35, 36, 37, 38, 39, 0, 0, 40, 41, + 42, 0, 0, 0, 0, 0, 0, 9, 0, 0, + 0, 111, 0, 0, 0, 0, 10, 11, 12, 13, + 0, 0, 0, 0, 0, 15, 33, 34, 35, 36, + 37, 38, 39, 0, 0, 40, 41, 42, 0, 0, + 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, + 0, 0, 0, 10, 11, 12, 13, 0, 1, 0, + 2, 3, 15, 4, 0, 0, 0, 5, 6, 0, + 7, 8, 0, 0, 0, 0, 9, 0, 0, 0, + 0, 0, 0, 94, 0, 10, 11, 12, 13, 14, + 1, 0, 2, 3, 15, 4, 117, 0, 0, 5, + 6, 0, 7, 8, 0, 0, 0, 0, 9, 0, + 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, + 13, 14, 1, 0, 2, 3, 15, 4, 0, 0, + 0, 5, 6, 0, 7, 8, 0, 0, 0, 0, + 9, 0, 0, 0, 0, 0, 0, 0, 0, 10, + 11, 12, 13, 14, 0, 0, 0, 0, 15 }; static const yytype_int8 yycheck[] = { - 0, 15, 2, 3, 20, 4, 20, 12, 7, 8, - 9, 56, 57, 58, 31, 23, 16, 17, 18, 32, - 15, 20, 0, 7, 8, 9, 0, 43, 6, 24, - 25, 26, 10, 11, 27, 13, 14, 51, 46, 34, - 35, 19, 16, 36, 43, 0, 91, 15, 64, 26, - 28, 29, 30, 31, 32, 15, 24, 25, 27, 37, - 16, 66, 13, 14, 63, 64, 66, 7, 67, 83, - 33, 87, 15, 13, 14, 23, 76, 77, 78, 63, - 16, 24, 25, 67, 51, -1, -1, -1, 87, -1, - -1, 34, 35, -1, 94, 3, 4, 5, 6, 7, - 8, -1, 10, 11, 12, 13, 14, -1, -1, -1, - -1, 19, -1, -1, -1, -1, -1, -1, -1, -1, - 28, 29, 30, 31, -1, -1, -1, -1, -1, 37, - 3, 4, 5, 6, 7, 8, -1, 10, 11, 12, - -1, -1, -1, -1, -1, -1, 19, -1, -1, -1, - 23, -1, -1, 26, -1, 28, 29, 30, 31, -1, - -1, -1, -1, -1, 37, 3, 4, 5, 6, 7, - 8, -1, 10, 11, 12, -1, -1, -1, -1, -1, - -1, 19, -1, -1, -1, 23, -1, -1, -1, -1, - 28, 29, 30, 31, -1, -1, -1, -1, -1, 37, - 3, 4, 5, 6, 7, 8, -1, 10, 11, 12, - -1, -1, -1, -1, -1, -1, 19, -1, -1, -1, - -1, -1, -1, -1, -1, 28, 29, 30, 31, -1, - -1, 6, -1, -1, 37, 10, 11, -1, 13, 14, - -1, -1, -1, -1, 19, -1, -1, -1, -1, -1, - -1, 26, -1, 28, 29, 30, 31, 32, -1, 6, - -1, -1, 37, 10, 11, -1, 13, 14, -1, -1, - -1, -1, 19, -1, -1, -1, -1, -1, -1, -1, - -1, 28, 29, 30, 31, 32, -1, -1, -1, -1, - 37 + 0, 10, 11, 12, 15, 5, 6, 29, 27, 7, + 91, 34, 10, 11, 12, 29, 33, 18, 0, 19, + 20, 21, 23, 4, 38, 23, 15, 16, 26, 25, + 17, 33, 30, 29, 53, 7, 117, 19, 33, 26, + 27, 63, 64, 65, 25, 0, 17, 17, 29, 36, + 37, 23, 50, 28, 26, 26, 27, 58, 30, 34, + 28, 70, 114, 29, 75, 18, 118, 119, 77, 25, + 92, 17, 70, 71, 74, 75, 35, 99, 50, 77, + 26, 27, 28, 35, 7, 107, 86, 87, 88, 111, + 36, 37, 15, 16, 19, 96, 3, 118, 119, 71, + 58, -1, -1, 101, -1, -1, 106, 105, -1, -1, + -1, -1, -1, 113, 114, 115, -1, -1, 118, 119, + -1, 0, -1, -1, 3, 123, 5, 6, -1, 8, + -1, -1, -1, 12, 13, -1, 15, 16, -1, -1, + -1, -1, 21, -1, -1, -1, -1, -1, -1, -1, + -1, 30, 31, 32, 33, 34, -1, -1, -1, -1, + 39, 3, 4, 5, 6, 7, 8, 9, -1, -1, + 12, 13, 14, 15, 16, -1, -1, -1, -1, 21, + -1, -1, -1, -1, -1, -1, -1, -1, 30, 31, + 32, 33, -1, -1, -1, -1, -1, 39, 3, 4, + 5, 6, 7, 8, 9, -1, -1, 12, 13, 14, + -1, -1, -1, -1, -1, -1, 21, -1, -1, -1, + 25, -1, -1, 28, -1, 30, 31, 32, 33, -1, + -1, -1, -1, -1, 39, 3, 4, 5, 6, 7, + 8, 9, -1, -1, 12, 13, 14, -1, -1, -1, + -1, -1, -1, 21, -1, -1, -1, -1, -1, -1, + 28, -1, 30, 31, 32, 33, -1, -1, 36, -1, + -1, 39, 3, 4, 5, 6, 7, 8, 9, -1, + -1, 12, 13, 14, -1, -1, -1, -1, -1, -1, + 21, -1, -1, -1, 25, -1, -1, -1, -1, 30, + 31, 32, 33, -1, -1, -1, -1, -1, 39, 3, + 4, 5, 6, 7, 8, 9, -1, -1, 12, 13, + 14, -1, -1, -1, -1, -1, -1, 21, -1, -1, + -1, 25, -1, -1, -1, -1, 30, 31, 32, 33, + -1, -1, -1, -1, -1, 39, 3, 4, 5, 6, + 7, 8, 9, -1, -1, 12, 13, 14, -1, -1, + -1, -1, -1, -1, 21, -1, -1, -1, -1, -1, + -1, -1, -1, 30, 31, 32, 33, -1, 3, -1, + 5, 6, 39, 8, -1, -1, -1, 12, 13, -1, + 15, 16, -1, -1, -1, -1, 21, -1, -1, -1, + -1, -1, -1, 28, -1, 30, 31, 32, 33, 34, + 3, -1, 5, 6, 39, 8, 9, -1, -1, 12, + 13, -1, 15, 16, -1, -1, -1, -1, 21, -1, + -1, -1, -1, -1, -1, -1, -1, 30, 31, 32, + 33, 34, 3, -1, 5, 6, 39, 8, -1, -1, + -1, 12, 13, -1, 15, 16, -1, -1, -1, -1, + 21, -1, -1, -1, -1, -1, -1, -1, -1, 30, + 31, 32, 33, 34, -1, -1, -1, -1, 39 }; /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of state STATE-NUM. */ static const yytype_int8 yystos[] = { - 0, 6, 10, 11, 13, 14, 19, 28, 29, 30, - 31, 32, 37, 39, 40, 43, 44, 47, 48, 50, - 51, 54, 55, 31, 42, 50, 50, 3, 4, 5, - 6, 7, 8, 10, 11, 12, 52, 53, 55, 56, - 52, 52, 52, 58, 41, 44, 45, 50, 43, 0, - 26, 48, 49, 40, 50, 50, 15, 24, 25, 34, - 35, 48, 53, 27, 36, 41, 59, 27, 16, 23, - 26, 53, 33, 41, 26, 49, 59, 59, 59, 52, - 53, 23, 26, 43, 46, 50, 52, 57, 50, 50, - 50, 7, 23, 53, 59, 50 + 0, 3, 5, 6, 8, 12, 13, 15, 16, 21, + 30, 31, 32, 33, 34, 39, 41, 42, 45, 46, + 51, 52, 54, 55, 58, 59, 33, 33, 44, 44, + 33, 54, 54, 3, 4, 5, 6, 7, 8, 9, + 12, 13, 14, 56, 57, 59, 60, 56, 56, 56, + 62, 43, 46, 47, 54, 45, 0, 28, 52, 53, + 42, 54, 54, 17, 26, 27, 36, 37, 52, 57, + 29, 38, 57, 43, 63, 63, 57, 29, 18, 25, + 28, 57, 35, 43, 28, 53, 63, 63, 63, 56, + 57, 4, 25, 25, 28, 54, 45, 48, 54, 25, + 56, 61, 54, 54, 54, 61, 63, 7, 63, 25, + 57, 25, 54, 63, 34, 63, 54, 9, 47, 49, + 50, 54, 54, 61, 50, 50, 35, 28, 36 }; /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ static const yytype_int8 yyr1[] = { - 0, 38, 39, 39, 40, 40, 41, 41, 42, 43, - 44, 44, 45, 45, 46, 46, 47, 48, 48, 49, - 49, 50, 50, 50, 50, 50, 50, 50, 50, 50, - 50, 50, 51, 51, 51, 52, 52, 53, 53, 54, - 54, 55, 55, 55, 55, 55, 55, 55, 56, 56, - 56, 56, 56, 56, 56, 56, 56, 57, 57, 58, - 58, 58, 59, 59 + 0, 40, 41, 41, 42, 42, 43, 43, 44, 45, + 46, 46, 47, 47, 48, 48, 49, 49, 50, 50, + 50, 51, 52, 52, 53, 53, 54, 54, 54, 54, + 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, + 54, 55, 55, 55, 56, 56, 57, 57, 58, 58, + 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, + 60, 60, 60, 60, 60, 60, 60, 61, 61, 62, + 62, 62, 63, 63 }; /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ static const yytype_int8 yyr2[] = { 0, 2, 0, 2, 1, 2, 1, 2, 3, 3, - 2, 2, 1, 2, 1, 4, 3, 1, 2, 0, - 2, 0, 1, 2, 4, 4, 4, 2, 2, 2, - 2, 4, 1, 2, 2, 1, 1, 1, 3, 1, - 3, 1, 2, 5, 3, 2, 2, 2, 1, 1, + 2, 2, 1, 2, 1, 4, 3, 3, 1, 2, + 2, 3, 1, 2, 0, 2, 0, 1, 2, 4, + 4, 4, 2, 2, 2, 2, 6, 8, 4, 4, + 8, 1, 2, 2, 1, 1, 1, 3, 1, 3, + 1, 2, 5, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 0, 2 }; @@ -1492,239 +1545,293 @@ yyreduce: case 2: /* rc: %empty */ #line 38 "sys/cmd/rc/syntax.y" { return 0; } -#line 1496 "sys/cmd/rc/parse.c" +#line 1549 "sys/cmd/rc/parse.c" break; case 3: /* rc: line '\n' */ #line 39 "sys/cmd/rc/syntax.y" { return compile((yyvsp[-1].tree)); } -#line 1502 "sys/cmd/rc/parse.c" +#line 1555 "sys/cmd/rc/parse.c" break; case 5: /* line: cmds line */ #line 43 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2(';', (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1508 "sys/cmd/rc/parse.c" +#line 1561 "sys/cmd/rc/parse.c" break; case 7: /* body: cmdsln body */ #line 47 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2(';', (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1514 "sys/cmd/rc/parse.c" +#line 1567 "sys/cmd/rc/parse.c" break; case 8: /* paren: '(' body ')' */ #line 50 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tparen, (yyvsp[-1].tree)); } -#line 1520 "sys/cmd/rc/parse.c" +#line 1573 "sys/cmd/rc/parse.c" break; case 9: /* block: '{' body '}' */ #line 53 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tblock, (yyvsp[-1].tree)); } -#line 1526 "sys/cmd/rc/parse.c" +#line 1579 "sys/cmd/rc/parse.c" break; case 11: /* cmds: cmd '&' */ #line 57 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1('&', (yyvsp[-1].tree)); } -#line 1532 "sys/cmd/rc/parse.c" +#line 1585 "sys/cmd/rc/parse.c" break; case 14: /* ifbody: cmd */ #line 64 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Tif, nil, (yyvsp[0].tree)); } -#line 1538 "sys/cmd/rc/parse.c" +#line 1591 "sys/cmd/rc/parse.c" break; case 15: /* ifbody: block Telse nl cmd */ #line 65 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree3(Tif, nil, (yyvsp[-3].tree), (yyvsp[-2].tree)); } -#line 1544 "sys/cmd/rc/parse.c" +#line 1597 "sys/cmd/rc/parse.c" break; - case 16: /* assign: executable '=' word */ + case 16: /* case: Tcase words ';' */ #line 68 "sys/cmd/rc/syntax.y" - { (yyval.tree) = maketree2('=', (yyvsp[-2].tree), (yyvsp[0].tree)); } -#line 1550 "sys/cmd/rc/parse.c" + { (yyval.tree) = hangchild1((yyvsp[-2].tree), (yyvsp[-1].tree), 0); } +#line 1603 "sys/cmd/rc/parse.c" + break; + + case 17: /* case: Tcase words '\n' */ +#line 69 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild1((yyvsp[-2].tree), (yyvsp[-1].tree), 0); } +#line 1609 "sys/cmd/rc/parse.c" break; - case 18: /* redir: Tredir word */ + case 18: /* casebody: cmd */ #line 72 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree2(Tcasebody, (yyvsp[0].tree), nil); } +#line 1615 "sys/cmd/rc/parse.c" + break; + + case 19: /* casebody: case casebody */ +#line 73 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree2(Tcasebody, (yyvsp[-1].tree), (yyvsp[0].tree)); } +#line 1621 "sys/cmd/rc/parse.c" + break; + + case 20: /* casebody: cmdsln casebody */ +#line 74 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree2(Tcasebody, (yyvsp[-1].tree), (yyvsp[0].tree)); } +#line 1627 "sys/cmd/rc/parse.c" + break; + + case 21: /* assign: executable '=' word */ +#line 77 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree2('=', (yyvsp[-2].tree), (yyvsp[0].tree)); } +#line 1633 "sys/cmd/rc/parse.c" + break; + + case 23: /* redir: Tredir word */ +#line 81 "sys/cmd/rc/syntax.y" { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 0); } -#line 1556 "sys/cmd/rc/parse.c" +#line 1639 "sys/cmd/rc/parse.c" break; - case 19: /* epilog: %empty */ -#line 75 "sys/cmd/rc/syntax.y" + case 24: /* epilog: %empty */ +#line 84 "sys/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1562 "sys/cmd/rc/parse.c" +#line 1645 "sys/cmd/rc/parse.c" break; - case 20: /* epilog: redir epilog */ -#line 76 "sys/cmd/rc/syntax.y" + case 25: /* epilog: redir epilog */ +#line 85 "sys/cmd/rc/syntax.y" { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 1); } -#line 1568 "sys/cmd/rc/parse.c" +#line 1651 "sys/cmd/rc/parse.c" break; - case 21: /* cmd: %empty */ -#line 79 "sys/cmd/rc/syntax.y" - { (yyval.tree) = nil; } -#line 1574 "sys/cmd/rc/parse.c" + case 26: /* cmd: %empty */ +#line 88 "sys/cmd/rc/syntax.y" + { (yyval.tree) = nil; } +#line 1657 "sys/cmd/rc/parse.c" break; - case 22: /* cmd: basic */ -#line 80 "sys/cmd/rc/syntax.y" - { (yyval.tree) = maketree1(Tbasic, (yyvsp[0].tree)); } -#line 1580 "sys/cmd/rc/parse.c" + case 27: /* cmd: basic */ +#line 89 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree1(Tbasic, (yyvsp[0].tree)); } +#line 1663 "sys/cmd/rc/parse.c" break; - case 23: /* cmd: block epilog */ -#line 81 "sys/cmd/rc/syntax.y" - { (yyval.tree) = hangepilog((yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1586 "sys/cmd/rc/parse.c" + case 28: /* cmd: block epilog */ +#line 90 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangepilog((yyvsp[-1].tree), (yyvsp[0].tree)); } +#line 1669 "sys/cmd/rc/parse.c" break; - case 24: /* cmd: cmd Tpipe nl cmd */ -#line 82 "sys/cmd/rc/syntax.y" - { (yyval.tree) = hangchild2((yyvsp[-2].tree), (yyvsp[-3].tree), 0, (yyvsp[0].tree), 1); } -#line 1592 "sys/cmd/rc/parse.c" + case 29: /* cmd: cmd Tpipe nl cmd */ +#line 91 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild2((yyvsp[-2].tree), (yyvsp[-3].tree), 0, (yyvsp[0].tree), 1); } +#line 1675 "sys/cmd/rc/parse.c" break; - case 25: /* cmd: cmd Tandand nl cmd */ -#line 83 "sys/cmd/rc/syntax.y" - { (yyval.tree) = maketree2(Tandand, (yyvsp[-3].tree), (yyvsp[0].tree)); } -#line 1598 "sys/cmd/rc/parse.c" + case 30: /* cmd: cmd Tandand nl cmd */ +#line 92 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree2(Tandand, (yyvsp[-3].tree), (yyvsp[0].tree)); } +#line 1681 "sys/cmd/rc/parse.c" break; - case 26: /* cmd: cmd Toror nl cmd */ -#line 84 "sys/cmd/rc/syntax.y" - { (yyval.tree) = maketree2(Toror, (yyvsp[-3].tree), (yyvsp[0].tree)); } -#line 1604 "sys/cmd/rc/parse.c" + case 31: /* cmd: cmd Toror nl cmd */ +#line 93 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree2(Toror, (yyvsp[-3].tree), (yyvsp[0].tree)); } +#line 1687 "sys/cmd/rc/parse.c" break; - case 27: /* cmd: redir cmd */ -#line 85 "sys/cmd/rc/syntax.y" - { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 1); } -#line 1610 "sys/cmd/rc/parse.c" + case 32: /* cmd: redir cmd */ +#line 94 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 1); } +#line 1693 "sys/cmd/rc/parse.c" break; - case 28: /* cmd: assign cmd */ -#line 86 "sys/cmd/rc/syntax.y" - { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 2); } -#line 1616 "sys/cmd/rc/parse.c" + case 33: /* cmd: assign cmd */ +#line 95 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild1((yyvsp[-1].tree), (yyvsp[0].tree), 2); } +#line 1699 "sys/cmd/rc/parse.c" break; - case 29: /* cmd: Tbang cmd */ -#line 87 "sys/cmd/rc/syntax.y" - { (yyval.tree) = maketree1(Tbang, (yyvsp[0].tree)); } -#line 1622 "sys/cmd/rc/parse.c" + case 34: /* cmd: Tbang cmd */ +#line 96 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree1(Tbang, (yyvsp[0].tree)); } +#line 1705 "sys/cmd/rc/parse.c" break; - case 30: /* cmd: Tsubshell cmd */ -#line 88 "sys/cmd/rc/syntax.y" - { (yyval.tree) = maketree1(Tsubshell, (yyvsp[0].tree)); } -#line 1628 "sys/cmd/rc/parse.c" + case 35: /* cmd: Tsubshell cmd */ +#line 97 "sys/cmd/rc/syntax.y" + { (yyval.tree) = maketree1(Tsubshell, (yyvsp[0].tree)); } +#line 1711 "sys/cmd/rc/parse.c" break; - case 31: /* cmd: Tif paren nl ifbody */ -#line 89 "sys/cmd/rc/syntax.y" - { (yyval.tree) = hangchild1((yyvsp[-2].tree), (yyvsp[-3].tree), 0); } -#line 1634 "sys/cmd/rc/parse.c" + case 36: /* cmd: Tfor '(' word ')' nl cmd */ +#line 98 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild3((yyvsp[-5].tree), (yyvsp[-3].tree), nil, (yyvsp[0].tree)); } +#line 1717 "sys/cmd/rc/parse.c" break; - case 33: /* basic: basic word */ -#line 93 "sys/cmd/rc/syntax.y" + case 37: /* cmd: Tfor '(' word Tin words ')' nl cmd */ +#line 99 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild3((yyvsp[-7].tree), (yyvsp[-5].tree), (yyvsp[-3].tree), (yyvsp[0].tree)); } +#line 1723 "sys/cmd/rc/parse.c" + break; + + case 38: /* cmd: Twhile paren nl cmd */ +#line 100 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild2((yyvsp[-3].tree), (yyvsp[-2].tree), 0, (yyvsp[0].tree), 1); } +#line 1729 "sys/cmd/rc/parse.c" + break; + + case 39: /* cmd: Tif paren nl ifbody */ +#line 101 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild1((yyvsp[-2].tree), (yyvsp[-3].tree), 0); } +#line 1735 "sys/cmd/rc/parse.c" + break; + + case 40: /* cmd: Tswitch '(' word ')' nl '{' casebody '}' */ +#line 102 "sys/cmd/rc/syntax.y" + { (yyval.tree) = hangchild2((yyvsp[-7].tree), (yyvsp[-5].tree), 0, (yyvsp[-1].tree), 1); } +#line 1741 "sys/cmd/rc/parse.c" + break; + + case 42: /* basic: basic word */ +#line 106 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Targs, (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1640 "sys/cmd/rc/parse.c" +#line 1747 "sys/cmd/rc/parse.c" break; - case 34: /* basic: basic redir */ -#line 94 "sys/cmd/rc/syntax.y" + case 43: /* basic: basic redir */ +#line 107 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Targs, (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1646 "sys/cmd/rc/parse.c" +#line 1753 "sys/cmd/rc/parse.c" break; - case 36: /* atom: keyword */ -#line 98 "sys/cmd/rc/syntax.y" + case 45: /* atom: keyword */ +#line 111 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tword, (yyvsp[0].tree)); } -#line 1652 "sys/cmd/rc/parse.c" +#line 1759 "sys/cmd/rc/parse.c" break; - case 38: /* word: word '^' atom */ -#line 102 "sys/cmd/rc/syntax.y" + case 47: /* word: word '^' atom */ +#line 115 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2('^', (yyvsp[-2].tree), (yyvsp[0].tree)); } -#line 1658 "sys/cmd/rc/parse.c" +#line 1765 "sys/cmd/rc/parse.c" break; - case 40: /* executable: executable '^' atom */ -#line 106 "sys/cmd/rc/syntax.y" + case 49: /* executable: executable '^' atom */ +#line 119 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2('^', (yyvsp[-2].tree), (yyvsp[0].tree)); } -#line 1664 "sys/cmd/rc/parse.c" +#line 1771 "sys/cmd/rc/parse.c" break; - case 42: /* nonkeyword: '$' atom */ -#line 110 "sys/cmd/rc/syntax.y" + case 51: /* nonkeyword: '$' atom */ +#line 123 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1('$', (yyvsp[0].tree)); } -#line 1670 "sys/cmd/rc/parse.c" +#line 1777 "sys/cmd/rc/parse.c" break; - case 43: /* nonkeyword: '$' atom Tindex words ')' */ -#line 111 "sys/cmd/rc/syntax.y" + case 52: /* nonkeyword: '$' atom Tindex words ')' */ +#line 124 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Tindex, (yyvsp[-3].tree), (yyvsp[-1].tree)); } -#line 1676 "sys/cmd/rc/parse.c" +#line 1783 "sys/cmd/rc/parse.c" break; - case 44: /* nonkeyword: '(' wordsnl ')' */ -#line 112 "sys/cmd/rc/syntax.y" + case 53: /* nonkeyword: '(' wordsnl ')' */ +#line 125 "sys/cmd/rc/syntax.y" { (yyval.tree) = (yyvsp[-1].tree); } -#line 1682 "sys/cmd/rc/parse.c" +#line 1789 "sys/cmd/rc/parse.c" break; - case 45: /* nonkeyword: Tcount atom */ -#line 113 "sys/cmd/rc/syntax.y" + case 54: /* nonkeyword: Tcount atom */ +#line 126 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tcount, (yyvsp[0].tree)); } -#line 1688 "sys/cmd/rc/parse.c" +#line 1795 "sys/cmd/rc/parse.c" break; - case 46: /* nonkeyword: Tjoin atom */ -#line 114 "sys/cmd/rc/syntax.y" + case 55: /* nonkeyword: Tjoin atom */ +#line 127 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1(Tjoin, (yyvsp[0].tree)); } -#line 1694 "sys/cmd/rc/parse.c" +#line 1801 "sys/cmd/rc/parse.c" break; - case 47: /* nonkeyword: '`' block */ -#line 115 "sys/cmd/rc/syntax.y" + case 56: /* nonkeyword: '`' block */ +#line 128 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree1('`', (yyvsp[0].tree)); } -#line 1700 "sys/cmd/rc/parse.c" +#line 1807 "sys/cmd/rc/parse.c" break; - case 57: /* words: %empty */ -#line 123 "sys/cmd/rc/syntax.y" + case 67: /* words: %empty */ +#line 135 "sys/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1706 "sys/cmd/rc/parse.c" +#line 1813 "sys/cmd/rc/parse.c" break; - case 58: /* words: words word */ -#line 124 "sys/cmd/rc/syntax.y" + case 68: /* words: words word */ +#line 136 "sys/cmd/rc/syntax.y" { (yyval.tree) = maketree2(Twords, (yyvsp[-1].tree), (yyvsp[0].tree)); } -#line 1712 "sys/cmd/rc/parse.c" +#line 1819 "sys/cmd/rc/parse.c" break; - case 59: /* wordsnl: %empty */ -#line 127 "sys/cmd/rc/syntax.y" + case 69: /* wordsnl: %empty */ +#line 139 "sys/cmd/rc/syntax.y" { (yyval.tree) = nil; } -#line 1718 "sys/cmd/rc/parse.c" +#line 1825 "sys/cmd/rc/parse.c" break; - case 61: /* wordsnl: wordsnl word */ -#line 129 "sys/cmd/rc/syntax.y" + case 71: /* wordsnl: wordsnl word */ +#line 141 "sys/cmd/rc/syntax.y" {(yyval.tree) = (!(yyvsp[-1].tree)) ? ((!(yyvsp[0].tree)) ? nil : (yyvsp[0].tree)) : ((!(yyvsp[0].tree)) ? (yyvsp[-1].tree) : maketree2(Twords, (yyvsp[-1].tree), (yyvsp[0].tree))); } -#line 1724 "sys/cmd/rc/parse.c" +#line 1831 "sys/cmd/rc/parse.c" break; -#line 1728 "sys/cmd/rc/parse.c" +#line 1835 "sys/cmd/rc/parse.c" default: break; } @@ -1948,5 +2055,5 @@ yyreturnlab: return yyresult; } -#line 134 "sys/cmd/rc/syntax.y" +#line 147 "sys/cmd/rc/syntax.y" diff --git a/sys/cmd/rc/parse.h b/sys/cmd/rc/parse.h index 5955904..64ee07b 100644 --- a/sys/cmd/rc/parse.h +++ b/sys/cmd/rc/parse.h @@ -60,24 +60,26 @@ extern int yydebug; Tif = 261, /* Tif */ Telse = 262, /* Telse */ Tswitch = 263, /* Tswitch */ - Ttwiddle = 264, /* Ttwiddle */ - Tbang = 265, /* Tbang */ - Tsubshell = 266, /* Tsubshell */ - Tfunc = 267, /* Tfunc */ - Tredir = 268, /* Tredir */ - Tdup = 269, /* Tdup */ - Tpipe = 270, /* Tpipe */ - Tindex = 271, /* Tindex */ - Tbasic = 272, /* Tbasic */ - Targs = 273, /* Targs */ - Tword = 274, /* Tword */ - Twords = 275, /* Twords */ - Tparen = 276, /* Tparen */ - Tblock = 277, /* Tblock */ - Tandand = 278, /* Tandand */ - Toror = 279, /* Toror */ - Tcount = 280, /* Tcount */ - Tjoin = 281 /* Tjoin */ + Tcase = 264, /* Tcase */ + Tcasebody = 265, /* Tcasebody */ + Ttwiddle = 266, /* Ttwiddle */ + Tbang = 267, /* Tbang */ + Tsubshell = 268, /* Tsubshell */ + Tfunc = 269, /* Tfunc */ + Tredir = 270, /* Tredir */ + Tdup = 271, /* Tdup */ + Tpipe = 272, /* Tpipe */ + Tindex = 273, /* Tindex */ + Tbasic = 274, /* Tbasic */ + Targs = 275, /* Targs */ + Tword = 276, /* Tword */ + Twords = 277, /* Twords */ + Tparen = 278, /* Tparen */ + Tblock = 279, /* Tblock */ + Tandand = 280, /* Tandand */ + Toror = 281, /* Toror */ + Tcount = 282, /* Tcount */ + Tjoin = 283 /* Tjoin */ }; typedef enum yytokentype yytoken_kind_t; #endif @@ -92,24 +94,26 @@ extern int yydebug; #define Tif 261 #define Telse 262 #define Tswitch 263 -#define Ttwiddle 264 -#define Tbang 265 -#define Tsubshell 266 -#define Tfunc 267 -#define Tredir 268 -#define Tdup 269 -#define Tpipe 270 -#define Tindex 271 -#define Tbasic 272 -#define Targs 273 -#define Tword 274 -#define Twords 275 -#define Tparen 276 -#define Tblock 277 -#define Tandand 278 -#define Toror 279 -#define Tcount 280 -#define Tjoin 281 +#define Tcase 264 +#define Tcasebody 265 +#define Ttwiddle 266 +#define Tbang 267 +#define Tsubshell 268 +#define Tfunc 269 +#define Tredir 270 +#define Tdup 271 +#define Tpipe 272 +#define Tindex 273 +#define Tbasic 274 +#define Targs 275 +#define Tword 276 +#define Twords 277 +#define Tparen 278 +#define Tblock 279 +#define Tandand 280 +#define Toror 281 +#define Tcount 282 +#define Tjoin 283 /* Value type. */ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED @@ -119,7 +123,7 @@ union YYSTYPE struct Tree *tree; -#line 123 "sys/cmd/rc/parse.h" +#line 127 "sys/cmd/rc/parse.h" }; typedef union YYSTYPE YYSTYPE; diff --git a/sys/cmd/rc/rc.h b/sys/cmd/rc/rc.h index 85a046a..11af508 100644 --- a/sys/cmd/rc/rc.h +++ b/sys/cmd/rc/rc.h @@ -203,6 +203,7 @@ Tree *maketree3(int, Tree*, Tree*, Tree*); Tree *token(int, char *); Tree *hangchild1(Tree *, Tree *, int); Tree *hangchild2(Tree *, Tree *, int, Tree *, int); +Tree *hangchild3(Tree *, Tree *, Tree *, Tree *); Tree *hangepilog(Tree *, Tree*); void freeparsetree(void); diff --git a/sys/cmd/rc/syntax.y b/sys/cmd/rc/syntax.y index f3c9f29..58bef16 100644 --- a/sys/cmd/rc/syntax.y +++ b/sys/cmd/rc/syntax.y @@ -1,4 +1,4 @@ -%token Tfor Tin Twhile Tif Telse Tswitch Ttwiddle Tbang Tsubshell Tfunc +%token Tfor Tin Twhile Tif Telse Tswitch Tcase Tcasebody Ttwiddle Tbang Tsubshell Tfunc %token Tredir Tdup Tpipe Tindex %token Tbasic Targs Tword Twords Tparen Tblock @@ -12,7 +12,7 @@ %} /* operator precendence: lowest first */ -%left Tif Tfor Tswitch ')' Twhile Telse +%left Tif Tfor Tswitch Tcase ')' Twhile Telse %left Tandand Toror '\n' %left Tbang Tsubshell %left Tpipe; @@ -24,9 +24,9 @@ %union{ struct Tree *tree; } -%type line cmds cmdsln body paren block ifbody assign epilog redir; +%type line cmds cmdsln body paren block ifbody casebody case assign epilog redir; %type cmd basic executable nonkeyword keyword word words wordsnl atom; -%type Tfor Tin Twhile Tif Telse Tswitch Ttwiddle Tbang Tsubshell Tfunc; +%type Tfor Tin Twhile Tif Telse Tswitch Tcase Ttwiddle Tbang Tsubshell Tfunc; %type Tword Tredir Tpipe Tdup; /* grammar */ @@ -64,6 +64,15 @@ ifbody: cmd %prec Telse { $$ = maketree2(Tif, nil, $1); } | block Telse nl cmd { $$ = maketree3(Tif, nil, $1, $2); } +case: + Tcase words ';' { $$ = hangchild1($1, $2, 0); } +| Tcase words '\n' { $$ = hangchild1($1, $2, 0); } + +casebody: + cmd { $$ = maketree2(Tcasebody, $1, nil); } +| case casebody { $$ = maketree2(Tcasebody, $1, $2); } +| cmdsln casebody { $$ = maketree2(Tcasebody, $1, $2); } + assign: executable '=' word { $$ = maketree2('=', $1, $3); } @@ -76,17 +85,21 @@ epilog: | redir epilog { $$ = hangchild1($1, $2, 1); } cmd: -/* empty */ %prec Twhile { $$ = nil; } -| basic { $$ = maketree1(Tbasic, $1); } -| block epilog { $$ = hangepilog($1, $2); } -| cmd Tpipe nl cmd { $$ = hangchild2($2, $1, 0, $4, 1); } -| cmd Tandand nl cmd { $$ = maketree2(Tandand, $1, $4); } -| cmd Toror nl cmd { $$ = maketree2(Toror, $1, $4); } -| redir cmd %prec Tbang { $$ = hangchild1($1, $2, 1); } -| assign cmd %prec Tbang { $$ = hangchild1($1, $2, 2); } -| Tbang cmd { $$ = maketree1(Tbang, $2); } -| Tsubshell cmd { $$ = maketree1(Tsubshell, $2); } -| Tif paren nl ifbody { $$ = hangchild1($2, $1, 0); } +/* empty */ %prec Twhile { $$ = nil; } +| basic { $$ = maketree1(Tbasic, $1); } +| block epilog { $$ = hangepilog($1, $2); } +| cmd Tpipe nl cmd { $$ = hangchild2($2, $1, 0, $4, 1); } +| cmd Tandand nl cmd { $$ = maketree2(Tandand, $1, $4); } +| cmd Toror nl cmd { $$ = maketree2(Toror, $1, $4); } +| redir cmd %prec Tbang { $$ = hangchild1($1, $2, 1); } +| assign cmd %prec Tbang { $$ = hangchild1($1, $2, 2); } +| Tbang cmd { $$ = maketree1(Tbang, $2); } +| Tsubshell cmd { $$ = maketree1(Tsubshell, $2); } +| Tfor '(' word ')' nl cmd { $$ = hangchild3($1, $3, nil, $6); } +| Tfor '(' word Tin words ')' nl cmd { $$ = hangchild3($1, $3, $5, $8); } +| Twhile paren nl cmd { $$ = hangchild2($1, $2, 0, $4, 1); } +| Tif paren nl ifbody { $$ = hangchild1($2, $1, 0); } +| Tswitch '(' word ')' nl '{' casebody '}' { $$ = hangchild2($1, $3, 0, $7, 1); } basic: executable @@ -113,11 +126,10 @@ nonkeyword: | Tcount atom { $$ = maketree1(Tcount, $2); } | Tjoin atom { $$ = maketree1(Tjoin, $2); } | '`' block { $$ = maketree1('`', $2); } -//| '(' words ')' { $$ = maketree1(Tparen, $2); } //| Tredir block { $$ = hangchild1($1, $2, 0); $$->type = Tpipefd; } keyword: - Tin|Tfor|Twhile|Tif|Telse|Tswitch|Tbang|Tsubshell|Tfunc + Tin|Tfor|Twhile|Tif|Telse|Tswitch|Tcase|Tbang|Tsubshell|Tfunc words: /* empty */ { $$ = nil; } @@ -131,4 +143,5 @@ wordsnl: nl: /*empty*/ | nl '\n' + %% diff --git a/sys/cmd/rc/tree.c b/sys/cmd/rc/tree.c index 0f7378f..2c65041 100644 --- a/sys/cmd/rc/tree.c +++ b/sys/cmd/rc/tree.c @@ -68,6 +68,16 @@ hangchild2(Tree *node, Tree *c1, int i1, Tree *c2, int i2) return node; } +Tree* +hangchild3(Tree *node, Tree *c0, Tree *c1, Tree *c2) +{ + node->child[0] = c0; + node->child[1] = c1; + node->child[2] = c2; + + return node; +} + Tree* hangepilog(Tree *cmd, Tree *epi) { -- cgit v1.2.1