diff options
Diffstat (limited to 'awkgram.c')
-rw-r--r-- | awkgram.c | 1588 |
1 files changed, 917 insertions, 671 deletions
@@ -96,11 +96,15 @@ static int isnoeffect(OPCODE type); static INSTRUCTION *make_assignable(INSTRUCTION *ip); static void dumpintlstr(const char *str, size_t len); static void dumpintlstr2(const char *str1, size_t len1, const char *str2, size_t len2); -static int include_source(INSTRUCTION *file); -static int load_library(INSTRUCTION *file); +static bool include_source(INSTRUCTION *file, void **srcfile_p); +static bool load_library(INSTRUCTION *file, void **srcfile_p); static void next_sourcefile(void); static char *tokexpand(void); static NODE *set_profile_text(NODE *n, const char *str, size_t len); +static INSTRUCTION *trailing_comment; +static INSTRUCTION *outer_comment; +static INSTRUCTION *interblock_comment; +static INSTRUCTION *pending_comment; #define instruction(t) bcalloc(t, 1, 0) @@ -127,8 +131,8 @@ static void check_funcs(void); static ssize_t read_one_line(int fd, void *buffer, size_t count); static int one_line_close(int fd); -static void split_comment(void); -static void check_comment(void); +static void merge_comments(INSTRUCTION *c1, INSTRUCTION *c2); +static INSTRUCTION *make_braced_statements(INSTRUCTION *lbrace, INSTRUCTION *stmts, INSTRUCTION *rbrace); static void add_sign_to_num(NODE *n, char sign); static bool at_seen = false; @@ -195,27 +199,19 @@ static INSTRUCTION *ip_endfile; static INSTRUCTION *ip_beginfile; INSTRUCTION *main_beginfile; -static INSTRUCTION *comment = NULL; -static INSTRUCTION *prior_comment = NULL; -static INSTRUCTION *comment_to_save = NULL; -static INSTRUCTION *program_comment = NULL; -static INSTRUCTION *function_comment = NULL; -static INSTRUCTION *block_comment = NULL; - -static bool func_first = true; +static bool func_first = true; // can nuke static bool first_rule = true; static inline INSTRUCTION *list_create(INSTRUCTION *x); static inline INSTRUCTION *list_append(INSTRUCTION *l, INSTRUCTION *x); static inline INSTRUCTION *list_prepend(INSTRUCTION *l, INSTRUCTION *x); static inline INSTRUCTION *list_merge(INSTRUCTION *l1, INSTRUCTION *l2); -static inline INSTRUCTION *add_pending_comment(INSTRUCTION *stmt); extern double fmod(double x, double y); #define YYSTYPE INSTRUCTION * -#line 219 "awkgram.c" /* yacc.c:338 */ +#line 215 "awkgram.c" /* yacc.c:338 */ # ifndef YY_NULLPTR # if defined __cplusplus # if 201103L <= __cplusplus @@ -665,27 +661,27 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 215, 215, 217, 222, 223, 227, 239, 244, 255, - 262, 268, 277, 285, 287, 292, 300, 302, 308, 316, - 326, 356, 370, 384, 392, 403, 415, 417, 419, 425, - 433, 434, 438, 438, 484, 483, 517, 532, 534, 539, - 549, 596, 601, 602, 606, 608, 610, 617, 707, 749, - 791, 904, 911, 918, 929, 939, 949, 959, 971, 988, - 987, 1001, 1013, 1013, 1112, 1112, 1146, 1177, 1186, 1187, - 1193, 1194, 1201, 1206, 1218, 1232, 1234, 1242, 1249, 1251, - 1259, 1268, 1270, 1279, 1280, 1288, 1293, 1293, 1306, 1310, - 1318, 1319, 1322, 1324, 1329, 1330, 1339, 1340, 1345, 1350, - 1359, 1361, 1363, 1370, 1371, 1377, 1378, 1383, 1385, 1390, - 1392, 1400, 1405, 1414, 1415, 1420, 1422, 1427, 1429, 1437, - 1442, 1450, 1451, 1456, 1463, 1467, 1469, 1471, 1484, 1501, - 1511, 1518, 1520, 1525, 1527, 1529, 1537, 1539, 1544, 1546, - 1551, 1553, 1555, 1612, 1614, 1616, 1618, 1620, 1622, 1624, - 1626, 1640, 1645, 1650, 1675, 1681, 1683, 1685, 1687, 1689, - 1691, 1696, 1700, 1732, 1740, 1746, 1752, 1765, 1766, 1767, - 1772, 1777, 1781, 1785, 1800, 1821, 1826, 1863, 1892, 1893, - 1899, 1900, 1905, 1907, 1914, 1931, 1948, 1950, 1957, 1962, - 1970, 1980, 1992, 2001, 2005, 2009, 2013, 2017, 2021, 2024, - 2026, 2030, 2034, 2038 + 0, 213, 213, 214, 219, 229, 233, 245, 254, 268, + 279, 289, 302, 312, 314, 319, 329, 331, 337, 341, + 346, 376, 389, 402, 409, 419, 437, 439, 441, 447, + 455, 456, 460, 460, 494, 493, 527, 542, 544, 549, + 550, 570, 575, 576, 580, 591, 596, 603, 711, 762, + 812, 938, 959, 980, 990, 1000, 1010, 1021, 1034, 1052, + 1051, 1065, 1083, 1083, 1181, 1181, 1214, 1244, 1252, 1253, + 1259, 1260, 1267, 1272, 1285, 1300, 1302, 1310, 1317, 1319, + 1327, 1336, 1338, 1347, 1348, 1356, 1361, 1361, 1374, 1380, + 1392, 1396, 1418, 1419, 1425, 1426, 1435, 1436, 1441, 1446, + 1463, 1465, 1467, 1474, 1475, 1481, 1482, 1487, 1489, 1496, + 1498, 1506, 1511, 1522, 1523, 1528, 1530, 1537, 1539, 1547, + 1552, 1562, 1563, 1568, 1575, 1579, 1581, 1583, 1596, 1613, + 1623, 1630, 1632, 1637, 1639, 1641, 1649, 1651, 1656, 1658, + 1663, 1665, 1667, 1724, 1726, 1728, 1730, 1732, 1734, 1736, + 1738, 1752, 1757, 1762, 1787, 1793, 1795, 1797, 1799, 1801, + 1803, 1808, 1812, 1844, 1852, 1858, 1864, 1877, 1878, 1879, + 1884, 1889, 1893, 1897, 1912, 1933, 1938, 1975, 2004, 2005, + 2011, 2012, 2017, 2019, 2026, 2043, 2060, 2062, 2069, 2074, + 2082, 2092, 2104, 2113, 2117, 2122, 2126, 2130, 2134, 2139, + 2140, 2144, 2148, 2152 }; #endif @@ -1882,25 +1878,45 @@ yyreduce: YY_REDUCE_PRINT (yyn); switch (yyn) { - case 3: -#line 218 "awkgram.y" /* yacc.c:1645 */ + case 2: +#line 213 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = NULL; } +#line 1885 "awkgram.c" /* yacc.c:1645 */ + break; + + case 3: +#line 215 "awkgram.y" /* yacc.c:1645 */ { rule = 0; yyerrok; } -#line 1892 "awkgram.c" /* yacc.c:1645 */ +#line 1894 "awkgram.c" /* yacc.c:1645 */ + break; + + case 4: +#line 220 "awkgram.y" /* yacc.c:1645 */ + { + if ((yyvsp[0]) != NULL) { + if ((yyvsp[-1]) == NULL) + outer_comment = (yyvsp[0]); + else + interblock_comment = (yyvsp[0]); + } + (yyval) = (yyvsp[-1]); + } +#line 1908 "awkgram.c" /* yacc.c:1645 */ break; case 5: -#line 224 "awkgram.y" /* yacc.c:1645 */ +#line 230 "awkgram.y" /* yacc.c:1645 */ { next_sourcefile(); } -#line 1900 "awkgram.c" /* yacc.c:1645 */ +#line 1916 "awkgram.c" /* yacc.c:1645 */ break; case 6: -#line 228 "awkgram.y" /* yacc.c:1645 */ +#line 234 "awkgram.y" /* yacc.c:1645 */ { rule = 0; /* @@ -1909,20 +1925,24 @@ yyreduce: */ /* yyerrok; */ } -#line 1913 "awkgram.c" /* yacc.c:1645 */ +#line 1929 "awkgram.c" /* yacc.c:1645 */ break; case 7: -#line 240 "awkgram.y" /* yacc.c:1645 */ +#line 246 "awkgram.y" /* yacc.c:1645 */ { (void) append_rule((yyvsp[-1]), (yyvsp[0])); + if (pending_comment != NULL) { + interblock_comment = pending_comment; + pending_comment = NULL; + } first_rule = false; } -#line 1922 "awkgram.c" /* yacc.c:1645 */ +#line 1942 "awkgram.c" /* yacc.c:1645 */ break; case 8: -#line 245 "awkgram.y" /* yacc.c:1645 */ +#line 255 "awkgram.y" /* yacc.c:1645 */ { if (rule != Rule) { msg(_("%s blocks must have an action part"), ruletab[rule]); @@ -1930,119 +1950,129 @@ yyreduce: } else if ((yyvsp[-1]) == NULL) { msg(_("each rule must have a pattern or an action part")); errcount++; - } else /* pattern rule with non-empty pattern */ + } else { /* pattern rule with non-empty pattern */ + if ((yyvsp[0]) != NULL) + list_append((yyvsp[-1]), (yyvsp[0])); (void) append_rule((yyvsp[-1]), NULL); + } } -#line 1937 "awkgram.c" /* yacc.c:1645 */ +#line 1960 "awkgram.c" /* yacc.c:1645 */ break; case 9: -#line 256 "awkgram.y" /* yacc.c:1645 */ +#line 269 "awkgram.y" /* yacc.c:1645 */ { in_function = NULL; (void) mk_function((yyvsp[-1]), (yyvsp[0])); want_param_names = DONT_CHECK; + if (pending_comment != NULL) { + interblock_comment = pending_comment; + pending_comment = NULL; + } yyerrok; } -#line 1948 "awkgram.c" /* yacc.c:1645 */ +#line 1975 "awkgram.c" /* yacc.c:1645 */ break; case 10: -#line 263 "awkgram.y" /* yacc.c:1645 */ +#line 280 "awkgram.y" /* yacc.c:1645 */ { want_source = false; at_seen = false; + if ((yyvsp[-1]) != NULL && (yyvsp[0]) != NULL) { + SRCFILE *s = (SRCFILE *) (yyvsp[-1]); + s->comment = (yyvsp[0]); + } yyerrok; } -#line 1958 "awkgram.c" /* yacc.c:1645 */ +#line 1989 "awkgram.c" /* yacc.c:1645 */ break; case 11: -#line 269 "awkgram.y" /* yacc.c:1645 */ +#line 290 "awkgram.y" /* yacc.c:1645 */ { want_source = false; at_seen = false; + if ((yyvsp[-1]) != NULL && (yyvsp[0]) != NULL) { + SRCFILE *s = (SRCFILE *) (yyvsp[-1]); + s->comment = (yyvsp[0]); + } yyerrok; } -#line 1968 "awkgram.c" /* yacc.c:1645 */ +#line 2003 "awkgram.c" /* yacc.c:1645 */ break; case 12: -#line 278 "awkgram.y" /* yacc.c:1645 */ +#line 303 "awkgram.y" /* yacc.c:1645 */ { - if (include_source((yyvsp[0])) < 0) + void *srcfile = NULL; + + if (! include_source((yyvsp[0]), & srcfile)) YYABORT; efree((yyvsp[0])->lextok); bcfree((yyvsp[0])); - (yyval) = NULL; + (yyval) = (INSTRUCTION *) srcfile; } -#line 1980 "awkgram.c" /* yacc.c:1645 */ +#line 2017 "awkgram.c" /* yacc.c:1645 */ break; case 13: -#line 286 "awkgram.y" /* yacc.c:1645 */ +#line 313 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 1986 "awkgram.c" /* yacc.c:1645 */ +#line 2023 "awkgram.c" /* yacc.c:1645 */ break; case 14: -#line 288 "awkgram.y" /* yacc.c:1645 */ +#line 315 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 1992 "awkgram.c" /* yacc.c:1645 */ +#line 2029 "awkgram.c" /* yacc.c:1645 */ break; case 15: -#line 293 "awkgram.y" /* yacc.c:1645 */ +#line 320 "awkgram.y" /* yacc.c:1645 */ { - if (load_library((yyvsp[0])) < 0) + void *srcfile; + + if (! load_library((yyvsp[0]), & srcfile)) YYABORT; efree((yyvsp[0])->lextok); bcfree((yyvsp[0])); - (yyval) = NULL; + (yyval) = (INSTRUCTION *) srcfile; } -#line 2004 "awkgram.c" /* yacc.c:1645 */ +#line 2043 "awkgram.c" /* yacc.c:1645 */ break; case 16: -#line 301 "awkgram.y" /* yacc.c:1645 */ +#line 330 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 2010 "awkgram.c" /* yacc.c:1645 */ +#line 2049 "awkgram.c" /* yacc.c:1645 */ break; case 17: -#line 303 "awkgram.y" /* yacc.c:1645 */ +#line 332 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 2016 "awkgram.c" /* yacc.c:1645 */ +#line 2055 "awkgram.c" /* yacc.c:1645 */ break; case 18: -#line 308 "awkgram.y" /* yacc.c:1645 */ +#line 337 "awkgram.y" /* yacc.c:1645 */ { rule = Rule; - if (comment != NULL) { - (yyval) = list_create(comment); - comment = NULL; - } else - (yyval) = NULL; + (yyval) = NULL; } -#line 2029 "awkgram.c" /* yacc.c:1645 */ +#line 2064 "awkgram.c" /* yacc.c:1645 */ break; case 19: -#line 317 "awkgram.y" /* yacc.c:1645 */ +#line 342 "awkgram.y" /* yacc.c:1645 */ { rule = Rule; - if (comment != NULL) { - (yyval) = list_prepend((yyvsp[0]), comment); - comment = NULL; - } else - (yyval) = (yyvsp[0]); } -#line 2042 "awkgram.c" /* yacc.c:1645 */ +#line 2072 "awkgram.c" /* yacc.c:1645 */ break; case 20: -#line 327 "awkgram.y" /* yacc.c:1645 */ +#line 347 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *tp; @@ -2065,18 +2095,18 @@ yyreduce: ((yyvsp[-3])->nexti + 1)->condpair_left = (yyvsp[-3])->lasti; ((yyvsp[-3])->nexti + 1)->condpair_right = (yyvsp[0])->lasti; } - if (comment != NULL) { - (yyval) = list_append(list_merge(list_prepend((yyvsp[-3]), comment), (yyvsp[0])), tp); - comment = NULL; - } else + /* Put any comments in front of the range expression */ + if ((yyvsp[-1]) != NULL) + (yyval) = list_append(list_merge(list_prepend((yyvsp[-3]), (yyvsp[-1])), (yyvsp[0])), tp); + else (yyval) = list_append(list_merge((yyvsp[-3]), (yyvsp[0])), tp); rule = Rule; } -#line 2076 "awkgram.c" /* yacc.c:1645 */ +#line 2106 "awkgram.c" /* yacc.c:1645 */ break; case 21: -#line 357 "awkgram.y" /* yacc.c:1645 */ +#line 377 "awkgram.y" /* yacc.c:1645 */ { static int begin_seen = 0; @@ -2087,14 +2117,13 @@ yyreduce: (yyvsp[0])->in_rule = rule = BEGIN; (yyvsp[0])->source_file = source; - check_comment(); (yyval) = (yyvsp[0]); } -#line 2094 "awkgram.c" /* yacc.c:1645 */ +#line 2123 "awkgram.c" /* yacc.c:1645 */ break; case 22: -#line 371 "awkgram.y" /* yacc.c:1645 */ +#line 390 "awkgram.y" /* yacc.c:1645 */ { static int end_seen = 0; @@ -2105,116 +2134,107 @@ yyreduce: (yyvsp[0])->in_rule = rule = END; (yyvsp[0])->source_file = source; - check_comment(); (yyval) = (yyvsp[0]); } -#line 2112 "awkgram.c" /* yacc.c:1645 */ +#line 2140 "awkgram.c" /* yacc.c:1645 */ break; case 23: -#line 385 "awkgram.y" /* yacc.c:1645 */ +#line 403 "awkgram.y" /* yacc.c:1645 */ { func_first = false; (yyvsp[0])->in_rule = rule = BEGINFILE; (yyvsp[0])->source_file = source; - check_comment(); (yyval) = (yyvsp[0]); } -#line 2124 "awkgram.c" /* yacc.c:1645 */ +#line 2151 "awkgram.c" /* yacc.c:1645 */ break; case 24: -#line 393 "awkgram.y" /* yacc.c:1645 */ +#line 410 "awkgram.y" /* yacc.c:1645 */ { func_first = false; (yyvsp[0])->in_rule = rule = ENDFILE; (yyvsp[0])->source_file = source; - check_comment(); (yyval) = (yyvsp[0]); } -#line 2136 "awkgram.c" /* yacc.c:1645 */ +#line 2162 "awkgram.c" /* yacc.c:1645 */ break; case 25: -#line 404 "awkgram.y" /* yacc.c:1645 */ +#line 420 "awkgram.y" /* yacc.c:1645 */ { - INSTRUCTION *ip; - if ((yyvsp[-3]) == NULL) - ip = list_create(instruction(Op_no_op)); - else - ip = (yyvsp[-3]); + INSTRUCTION *ip = make_braced_statements((yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2])); + + if ((yyvsp[-2]) != NULL && (yyvsp[0]) != NULL) { + merge_comments((yyvsp[-2]), (yyvsp[0])); + pending_comment = (yyvsp[-2]); + } else if ((yyvsp[-2]) != NULL) { + pending_comment = (yyvsp[-2]); + } else if ((yyvsp[0]) != NULL) { + pending_comment = (yyvsp[0]); + } + (yyval) = ip; } -#line 2149 "awkgram.c" /* yacc.c:1645 */ +#line 2181 "awkgram.c" /* yacc.c:1645 */ break; case 26: -#line 416 "awkgram.y" /* yacc.c:1645 */ +#line 438 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 2155 "awkgram.c" /* yacc.c:1645 */ +#line 2187 "awkgram.c" /* yacc.c:1645 */ break; case 27: -#line 418 "awkgram.y" /* yacc.c:1645 */ +#line 440 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 2161 "awkgram.c" /* yacc.c:1645 */ +#line 2193 "awkgram.c" /* yacc.c:1645 */ break; case 28: -#line 420 "awkgram.y" /* yacc.c:1645 */ +#line 442 "awkgram.y" /* yacc.c:1645 */ { yyerror(_("`%s' is a built-in function, it cannot be redefined"), tokstart); YYABORT; } -#line 2171 "awkgram.c" /* yacc.c:1645 */ +#line 2203 "awkgram.c" /* yacc.c:1645 */ break; case 29: -#line 426 "awkgram.y" /* yacc.c:1645 */ +#line 448 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); at_seen = false; } -#line 2180 "awkgram.c" /* yacc.c:1645 */ +#line 2212 "awkgram.c" /* yacc.c:1645 */ break; case 32: -#line 438 "awkgram.y" /* yacc.c:1645 */ +#line 460 "awkgram.y" /* yacc.c:1645 */ { want_param_names = FUNC_HEADER; } -#line 2186 "awkgram.c" /* yacc.c:1645 */ +#line 2218 "awkgram.c" /* yacc.c:1645 */ break; case 33: -#line 439 "awkgram.y" /* yacc.c:1645 */ +#line 461 "awkgram.y" /* yacc.c:1645 */ { - /* - * treat any comments between BOF and the first function - * definition (with no intervening BEGIN etc block) as - * program comments. Special kludge: iff there are more - * than one such comments, treat the last as a function - * comment. - */ - if (prior_comment != NULL) { - comment_to_save = prior_comment; - prior_comment = NULL; - } else if (comment != NULL) { - comment_to_save = comment; - comment = NULL; - } else - comment_to_save = NULL; - - if (comment_to_save != NULL && func_first - && strstr(comment_to_save->memory->stptr, "\n\n") != NULL) - split_comment(); - - /* save any other pre-function comment as function comment */ - if (comment_to_save != NULL) { - function_comment = comment_to_save; - comment_to_save = NULL; + INSTRUCTION *func_comment = NULL; + // Merge any comments found in the parameter list with those + // following the function header, associate the whole shebang + // with the function as one block comment. + if ((yyvsp[-2]) != NULL && (yyvsp[-2])->comment != NULL) { + if ((yyvsp[0]) != NULL) { + merge_comments((yyvsp[-2])->comment, (yyvsp[0])); + } + func_comment = (yyvsp[-2])->comment; + } else if ((yyvsp[0]) != NULL) { + func_comment = (yyvsp[0]); } - func_first = false; + (yyvsp[-6])->source_file = source; + (yyvsp[-6])->comment = func_comment; if (install_function((yyvsp[-5])->lextok, (yyvsp[-6]), (yyvsp[-2])) < 0) YYABORT; in_function = (yyvsp[-5])->lextok; @@ -2224,17 +2244,17 @@ yyreduce: (yyval) = (yyvsp[-6]); want_param_names = FUNC_BODY; } -#line 2228 "awkgram.c" /* yacc.c:1645 */ +#line 2248 "awkgram.c" /* yacc.c:1645 */ break; case 34: -#line 484 "awkgram.y" /* yacc.c:1645 */ +#line 494 "awkgram.y" /* yacc.c:1645 */ { want_regexp = true; } -#line 2234 "awkgram.c" /* yacc.c:1645 */ +#line 2254 "awkgram.c" /* yacc.c:1645 */ break; case 35: -#line 486 "awkgram.y" /* yacc.c:1645 */ +#line 496 "awkgram.y" /* yacc.c:1645 */ { NODE *n, *exp; char *re; @@ -2263,11 +2283,11 @@ yyreduce: (yyval)->opcode = Op_match_rec; (yyval)->memory = n; } -#line 2267 "awkgram.c" /* yacc.c:1645 */ +#line 2287 "awkgram.c" /* yacc.c:1645 */ break; case 36: -#line 518 "awkgram.y" /* yacc.c:1645 */ +#line 528 "awkgram.y" /* yacc.c:1645 */ { char *re; size_t len; @@ -2280,112 +2300,100 @@ yyreduce: (yyval)->opcode = Op_push_re; (yyval)->memory = make_typed_regex(re, len); } -#line 2284 "awkgram.c" /* yacc.c:1645 */ +#line 2304 "awkgram.c" /* yacc.c:1645 */ break; case 37: -#line 533 "awkgram.y" /* yacc.c:1645 */ +#line 543 "awkgram.y" /* yacc.c:1645 */ { bcfree((yyvsp[0])); } -#line 2290 "awkgram.c" /* yacc.c:1645 */ +#line 2310 "awkgram.c" /* yacc.c:1645 */ break; case 39: -#line 539 "awkgram.y" /* yacc.c:1645 */ - { - if (prior_comment != NULL) { - (yyval) = list_create(prior_comment); - prior_comment = NULL; - } else if (comment != NULL) { - (yyval) = list_create(comment); - comment = NULL; - } else - (yyval) = NULL; - } -#line 2305 "awkgram.c" /* yacc.c:1645 */ +#line 549 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = NULL; } +#line 2316 "awkgram.c" /* yacc.c:1645 */ break; case 40: -#line 550 "awkgram.y" /* yacc.c:1645 */ +#line 551 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[0]) == NULL) { - if (prior_comment != NULL) { - (yyval) = list_append((yyvsp[-1]), prior_comment); - prior_comment = NULL; - if (comment != NULL) { - (yyval) = list_append((yyval), comment); - comment = NULL; - } - } else if (comment != NULL) { - (yyval) = list_append((yyvsp[-1]), comment); - comment = NULL; - } else - (yyval) = (yyvsp[-1]); + (yyval) = (yyvsp[-1]); } else { add_lint((yyvsp[0]), LINT_no_effect); if ((yyvsp[-1]) == NULL) { - if (prior_comment != NULL) { - (yyval) = list_append((yyvsp[0]), prior_comment); - prior_comment = NULL; - if (comment != NULL) { - (yyval) = list_append((yyval), comment); - comment = NULL; - } - } else if (comment != NULL) { - (yyval) = list_append((yyvsp[0]), comment); - comment = NULL; - } else - (yyval) = (yyvsp[0]); + (yyval) = (yyvsp[0]); } else { - if (prior_comment != NULL) { - list_append((yyvsp[0]), prior_comment); - prior_comment = NULL; - if (comment != NULL) { - list_append((yyvsp[0]), comment); - comment = NULL; - } - } else if (comment != NULL) { - list_append((yyvsp[0]), comment); - comment = NULL; - } (yyval) = list_merge((yyvsp[-1]), (yyvsp[0])); } } + + if (trailing_comment != NULL) { + (yyval) = list_append((yyval), trailing_comment); + trailing_comment = NULL; + } + yyerrok; } -#line 2356 "awkgram.c" /* yacc.c:1645 */ +#line 2340 "awkgram.c" /* yacc.c:1645 */ break; case 41: -#line 597 "awkgram.y" /* yacc.c:1645 */ +#line 571 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 2362 "awkgram.c" /* yacc.c:1645 */ +#line 2346 "awkgram.c" /* yacc.c:1645 */ + break; + + case 42: +#line 575 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = (yyvsp[0]); } +#line 2352 "awkgram.c" /* yacc.c:1645 */ + break; + + case 43: +#line 576 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = (yyvsp[0]); } +#line 2358 "awkgram.c" /* yacc.c:1645 */ break; case 44: -#line 607 "awkgram.y" /* yacc.c:1645 */ - { (yyval) = NULL; } -#line 2368 "awkgram.c" /* yacc.c:1645 */ +#line 581 "awkgram.y" /* yacc.c:1645 */ + { + if ((yyvsp[0]) != NULL) { + INSTRUCTION *ip; + + merge_comments((yyvsp[0]), NULL); + ip = list_create(instruction(Op_no_op)); + (yyval) = list_append(ip, (yyvsp[0])); + } else + (yyval) = NULL; + } +#line 2373 "awkgram.c" /* yacc.c:1645 */ break; case 45: -#line 609 "awkgram.y" /* yacc.c:1645 */ - { (yyval) = (yyvsp[-1]); } -#line 2374 "awkgram.c" /* yacc.c:1645 */ +#line 592 "awkgram.y" /* yacc.c:1645 */ + { + trailing_comment = (yyvsp[0]); // NULL or comment + (yyval) = make_braced_statements((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])); + } +#line 2382 "awkgram.c" /* yacc.c:1645 */ break; case 46: -#line 611 "awkgram.y" /* yacc.c:1645 */ +#line 597 "awkgram.y" /* yacc.c:1645 */ { if (do_pretty_print) (yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count)); else (yyval) = (yyvsp[0]); } -#line 2385 "awkgram.c" /* yacc.c:1645 */ +#line 2393 "awkgram.c" /* yacc.c:1645 */ break; case 47: -#line 618 "awkgram.y" /* yacc.c:1645 */ +#line 604 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *dflt, *curr = NULL, *cexp, *cstmt; INSTRUCTION *ip, *nextc, *tbreak; @@ -2403,8 +2411,9 @@ yyreduce: if ((yyvsp[-2]) != NULL) { curr = (yyvsp[-2])->nexti; bcfree((yyvsp[-2])); /* Op_list */ - } /* else - curr = NULL; */ + } + /* else + curr = NULL; */ for (; curr != NULL; curr = nextc) { INSTRUCTION *caseexp = curr->case_exp; @@ -2460,26 +2469,43 @@ yyreduce: ip = (yyvsp[-6]); if (do_pretty_print) { + // first merge comments + INSTRUCTION *head_comment = NULL; + + if ((yyvsp[-4]) != NULL && (yyvsp[-3]) != NULL) { + merge_comments((yyvsp[-4]), (yyvsp[-3])); + head_comment = (yyvsp[-4]); + } else if ((yyvsp[-4]) != NULL) + head_comment = (yyvsp[-4]); + else + head_comment = (yyvsp[-3]); + + (yyvsp[-8])->comment = head_comment; + (void) list_prepend(ip, (yyvsp[-8])); (void) list_prepend(ip, instruction(Op_exec_count)); (yyvsp[-8])->target_break = tbreak; ((yyvsp[-8]) + 1)->switch_start = cexp->nexti; ((yyvsp[-8]) + 1)->switch_end = cexp->lasti; - }/* else - $1 is NULL */ + ((yyvsp[-8]) + 1)->switch_end->comment = (yyvsp[0]); + } + /* else + $1 is NULL */ (void) list_append(cexp, dflt); (void) list_merge(ip, cexp); + if ((yyvsp[-1]) != NULL) + (void) list_append(cstmt, (yyvsp[-1])); (yyval) = list_merge(ip, cstmt); break_allowed--; fix_break_continue(ip, tbreak, NULL); } -#line 2479 "awkgram.c" /* yacc.c:1645 */ +#line 2505 "awkgram.c" /* yacc.c:1645 */ break; case 48: -#line 708 "awkgram.y" /* yacc.c:1645 */ +#line 712 "awkgram.y" /* yacc.c:1645 */ { /* * ----------------- @@ -2508,8 +2534,17 @@ yyreduce: (yyvsp[-5])->target_continue = tcont; ((yyvsp[-5]) + 1)->while_body = ip->lasti; (void) list_prepend(ip, (yyvsp[-5])); - }/* else - $1 is NULL */ + } + /* else + $1 is NULL */ + + if ((yyvsp[-1]) != NULL) { + if ((yyvsp[0]) == NULL) + (yyvsp[0]) = list_create(instruction(Op_no_op)); + + (yyvsp[-1])->memory->comment_type = BLOCK_COMMENT; + (yyvsp[0]) = list_prepend((yyvsp[0]), (yyvsp[-1])); + } if ((yyvsp[0]) != NULL) (void) list_merge(ip, (yyvsp[0])); @@ -2521,11 +2556,11 @@ yyreduce: continue_allowed--; fix_break_continue(ip, tbreak, tcont); } -#line 2525 "awkgram.c" /* yacc.c:1645 */ +#line 2560 "awkgram.c" /* yacc.c:1645 */ break; case 49: -#line 750 "awkgram.y" /* yacc.c:1645 */ +#line 763 "awkgram.y" /* yacc.c:1645 */ { /* * ----------------- @@ -2548,8 +2583,13 @@ yyreduce: ip = list_merge((yyvsp[-5]), (yyvsp[-2])); else ip = list_prepend((yyvsp[-2]), instruction(Op_no_op)); + + if ((yyvsp[-6]) != NULL) + (void) list_prepend(ip, (yyvsp[-6])); + if (do_pretty_print) (void) list_prepend(ip, instruction(Op_exec_count)); + (void) list_append(ip, instruction(Op_jmp_true)); ip->lasti->target_jmp = ip->nexti; (yyval) = list_append(ip, tbreak); @@ -2564,14 +2604,17 @@ yyreduce: ((yyvsp[-7]) + 1)->doloop_cond = tcont; (yyval) = list_prepend(ip, (yyvsp[-7])); bcfree((yyvsp[-4])); - } /* else + if ((yyvsp[0]) != NULL) + (yyvsp[-7])->comment = (yyvsp[0]); + } + /* else $1 and $4 are NULLs */ } -#line 2571 "awkgram.c" /* yacc.c:1645 */ +#line 2614 "awkgram.c" /* yacc.c:1645 */ break; case 50: -#line 792 "awkgram.y" /* yacc.c:1645 */ +#line 813 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *ip; char *var_name = (yyvsp[-5])->lextok; @@ -2584,7 +2627,8 @@ yyreduce: && strcmp((yyvsp[0])->nexti->memory->vname, var_name) == 0 ) { - /* Efficiency hack. Recognize the special case of + /* + * Efficiency hack. Recognize the special case of * * for (iggy in foo) * delete foo[iggy] @@ -2616,6 +2660,10 @@ yyreduce: bcfree((yyvsp[-5])); bcfree((yyvsp[-4])); bcfree((yyvsp[-3])); + if ((yyvsp[-1]) != NULL) { + merge_comments((yyvsp[-1]), NULL); + (yyvsp[0]) = list_prepend((yyvsp[0]), (yyvsp[-1])); + } (yyval) = (yyvsp[0]); } else goto regular_loop; @@ -2650,8 +2698,9 @@ regular_loop: (yyvsp[-7])->target_continue = tcont; (yyvsp[-7])->target_break = tbreak; (void) list_append(ip, (yyvsp[-7])); - } /* else - $1 is NULL */ + } + /* else + $1 is NULL */ /* add update_FOO instruction if necessary */ if ((yyvsp[-4])->array_var->type == Node_var && (yyvsp[-4])->array_var->var_update) { @@ -2672,8 +2721,15 @@ regular_loop: ((yyvsp[-7]) + 1)->forloop_body = ip->lasti; } - if ((yyvsp[0]) != NULL) + if ((yyvsp[-1]) != NULL) + merge_comments((yyvsp[-1]), NULL); + + if ((yyvsp[0]) != NULL) { + if ((yyvsp[-1]) != NULL) + (yyvsp[0]) = list_prepend((yyvsp[0]), (yyvsp[-1])); (void) list_merge(ip, (yyvsp[0])); + } else if ((yyvsp[-1]) != NULL) + (void) list_append(ip, (yyvsp[-1])); (void) list_append(ip, instruction(Op_jmp)); ip->lasti->target_jmp = (yyvsp[-4]); @@ -2684,73 +2740,100 @@ regular_loop: break_allowed--; continue_allowed--; } -#line 2688 "awkgram.c" /* yacc.c:1645 */ +#line 2744 "awkgram.c" /* yacc.c:1645 */ break; case 51: -#line 905 "awkgram.y" /* yacc.c:1645 */ +#line 939 "awkgram.y" /* yacc.c:1645 */ { + if ((yyvsp[-7]) != NULL) { + merge_comments((yyvsp[-7]), NULL); + (yyvsp[-11])->comment = (yyvsp[-7]); + } + if ((yyvsp[-4]) != NULL) { + merge_comments((yyvsp[-4]), NULL); + if ((yyvsp[-11])->comment == NULL) { + (yyvsp[-4])->memory->comment_type = FOR_COMMENT; + (yyvsp[-11])->comment = (yyvsp[-4]); + } else + (yyvsp[-11])->comment->comment = (yyvsp[-4]); + } + if ((yyvsp[-1]) != NULL) + (yyvsp[0]) = list_prepend((yyvsp[0]), (yyvsp[-1])); (yyval) = mk_for_loop((yyvsp[-11]), (yyvsp[-9]), (yyvsp[-6]), (yyvsp[-3]), (yyvsp[0])); break_allowed--; continue_allowed--; } -#line 2699 "awkgram.c" /* yacc.c:1645 */ +#line 2769 "awkgram.c" /* yacc.c:1645 */ break; case 52: -#line 912 "awkgram.y" /* yacc.c:1645 */ +#line 960 "awkgram.y" /* yacc.c:1645 */ { + if ((yyvsp[-6]) != NULL) { + merge_comments((yyvsp[-6]), NULL); + (yyvsp[-10])->comment = (yyvsp[-6]); + } + if ((yyvsp[-4]) != NULL) { + merge_comments((yyvsp[-4]), NULL); + if ((yyvsp[-10])->comment == NULL) { + (yyvsp[-4])->memory->comment_type = FOR_COMMENT; + (yyvsp[-10])->comment = (yyvsp[-4]); + } else + (yyvsp[-10])->comment->comment = (yyvsp[-4]); + } + if ((yyvsp[-1]) != NULL) + (yyvsp[0]) = list_prepend((yyvsp[0]), (yyvsp[-1])); (yyval) = mk_for_loop((yyvsp[-10]), (yyvsp[-8]), (INSTRUCTION *) NULL, (yyvsp[-3]), (yyvsp[0])); break_allowed--; continue_allowed--; } -#line 2710 "awkgram.c" /* yacc.c:1645 */ +#line 2794 "awkgram.c" /* yacc.c:1645 */ break; case 53: -#line 919 "awkgram.y" /* yacc.c:1645 */ +#line 981 "awkgram.y" /* yacc.c:1645 */ { if (do_pretty_print) (yyval) = list_prepend((yyvsp[0]), instruction(Op_exec_count)); else (yyval) = (yyvsp[0]); - (yyval) = add_pending_comment((yyval)); } -#line 2722 "awkgram.c" /* yacc.c:1645 */ +#line 2805 "awkgram.c" /* yacc.c:1645 */ break; case 54: -#line 930 "awkgram.y" /* yacc.c:1645 */ +#line 991 "awkgram.y" /* yacc.c:1645 */ { if (! break_allowed) error_ln((yyvsp[-1])->source_line, _("`break' is not allowed outside a loop or switch")); (yyvsp[-1])->target_jmp = NULL; (yyval) = list_create((yyvsp[-1])); - (yyval) = add_pending_comment((yyval)); - + if ((yyvsp[0]) != NULL) + (yyval) = list_append((yyval), (yyvsp[0])); } -#line 2736 "awkgram.c" /* yacc.c:1645 */ +#line 2819 "awkgram.c" /* yacc.c:1645 */ break; case 55: -#line 940 "awkgram.y" /* yacc.c:1645 */ +#line 1001 "awkgram.y" /* yacc.c:1645 */ { if (! continue_allowed) error_ln((yyvsp[-1])->source_line, _("`continue' is not allowed outside a loop")); (yyvsp[-1])->target_jmp = NULL; (yyval) = list_create((yyvsp[-1])); - (yyval) = add_pending_comment((yyval)); - + if ((yyvsp[0]) != NULL) + (yyval) = list_append((yyval), (yyvsp[0])); } -#line 2750 "awkgram.c" /* yacc.c:1645 */ +#line 2833 "awkgram.c" /* yacc.c:1645 */ break; case 56: -#line 950 "awkgram.y" /* yacc.c:1645 */ +#line 1011 "awkgram.y" /* yacc.c:1645 */ { /* if inside function (rule = 0), resolve context at run-time */ if (rule && rule != Rule) @@ -2758,13 +2841,14 @@ regular_loop: _("`next' used in %s action"), ruletab[rule]); (yyvsp[-1])->target_jmp = ip_rec; (yyval) = list_create((yyvsp[-1])); - (yyval) = add_pending_comment((yyval)); + if ((yyvsp[0]) != NULL) + (yyval) = list_append((yyval), (yyvsp[0])); } -#line 2764 "awkgram.c" /* yacc.c:1645 */ +#line 2848 "awkgram.c" /* yacc.c:1645 */ break; case 57: -#line 960 "awkgram.y" /* yacc.c:1645 */ +#line 1022 "awkgram.y" /* yacc.c:1645 */ { /* if inside function (rule = 0), resolve context at run-time */ if (rule == BEGIN || rule == END || rule == ENDFILE) @@ -2774,13 +2858,14 @@ regular_loop: (yyvsp[-1])->target_newfile = ip_newfile; (yyvsp[-1])->target_endfile = ip_endfile; (yyval) = list_create((yyvsp[-1])); - (yyval) = add_pending_comment((yyval)); + if ((yyvsp[0]) != NULL) + (yyval) = list_append((yyval), (yyvsp[0])); } -#line 2780 "awkgram.c" /* yacc.c:1645 */ +#line 2865 "awkgram.c" /* yacc.c:1645 */ break; case 58: -#line 972 "awkgram.y" /* yacc.c:1645 */ +#line 1035 "awkgram.y" /* yacc.c:1645 */ { /* Initialize the two possible jump targets, the actual target * is resolved at run-time. @@ -2794,22 +2879,23 @@ regular_loop: (yyval)->nexti->memory = dupnode(Nnull_string); } else (yyval) = list_append((yyvsp[-1]), (yyvsp[-2])); - (yyval) = add_pending_comment((yyval)); + if ((yyvsp[0]) != NULL) + (yyval) = list_append((yyval), (yyvsp[0])); } -#line 2800 "awkgram.c" /* yacc.c:1645 */ +#line 2886 "awkgram.c" /* yacc.c:1645 */ break; case 59: -#line 988 "awkgram.y" /* yacc.c:1645 */ +#line 1052 "awkgram.y" /* yacc.c:1645 */ { if (! in_function) yyerror(_("`return' used outside function context")); } -#line 2809 "awkgram.c" /* yacc.c:1645 */ +#line 2895 "awkgram.c" /* yacc.c:1645 */ break; case 60: -#line 991 "awkgram.y" /* yacc.c:1645 */ +#line 1055 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[-1]) == NULL) { (yyval) = list_create((yyvsp[-3])); @@ -2817,20 +2903,31 @@ regular_loop: (yyval)->nexti->memory = dupnode(Nnull_string); } else (yyval) = list_append((yyvsp[-1]), (yyvsp[-3])); + if ((yyvsp[0]) != NULL) + (yyval) = list_append((yyval), (yyvsp[0])); + } +#line 2910 "awkgram.c" /* yacc.c:1645 */ + break; - (yyval) = add_pending_comment((yyval)); + case 61: +#line 1066 "awkgram.y" /* yacc.c:1645 */ + { + if ((yyvsp[0]) != NULL) + (yyval) = list_append((yyvsp[-1]), (yyvsp[0])); + else + (yyval) = (yyvsp[-1]); } -#line 2824 "awkgram.c" /* yacc.c:1645 */ +#line 2921 "awkgram.c" /* yacc.c:1645 */ break; case 62: -#line 1013 "awkgram.y" /* yacc.c:1645 */ +#line 1083 "awkgram.y" /* yacc.c:1645 */ { in_print = true; in_parens = 0; } -#line 2830 "awkgram.c" /* yacc.c:1645 */ +#line 2927 "awkgram.c" /* yacc.c:1645 */ break; case 63: -#line 1014 "awkgram.y" /* yacc.c:1645 */ +#line 1084 "awkgram.y" /* yacc.c:1645 */ { /* * Optimization: plain `print' has no expression list, so $3 is null. @@ -2838,7 +2935,7 @@ regular_loop: * which is faster for these two cases. */ - if ((yyvsp[-3])->opcode == Op_K_print && + if (do_optimize && (yyvsp[-3])->opcode == Op_K_print && ((yyvsp[-1]) == NULL || ((yyvsp[-1])->lasti->opcode == Op_field_spec && (yyvsp[-1])->nexti->nexti->nexti == (yyvsp[-1])->lasti @@ -2926,19 +3023,18 @@ regular_print: } } } - (yyval) = add_pending_comment((yyval)); } -#line 2932 "awkgram.c" /* yacc.c:1645 */ +#line 3028 "awkgram.c" /* yacc.c:1645 */ break; case 64: -#line 1112 "awkgram.y" /* yacc.c:1645 */ +#line 1181 "awkgram.y" /* yacc.c:1645 */ { sub_counter = 0; } -#line 2938 "awkgram.c" /* yacc.c:1645 */ +#line 3034 "awkgram.c" /* yacc.c:1645 */ break; case 65: -#line 1113 "awkgram.y" /* yacc.c:1645 */ +#line 1182 "awkgram.y" /* yacc.c:1645 */ { char *arr = (yyvsp[-2])->lextok; @@ -2970,13 +3066,12 @@ regular_print: (yyvsp[-3])->expr_count = sub_counter; (yyval) = list_append(list_append((yyvsp[0]), (yyvsp[-2])), (yyvsp[-3])); } - (yyval) = add_pending_comment((yyval)); } -#line 2976 "awkgram.c" /* yacc.c:1645 */ +#line 3071 "awkgram.c" /* yacc.c:1645 */ break; case 66: -#line 1151 "awkgram.y" /* yacc.c:1645 */ +#line 1219 "awkgram.y" /* yacc.c:1645 */ { static bool warned = false; char *arr = (yyvsp[-1])->lextok; @@ -3001,57 +3096,55 @@ regular_print: else if ((yyvsp[-1])->memory == func_table) fatal(_("`delete' is not allowed with FUNCTAB")); } - (yyval) = add_pending_comment((yyval)); } -#line 3007 "awkgram.c" /* yacc.c:1645 */ +#line 3101 "awkgram.c" /* yacc.c:1645 */ break; case 67: -#line 1178 "awkgram.y" /* yacc.c:1645 */ +#line 1245 "awkgram.y" /* yacc.c:1645 */ { (yyval) = optimize_assignment((yyvsp[0])); - (yyval) = add_pending_comment((yyval)); } -#line 3016 "awkgram.c" /* yacc.c:1645 */ +#line 3109 "awkgram.c" /* yacc.c:1645 */ break; case 68: -#line 1186 "awkgram.y" /* yacc.c:1645 */ +#line 1252 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3022 "awkgram.c" /* yacc.c:1645 */ +#line 3115 "awkgram.c" /* yacc.c:1645 */ break; case 69: -#line 1188 "awkgram.y" /* yacc.c:1645 */ +#line 1254 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3028 "awkgram.c" /* yacc.c:1645 */ +#line 3121 "awkgram.c" /* yacc.c:1645 */ break; case 70: -#line 1193 "awkgram.y" /* yacc.c:1645 */ +#line 1259 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3034 "awkgram.c" /* yacc.c:1645 */ +#line 3127 "awkgram.c" /* yacc.c:1645 */ break; case 71: -#line 1195 "awkgram.y" /* yacc.c:1645 */ +#line 1261 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[-1]) == NULL) (yyval) = list_create((yyvsp[0])); else (yyval) = list_prepend((yyvsp[-1]), (yyvsp[0])); } -#line 3045 "awkgram.c" /* yacc.c:1645 */ +#line 3138 "awkgram.c" /* yacc.c:1645 */ break; case 72: -#line 1202 "awkgram.y" /* yacc.c:1645 */ +#line 1268 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3051 "awkgram.c" /* yacc.c:1645 */ +#line 3144 "awkgram.c" /* yacc.c:1645 */ break; case 73: -#line 1207 "awkgram.y" /* yacc.c:1645 */ +#line 1273 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *casestmt = (yyvsp[0]); if ((yyvsp[0]) == NULL) @@ -3060,14 +3153,15 @@ regular_print: (void) list_prepend(casestmt, instruction(Op_exec_count)); (yyvsp[-4])->case_exp = (yyvsp[-3]); (yyvsp[-4])->case_stmt = casestmt; + (yyvsp[-4])->comment = (yyvsp[-1]); bcfree((yyvsp[-2])); (yyval) = (yyvsp[-4]); } -#line 3067 "awkgram.c" /* yacc.c:1645 */ +#line 3161 "awkgram.c" /* yacc.c:1645 */ break; case 74: -#line 1219 "awkgram.y" /* yacc.c:1645 */ +#line 1286 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *casestmt = (yyvsp[0]); if ((yyvsp[0]) == NULL) @@ -3076,19 +3170,20 @@ regular_print: (void) list_prepend(casestmt, instruction(Op_exec_count)); bcfree((yyvsp[-2])); (yyvsp[-3])->case_stmt = casestmt; + (yyvsp[-3])->comment = (yyvsp[-1]); (yyval) = (yyvsp[-3]); } -#line 3082 "awkgram.c" /* yacc.c:1645 */ +#line 3177 "awkgram.c" /* yacc.c:1645 */ break; case 75: -#line 1233 "awkgram.y" /* yacc.c:1645 */ +#line 1301 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3088 "awkgram.c" /* yacc.c:1645 */ +#line 3183 "awkgram.c" /* yacc.c:1645 */ break; case 76: -#line 1235 "awkgram.y" /* yacc.c:1645 */ +#line 1303 "awkgram.y" /* yacc.c:1645 */ { NODE *n = (yyvsp[0])->memory; (void) force_number(n); @@ -3096,28 +3191,28 @@ regular_print: bcfree((yyvsp[-1])); (yyval) = (yyvsp[0]); } -#line 3100 "awkgram.c" /* yacc.c:1645 */ +#line 3195 "awkgram.c" /* yacc.c:1645 */ break; case 77: -#line 1243 "awkgram.y" /* yacc.c:1645 */ +#line 1311 "awkgram.y" /* yacc.c:1645 */ { NODE *n = (yyvsp[0])->lasti->memory; bcfree((yyvsp[-1])); add_sign_to_num(n, '+'); (yyval) = (yyvsp[0]); } -#line 3111 "awkgram.c" /* yacc.c:1645 */ +#line 3206 "awkgram.c" /* yacc.c:1645 */ break; case 78: -#line 1250 "awkgram.y" /* yacc.c:1645 */ +#line 1318 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3117 "awkgram.c" /* yacc.c:1645 */ +#line 3212 "awkgram.c" /* yacc.c:1645 */ break; case 79: -#line 1252 "awkgram.y" /* yacc.c:1645 */ +#line 1320 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[0])->memory->type == Node_regex) (yyvsp[0])->opcode = Op_push_re; @@ -3125,57 +3220,57 @@ regular_print: (yyvsp[0])->opcode = Op_push; (yyval) = (yyvsp[0]); } -#line 3129 "awkgram.c" /* yacc.c:1645 */ +#line 3224 "awkgram.c" /* yacc.c:1645 */ break; case 80: -#line 1260 "awkgram.y" /* yacc.c:1645 */ +#line 1328 "awkgram.y" /* yacc.c:1645 */ { assert(((yyvsp[0])->memory->flags & REGEX) == REGEX); (yyvsp[0])->opcode = Op_push_re; (yyval) = (yyvsp[0]); } -#line 3139 "awkgram.c" /* yacc.c:1645 */ +#line 3234 "awkgram.c" /* yacc.c:1645 */ break; case 81: -#line 1269 "awkgram.y" /* yacc.c:1645 */ +#line 1337 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3145 "awkgram.c" /* yacc.c:1645 */ +#line 3240 "awkgram.c" /* yacc.c:1645 */ break; case 82: -#line 1271 "awkgram.y" /* yacc.c:1645 */ +#line 1339 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3151 "awkgram.c" /* yacc.c:1645 */ +#line 3246 "awkgram.c" /* yacc.c:1645 */ break; case 84: -#line 1281 "awkgram.y" /* yacc.c:1645 */ +#line 1349 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[-1]); } -#line 3159 "awkgram.c" /* yacc.c:1645 */ +#line 3254 "awkgram.c" /* yacc.c:1645 */ break; case 85: -#line 1288 "awkgram.y" /* yacc.c:1645 */ +#line 1356 "awkgram.y" /* yacc.c:1645 */ { in_print = false; in_parens = 0; (yyval) = NULL; } -#line 3169 "awkgram.c" /* yacc.c:1645 */ +#line 3264 "awkgram.c" /* yacc.c:1645 */ break; case 86: -#line 1293 "awkgram.y" /* yacc.c:1645 */ +#line 1361 "awkgram.y" /* yacc.c:1645 */ { in_print = false; in_parens = 0; } -#line 3175 "awkgram.c" /* yacc.c:1645 */ +#line 3270 "awkgram.c" /* yacc.c:1645 */ break; case 87: -#line 1294 "awkgram.y" /* yacc.c:1645 */ +#line 1362 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[-2])->redir_type == redirect_twoway && (yyvsp[0])->lasti->opcode == Op_K_getline_redir @@ -3185,139 +3280,197 @@ regular_print: lintwarn(_("concatenation as I/O `>' redirection target is ambiguous")); (yyval) = list_prepend((yyvsp[0]), (yyvsp[-2])); } -#line 3189 "awkgram.c" /* yacc.c:1645 */ +#line 3284 "awkgram.c" /* yacc.c:1645 */ break; case 88: -#line 1307 "awkgram.y" /* yacc.c:1645 */ +#line 1375 "awkgram.y" /* yacc.c:1645 */ { + if ((yyvsp[-1]) != NULL) + (yyvsp[-5])->comment = (yyvsp[-1]); (yyval) = mk_condition((yyvsp[-3]), (yyvsp[-5]), (yyvsp[0]), NULL, NULL); } -#line 3197 "awkgram.c" /* yacc.c:1645 */ +#line 3294 "awkgram.c" /* yacc.c:1645 */ break; case 89: -#line 1312 "awkgram.y" /* yacc.c:1645 */ +#line 1382 "awkgram.y" /* yacc.c:1645 */ { + if ((yyvsp[-4]) != NULL) + (yyvsp[-8])->comment = (yyvsp[-4]); + if ((yyvsp[-1]) != NULL) + (yyvsp[-2])->comment = (yyvsp[-1]); (yyval) = mk_condition((yyvsp[-6]), (yyvsp[-8]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[0])); } -#line 3205 "awkgram.c" /* yacc.c:1645 */ +#line 3306 "awkgram.c" /* yacc.c:1645 */ + break; + + case 90: +#line 1393 "awkgram.y" /* yacc.c:1645 */ + { + (yyval) = (yyvsp[0]); + } +#line 3314 "awkgram.c" /* yacc.c:1645 */ + break; + + case 91: +#line 1397 "awkgram.y" /* yacc.c:1645 */ + { + if ((yyvsp[-1]) != NULL && (yyvsp[0]) != NULL) { + if ((yyvsp[-1])->memory->comment_type == EOL_COMMENT) { + assert((yyvsp[0])->memory->comment_type == BLOCK_COMMENT); + (yyvsp[-1])->comment = (yyvsp[0]); // chain them + } else { + merge_comments((yyvsp[-1]), (yyvsp[0])); + } + + (yyval) = (yyvsp[-1]); + } else if ((yyvsp[-1]) != NULL) { + (yyval) = (yyvsp[-1]); + } else if ((yyvsp[0]) != NULL) { + (yyval) = (yyvsp[0]); + } else + (yyval) = NULL; + } +#line 3336 "awkgram.c" /* yacc.c:1645 */ + break; + + case 92: +#line 1418 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = NULL; } +#line 3342 "awkgram.c" /* yacc.c:1645 */ + break; + + case 93: +#line 1420 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = (yyvsp[0]); } +#line 3348 "awkgram.c" /* yacc.c:1645 */ break; case 94: -#line 1329 "awkgram.y" /* yacc.c:1645 */ +#line 1425 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3211 "awkgram.c" /* yacc.c:1645 */ +#line 3354 "awkgram.c" /* yacc.c:1645 */ break; case 95: -#line 1331 "awkgram.y" /* yacc.c:1645 */ +#line 1427 "awkgram.y" /* yacc.c:1645 */ { bcfree((yyvsp[-1])); (yyval) = (yyvsp[0]); } -#line 3220 "awkgram.c" /* yacc.c:1645 */ +#line 3363 "awkgram.c" /* yacc.c:1645 */ break; case 96: -#line 1339 "awkgram.y" /* yacc.c:1645 */ +#line 1435 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3226 "awkgram.c" /* yacc.c:1645 */ +#line 3369 "awkgram.c" /* yacc.c:1645 */ break; case 97: -#line 1341 "awkgram.y" /* yacc.c:1645 */ +#line 1437 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3232 "awkgram.c" /* yacc.c:1645 */ +#line 3375 "awkgram.c" /* yacc.c:1645 */ break; case 98: -#line 1346 "awkgram.y" /* yacc.c:1645 */ +#line 1442 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[0])->param_count = 0; (yyval) = list_create((yyvsp[0])); } -#line 3241 "awkgram.c" /* yacc.c:1645 */ +#line 3384 "awkgram.c" /* yacc.c:1645 */ break; case 99: -#line 1351 "awkgram.y" /* yacc.c:1645 */ +#line 1447 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[-2]) != NULL && (yyvsp[0]) != NULL) { - (yyvsp[0])->param_count = (yyvsp[-2])->lasti->param_count + 1; + (yyvsp[0])->param_count = (yyvsp[-2])->lasti->param_count + 1; (yyval) = list_append((yyvsp[-2]), (yyvsp[0])); yyerrok; + + // newlines are allowed after commas, catch any comments + if ((yyvsp[-1]) != NULL) { + if ((yyvsp[-2])->comment != NULL) + merge_comments((yyvsp[-2])->comment, (yyvsp[-1])); + else + (yyvsp[-2])->comment = (yyvsp[-1]); + } } else (yyval) = NULL; } -#line 3254 "awkgram.c" /* yacc.c:1645 */ +#line 3405 "awkgram.c" /* yacc.c:1645 */ break; case 100: -#line 1360 "awkgram.y" /* yacc.c:1645 */ +#line 1464 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3260 "awkgram.c" /* yacc.c:1645 */ +#line 3411 "awkgram.c" /* yacc.c:1645 */ break; case 101: -#line 1362 "awkgram.y" /* yacc.c:1645 */ +#line 1466 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[-1]); } -#line 3266 "awkgram.c" /* yacc.c:1645 */ +#line 3417 "awkgram.c" /* yacc.c:1645 */ break; case 102: -#line 1364 "awkgram.y" /* yacc.c:1645 */ +#line 1468 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[-2]); } -#line 3272 "awkgram.c" /* yacc.c:1645 */ +#line 3423 "awkgram.c" /* yacc.c:1645 */ break; case 103: -#line 1370 "awkgram.y" /* yacc.c:1645 */ +#line 1474 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3278 "awkgram.c" /* yacc.c:1645 */ +#line 3429 "awkgram.c" /* yacc.c:1645 */ break; case 104: -#line 1372 "awkgram.y" /* yacc.c:1645 */ +#line 1476 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3284 "awkgram.c" /* yacc.c:1645 */ +#line 3435 "awkgram.c" /* yacc.c:1645 */ break; case 105: -#line 1377 "awkgram.y" /* yacc.c:1645 */ +#line 1481 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3290 "awkgram.c" /* yacc.c:1645 */ +#line 3441 "awkgram.c" /* yacc.c:1645 */ break; case 106: -#line 1379 "awkgram.y" /* yacc.c:1645 */ +#line 1483 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3296 "awkgram.c" /* yacc.c:1645 */ +#line 3447 "awkgram.c" /* yacc.c:1645 */ break; case 107: -#line 1384 "awkgram.y" /* yacc.c:1645 */ +#line 1488 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_expression_list(NULL, (yyvsp[0])); } -#line 3302 "awkgram.c" /* yacc.c:1645 */ +#line 3453 "awkgram.c" /* yacc.c:1645 */ break; case 108: -#line 1386 "awkgram.y" /* yacc.c:1645 */ +#line 1490 "awkgram.y" /* yacc.c:1645 */ { + if ((yyvsp[-1]) != NULL) + (yyvsp[-2])->lasti->comment = (yyvsp[-1]); (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0])); yyerrok; } -#line 3311 "awkgram.c" /* yacc.c:1645 */ +#line 3464 "awkgram.c" /* yacc.c:1645 */ break; case 109: -#line 1391 "awkgram.y" /* yacc.c:1645 */ +#line 1497 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3317 "awkgram.c" /* yacc.c:1645 */ +#line 3470 "awkgram.c" /* yacc.c:1645 */ break; case 110: -#line 1393 "awkgram.y" /* yacc.c:1645 */ +#line 1499 "awkgram.y" /* yacc.c:1645 */ { /* * Returning the expression list instead of NULL lets @@ -3325,62 +3478,66 @@ regular_print: */ (yyval) = (yyvsp[-1]); } -#line 3329 "awkgram.c" /* yacc.c:1645 */ +#line 3482 "awkgram.c" /* yacc.c:1645 */ break; case 111: -#line 1401 "awkgram.y" /* yacc.c:1645 */ +#line 1507 "awkgram.y" /* yacc.c:1645 */ { /* Ditto */ (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0])); } -#line 3338 "awkgram.c" /* yacc.c:1645 */ +#line 3491 "awkgram.c" /* yacc.c:1645 */ break; case 112: -#line 1406 "awkgram.y" /* yacc.c:1645 */ +#line 1512 "awkgram.y" /* yacc.c:1645 */ { /* Ditto */ + if ((yyvsp[-1]) != NULL) + (yyvsp[-2])->lasti->comment = (yyvsp[-1]); (yyval) = (yyvsp[-2]); } -#line 3347 "awkgram.c" /* yacc.c:1645 */ +#line 3502 "awkgram.c" /* yacc.c:1645 */ break; case 113: -#line 1414 "awkgram.y" /* yacc.c:1645 */ +#line 1522 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3353 "awkgram.c" /* yacc.c:1645 */ +#line 3508 "awkgram.c" /* yacc.c:1645 */ break; case 114: -#line 1416 "awkgram.y" /* yacc.c:1645 */ +#line 1524 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3359 "awkgram.c" /* yacc.c:1645 */ +#line 3514 "awkgram.c" /* yacc.c:1645 */ break; case 115: -#line 1421 "awkgram.y" /* yacc.c:1645 */ +#line 1529 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_expression_list(NULL, (yyvsp[0])); } -#line 3365 "awkgram.c" /* yacc.c:1645 */ +#line 3520 "awkgram.c" /* yacc.c:1645 */ break; case 116: -#line 1423 "awkgram.y" /* yacc.c:1645 */ +#line 1531 "awkgram.y" /* yacc.c:1645 */ { + if ((yyvsp[-1]) != NULL) + (yyvsp[-2])->lasti->comment = (yyvsp[-1]); (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0])); yyerrok; } -#line 3374 "awkgram.c" /* yacc.c:1645 */ +#line 3531 "awkgram.c" /* yacc.c:1645 */ break; case 117: -#line 1428 "awkgram.y" /* yacc.c:1645 */ +#line 1538 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 3380 "awkgram.c" /* yacc.c:1645 */ +#line 3537 "awkgram.c" /* yacc.c:1645 */ break; case 118: -#line 1430 "awkgram.y" /* yacc.c:1645 */ +#line 1540 "awkgram.y" /* yacc.c:1645 */ { /* * Returning the expression list instead of NULL lets @@ -3388,72 +3545,74 @@ regular_print: */ (yyval) = (yyvsp[-1]); } -#line 3392 "awkgram.c" /* yacc.c:1645 */ +#line 3549 "awkgram.c" /* yacc.c:1645 */ break; case 119: -#line 1438 "awkgram.y" /* yacc.c:1645 */ +#line 1548 "awkgram.y" /* yacc.c:1645 */ { /* Ditto */ (yyval) = mk_expression_list((yyvsp[-2]), (yyvsp[0])); } -#line 3401 "awkgram.c" /* yacc.c:1645 */ +#line 3558 "awkgram.c" /* yacc.c:1645 */ break; case 120: -#line 1443 "awkgram.y" /* yacc.c:1645 */ +#line 1553 "awkgram.y" /* yacc.c:1645 */ { /* Ditto */ + if ((yyvsp[-1]) != NULL) + (yyvsp[-2])->comment = (yyvsp[-1]); (yyval) = (yyvsp[-2]); } -#line 3410 "awkgram.c" /* yacc.c:1645 */ +#line 3569 "awkgram.c" /* yacc.c:1645 */ break; case 121: -#line 1450 "awkgram.y" /* yacc.c:1645 */ +#line 1562 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3416 "awkgram.c" /* yacc.c:1645 */ +#line 3575 "awkgram.c" /* yacc.c:1645 */ break; case 122: -#line 1451 "awkgram.y" /* yacc.c:1645 */ +#line 1563 "awkgram.y" /* yacc.c:1645 */ { (yyval) = list_create((yyvsp[0])); } -#line 3422 "awkgram.c" /* yacc.c:1645 */ +#line 3581 "awkgram.c" /* yacc.c:1645 */ break; case 123: -#line 1457 "awkgram.y" /* yacc.c:1645 */ +#line 1569 "awkgram.y" /* yacc.c:1645 */ { if (do_lint && (yyvsp[0])->lasti->opcode == Op_match_rec) lintwarn_ln((yyvsp[-1])->source_line, _("regular expression on right of assignment")); (yyval) = mk_assignment((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3433 "awkgram.c" /* yacc.c:1645 */ +#line 3592 "awkgram.c" /* yacc.c:1645 */ break; case 124: -#line 1464 "awkgram.y" /* yacc.c:1645 */ +#line 1576 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_assignment((yyvsp[-2]), list_create((yyvsp[0])), (yyvsp[-1])); } -#line 3441 "awkgram.c" /* yacc.c:1645 */ +#line 3600 "awkgram.c" /* yacc.c:1645 */ break; case 125: -#line 1468 "awkgram.y" /* yacc.c:1645 */ +#line 1580 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_boolean((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3447 "awkgram.c" /* yacc.c:1645 */ +#line 3606 "awkgram.c" /* yacc.c:1645 */ break; case 126: -#line 1470 "awkgram.y" /* yacc.c:1645 */ +#line 1582 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_boolean((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3453 "awkgram.c" /* yacc.c:1645 */ +#line 3612 "awkgram.c" /* yacc.c:1645 */ break; case 127: -#line 1472 "awkgram.y" /* yacc.c:1645 */ +#line 1584 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[-2])->lasti->opcode == Op_match_rec) warning_ln((yyvsp[-1])->source_line, @@ -3466,11 +3625,11 @@ regular_print: bcfree((yyvsp[0])); (yyval) = list_append((yyvsp[-2]), (yyvsp[-1])); } -#line 3470 "awkgram.c" /* yacc.c:1645 */ +#line 3629 "awkgram.c" /* yacc.c:1645 */ break; case 128: -#line 1485 "awkgram.y" /* yacc.c:1645 */ +#line 1597 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[-2])->lasti->opcode == Op_match_rec) warning_ln((yyvsp[-1])->source_line, @@ -3487,11 +3646,11 @@ regular_print: (yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1])); } } -#line 3491 "awkgram.c" /* yacc.c:1645 */ +#line 3650 "awkgram.c" /* yacc.c:1645 */ break; case 129: -#line 1502 "awkgram.y" /* yacc.c:1645 */ +#line 1614 "awkgram.y" /* yacc.c:1645 */ { if (do_lint_old) warning_ln((yyvsp[-1])->source_line, @@ -3501,91 +3660,91 @@ regular_print: (yyvsp[-1])->expr_count = 1; (yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1])); } -#line 3505 "awkgram.c" /* yacc.c:1645 */ +#line 3664 "awkgram.c" /* yacc.c:1645 */ break; case 130: -#line 1512 "awkgram.y" /* yacc.c:1645 */ +#line 1624 "awkgram.y" /* yacc.c:1645 */ { if (do_lint && (yyvsp[0])->lasti->opcode == Op_match_rec) lintwarn_ln((yyvsp[-1])->source_line, _("regular expression on right of comparison")); (yyval) = list_append(list_merge((yyvsp[-2]), (yyvsp[0])), (yyvsp[-1])); } -#line 3516 "awkgram.c" /* yacc.c:1645 */ +#line 3675 "awkgram.c" /* yacc.c:1645 */ break; case 131: -#line 1519 "awkgram.y" /* yacc.c:1645 */ +#line 1631 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_condition((yyvsp[-4]), (yyvsp[-3]), (yyvsp[-2]), (yyvsp[-1]), (yyvsp[0])); } -#line 3522 "awkgram.c" /* yacc.c:1645 */ +#line 3681 "awkgram.c" /* yacc.c:1645 */ break; case 132: -#line 1521 "awkgram.y" /* yacc.c:1645 */ +#line 1633 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3528 "awkgram.c" /* yacc.c:1645 */ +#line 3687 "awkgram.c" /* yacc.c:1645 */ break; case 133: -#line 1526 "awkgram.y" /* yacc.c:1645 */ +#line 1638 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3534 "awkgram.c" /* yacc.c:1645 */ +#line 3693 "awkgram.c" /* yacc.c:1645 */ break; case 134: -#line 1528 "awkgram.y" /* yacc.c:1645 */ +#line 1640 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3540 "awkgram.c" /* yacc.c:1645 */ +#line 3699 "awkgram.c" /* yacc.c:1645 */ break; case 135: -#line 1530 "awkgram.y" /* yacc.c:1645 */ +#line 1642 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[0])->opcode = Op_assign_quotient; (yyval) = (yyvsp[0]); } -#line 3549 "awkgram.c" /* yacc.c:1645 */ +#line 3708 "awkgram.c" /* yacc.c:1645 */ break; case 136: -#line 1538 "awkgram.y" /* yacc.c:1645 */ +#line 1650 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3555 "awkgram.c" /* yacc.c:1645 */ +#line 3714 "awkgram.c" /* yacc.c:1645 */ break; case 137: -#line 1540 "awkgram.y" /* yacc.c:1645 */ +#line 1652 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3561 "awkgram.c" /* yacc.c:1645 */ +#line 3720 "awkgram.c" /* yacc.c:1645 */ break; case 138: -#line 1545 "awkgram.y" /* yacc.c:1645 */ +#line 1657 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3567 "awkgram.c" /* yacc.c:1645 */ +#line 3726 "awkgram.c" /* yacc.c:1645 */ break; case 139: -#line 1547 "awkgram.y" /* yacc.c:1645 */ +#line 1659 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3573 "awkgram.c" /* yacc.c:1645 */ +#line 3732 "awkgram.c" /* yacc.c:1645 */ break; case 140: -#line 1552 "awkgram.y" /* yacc.c:1645 */ +#line 1664 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3579 "awkgram.c" /* yacc.c:1645 */ +#line 3738 "awkgram.c" /* yacc.c:1645 */ break; case 141: -#line 1554 "awkgram.y" /* yacc.c:1645 */ +#line 1666 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 3585 "awkgram.c" /* yacc.c:1645 */ +#line 3744 "awkgram.c" /* yacc.c:1645 */ break; case 142: -#line 1556 "awkgram.y" /* yacc.c:1645 */ +#line 1668 "awkgram.y" /* yacc.c:1645 */ { int count = 2; bool is_simple_var = false; @@ -3639,47 +3798,47 @@ regular_print: max_args = count; } } -#line 3643 "awkgram.c" /* yacc.c:1645 */ +#line 3802 "awkgram.c" /* yacc.c:1645 */ break; case 144: -#line 1615 "awkgram.y" /* yacc.c:1645 */ +#line 1727 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3649 "awkgram.c" /* yacc.c:1645 */ +#line 3808 "awkgram.c" /* yacc.c:1645 */ break; case 145: -#line 1617 "awkgram.y" /* yacc.c:1645 */ +#line 1729 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3655 "awkgram.c" /* yacc.c:1645 */ +#line 3814 "awkgram.c" /* yacc.c:1645 */ break; case 146: -#line 1619 "awkgram.y" /* yacc.c:1645 */ +#line 1731 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3661 "awkgram.c" /* yacc.c:1645 */ +#line 3820 "awkgram.c" /* yacc.c:1645 */ break; case 147: -#line 1621 "awkgram.y" /* yacc.c:1645 */ +#line 1733 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3667 "awkgram.c" /* yacc.c:1645 */ +#line 3826 "awkgram.c" /* yacc.c:1645 */ break; case 148: -#line 1623 "awkgram.y" /* yacc.c:1645 */ +#line 1735 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3673 "awkgram.c" /* yacc.c:1645 */ +#line 3832 "awkgram.c" /* yacc.c:1645 */ break; case 149: -#line 1625 "awkgram.y" /* yacc.c:1645 */ +#line 1737 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3679 "awkgram.c" /* yacc.c:1645 */ +#line 3838 "awkgram.c" /* yacc.c:1645 */ break; case 150: -#line 1627 "awkgram.y" /* yacc.c:1645 */ +#line 1739 "awkgram.y" /* yacc.c:1645 */ { /* * In BEGINFILE/ENDFILE, allow `getline [var] < file' @@ -3693,29 +3852,29 @@ regular_print: _("non-redirected `getline' undefined inside END action")); (yyval) = mk_getline((yyvsp[-2]), (yyvsp[-1]), (yyvsp[0]), redirect_input); } -#line 3697 "awkgram.c" /* yacc.c:1645 */ +#line 3856 "awkgram.c" /* yacc.c:1645 */ break; case 151: -#line 1641 "awkgram.y" /* yacc.c:1645 */ +#line 1753 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[0])->opcode = Op_postincrement; (yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0])); } -#line 3706 "awkgram.c" /* yacc.c:1645 */ +#line 3865 "awkgram.c" /* yacc.c:1645 */ break; case 152: -#line 1646 "awkgram.y" /* yacc.c:1645 */ +#line 1758 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[0])->opcode = Op_postdecrement; (yyval) = mk_assignment((yyvsp[-1]), NULL, (yyvsp[0])); } -#line 3715 "awkgram.c" /* yacc.c:1645 */ +#line 3874 "awkgram.c" /* yacc.c:1645 */ break; case 153: -#line 1651 "awkgram.y" /* yacc.c:1645 */ +#line 1763 "awkgram.y" /* yacc.c:1645 */ { if (do_lint_old) { warning_ln((yyvsp[-1])->source_line, @@ -3735,64 +3894,64 @@ regular_print: (yyval) = list_append(list_merge(t, (yyvsp[0])), (yyvsp[-1])); } } -#line 3739 "awkgram.c" /* yacc.c:1645 */ +#line 3898 "awkgram.c" /* yacc.c:1645 */ break; case 154: -#line 1676 "awkgram.y" /* yacc.c:1645 */ +#line 1788 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_getline((yyvsp[-1]), (yyvsp[0]), (yyvsp[-3]), (yyvsp[-2])->redir_type); bcfree((yyvsp[-2])); } -#line 3748 "awkgram.c" /* yacc.c:1645 */ +#line 3907 "awkgram.c" /* yacc.c:1645 */ break; case 155: -#line 1682 "awkgram.y" /* yacc.c:1645 */ +#line 1794 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3754 "awkgram.c" /* yacc.c:1645 */ +#line 3913 "awkgram.c" /* yacc.c:1645 */ break; case 156: -#line 1684 "awkgram.y" /* yacc.c:1645 */ +#line 1796 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3760 "awkgram.c" /* yacc.c:1645 */ +#line 3919 "awkgram.c" /* yacc.c:1645 */ break; case 157: -#line 1686 "awkgram.y" /* yacc.c:1645 */ +#line 1798 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3766 "awkgram.c" /* yacc.c:1645 */ +#line 3925 "awkgram.c" /* yacc.c:1645 */ break; case 158: -#line 1688 "awkgram.y" /* yacc.c:1645 */ +#line 1800 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3772 "awkgram.c" /* yacc.c:1645 */ +#line 3931 "awkgram.c" /* yacc.c:1645 */ break; case 159: -#line 1690 "awkgram.y" /* yacc.c:1645 */ +#line 1802 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3778 "awkgram.c" /* yacc.c:1645 */ +#line 3937 "awkgram.c" /* yacc.c:1645 */ break; case 160: -#line 1692 "awkgram.y" /* yacc.c:1645 */ +#line 1804 "awkgram.y" /* yacc.c:1645 */ { (yyval) = mk_binary((yyvsp[-2]), (yyvsp[0]), (yyvsp[-1])); } -#line 3784 "awkgram.c" /* yacc.c:1645 */ +#line 3943 "awkgram.c" /* yacc.c:1645 */ break; case 161: -#line 1697 "awkgram.y" /* yacc.c:1645 */ +#line 1809 "awkgram.y" /* yacc.c:1645 */ { (yyval) = list_create((yyvsp[0])); } -#line 3792 "awkgram.c" /* yacc.c:1645 */ +#line 3951 "awkgram.c" /* yacc.c:1645 */ break; case 162: -#line 1701 "awkgram.y" /* yacc.c:1645 */ +#line 1813 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[0])->opcode == Op_match_rec) { (yyvsp[0])->opcode = Op_nomatch; @@ -3824,11 +3983,11 @@ regular_print: } } } -#line 3828 "awkgram.c" /* yacc.c:1645 */ +#line 3987 "awkgram.c" /* yacc.c:1645 */ break; case 163: -#line 1733 "awkgram.y" /* yacc.c:1645 */ +#line 1845 "awkgram.y" /* yacc.c:1645 */ { // Always include. Allows us to lint warn on // print "foo" > "bar" 1 @@ -3836,31 +3995,31 @@ regular_print: // print "foo" > ("bar" 1) (yyval) = list_append((yyvsp[-1]), bcalloc(Op_parens, 1, sourceline)); } -#line 3840 "awkgram.c" /* yacc.c:1645 */ +#line 3999 "awkgram.c" /* yacc.c:1645 */ break; case 164: -#line 1741 "awkgram.y" /* yacc.c:1645 */ +#line 1853 "awkgram.y" /* yacc.c:1645 */ { (yyval) = snode((yyvsp[-1]), (yyvsp[-3])); if ((yyval) == NULL) YYABORT; } -#line 3850 "awkgram.c" /* yacc.c:1645 */ +#line 4009 "awkgram.c" /* yacc.c:1645 */ break; case 165: -#line 1747 "awkgram.y" /* yacc.c:1645 */ +#line 1859 "awkgram.y" /* yacc.c:1645 */ { (yyval) = snode((yyvsp[-1]), (yyvsp[-3])); if ((yyval) == NULL) YYABORT; } -#line 3860 "awkgram.c" /* yacc.c:1645 */ +#line 4019 "awkgram.c" /* yacc.c:1645 */ break; case 166: -#line 1753 "awkgram.y" /* yacc.c:1645 */ +#line 1865 "awkgram.y" /* yacc.c:1645 */ { static bool warned = false; @@ -3873,45 +4032,45 @@ regular_print: if ((yyval) == NULL) YYABORT; } -#line 3877 "awkgram.c" /* yacc.c:1645 */ +#line 4036 "awkgram.c" /* yacc.c:1645 */ break; case 169: -#line 1768 "awkgram.y" /* yacc.c:1645 */ +#line 1880 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[-1])->opcode = Op_preincrement; (yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1])); } -#line 3886 "awkgram.c" /* yacc.c:1645 */ +#line 4045 "awkgram.c" /* yacc.c:1645 */ break; case 170: -#line 1773 "awkgram.y" /* yacc.c:1645 */ +#line 1885 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[-1])->opcode = Op_predecrement; (yyval) = mk_assignment((yyvsp[0]), NULL, (yyvsp[-1])); } -#line 3895 "awkgram.c" /* yacc.c:1645 */ +#line 4054 "awkgram.c" /* yacc.c:1645 */ break; case 171: -#line 1778 "awkgram.y" /* yacc.c:1645 */ +#line 1890 "awkgram.y" /* yacc.c:1645 */ { (yyval) = list_create((yyvsp[0])); } -#line 3903 "awkgram.c" /* yacc.c:1645 */ +#line 4062 "awkgram.c" /* yacc.c:1645 */ break; case 172: -#line 1782 "awkgram.y" /* yacc.c:1645 */ +#line 1894 "awkgram.y" /* yacc.c:1645 */ { (yyval) = list_create((yyvsp[0])); } -#line 3911 "awkgram.c" /* yacc.c:1645 */ +#line 4070 "awkgram.c" /* yacc.c:1645 */ break; case 173: -#line 1786 "awkgram.y" /* yacc.c:1645 */ +#line 1898 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[0])->lasti->opcode == Op_push_i && ((yyvsp[0])->lasti->memory->flags & STRING) == 0 @@ -3926,11 +4085,11 @@ regular_print: (yyval) = list_append((yyvsp[0]), (yyvsp[-1])); } } -#line 3930 "awkgram.c" /* yacc.c:1645 */ +#line 4089 "awkgram.c" /* yacc.c:1645 */ break; case 174: -#line 1801 "awkgram.y" /* yacc.c:1645 */ +#line 1913 "awkgram.y" /* yacc.c:1645 */ { if ((yyvsp[0])->lasti->opcode == Op_push_i && ((yyvsp[0])->lasti->memory->flags & STRING) == 0 @@ -3948,20 +4107,20 @@ regular_print: (yyval) = list_append((yyvsp[0]), (yyvsp[-1])); } } -#line 3952 "awkgram.c" /* yacc.c:1645 */ +#line 4111 "awkgram.c" /* yacc.c:1645 */ break; case 175: -#line 1822 "awkgram.y" /* yacc.c:1645 */ +#line 1934 "awkgram.y" /* yacc.c:1645 */ { func_use((yyvsp[0])->lasti->func_name, FUNC_USE); (yyval) = (yyvsp[0]); } -#line 3961 "awkgram.c" /* yacc.c:1645 */ +#line 4120 "awkgram.c" /* yacc.c:1645 */ break; case 176: -#line 1827 "awkgram.y" /* yacc.c:1645 */ +#line 1939 "awkgram.y" /* yacc.c:1645 */ { /* indirect function call */ INSTRUCTION *f, *t; @@ -3995,11 +4154,11 @@ regular_print: (yyval) = list_prepend((yyvsp[0]), t); at_seen = false; } -#line 3999 "awkgram.c" /* yacc.c:1645 */ +#line 4158 "awkgram.c" /* yacc.c:1645 */ break; case 177: -#line 1864 "awkgram.y" /* yacc.c:1645 */ +#line 1976 "awkgram.y" /* yacc.c:1645 */ { NODE *n; @@ -4024,49 +4183,49 @@ regular_print: (yyval) = list_append(t, (yyvsp[-3])); } } -#line 4028 "awkgram.c" /* yacc.c:1645 */ +#line 4187 "awkgram.c" /* yacc.c:1645 */ break; case 178: -#line 1892 "awkgram.y" /* yacc.c:1645 */ +#line 2004 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 4034 "awkgram.c" /* yacc.c:1645 */ +#line 4193 "awkgram.c" /* yacc.c:1645 */ break; case 179: -#line 1894 "awkgram.y" /* yacc.c:1645 */ +#line 2006 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 4040 "awkgram.c" /* yacc.c:1645 */ +#line 4199 "awkgram.c" /* yacc.c:1645 */ break; case 180: -#line 1899 "awkgram.y" /* yacc.c:1645 */ +#line 2011 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 4046 "awkgram.c" /* yacc.c:1645 */ +#line 4205 "awkgram.c" /* yacc.c:1645 */ break; case 181: -#line 1901 "awkgram.y" /* yacc.c:1645 */ +#line 2013 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[-1]); } -#line 4052 "awkgram.c" /* yacc.c:1645 */ +#line 4211 "awkgram.c" /* yacc.c:1645 */ break; case 182: -#line 1906 "awkgram.y" /* yacc.c:1645 */ +#line 2018 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 4058 "awkgram.c" /* yacc.c:1645 */ +#line 4217 "awkgram.c" /* yacc.c:1645 */ break; case 183: -#line 1908 "awkgram.y" /* yacc.c:1645 */ +#line 2020 "awkgram.y" /* yacc.c:1645 */ { (yyval) = list_merge((yyvsp[-1]), (yyvsp[0])); } -#line 4066 "awkgram.c" /* yacc.c:1645 */ +#line 4225 "awkgram.c" /* yacc.c:1645 */ break; case 184: -#line 1915 "awkgram.y" /* yacc.c:1645 */ +#line 2027 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *ip = (yyvsp[0])->lasti; int count = ip->sub_count; /* # of SUBSEP-seperated expressions */ @@ -4080,11 +4239,11 @@ regular_print: sub_counter++; /* count # of dimensions */ (yyval) = (yyvsp[0]); } -#line 4084 "awkgram.c" /* yacc.c:1645 */ +#line 4243 "awkgram.c" /* yacc.c:1645 */ break; case 185: -#line 1932 "awkgram.y" /* yacc.c:1645 */ +#line 2044 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *t = (yyvsp[-1]); if ((yyvsp[-1]) == NULL) { @@ -4098,31 +4257,31 @@ regular_print: (yyvsp[0])->sub_count = count_expressions(&t, false); (yyval) = list_append(t, (yyvsp[0])); } -#line 4102 "awkgram.c" /* yacc.c:1645 */ +#line 4261 "awkgram.c" /* yacc.c:1645 */ break; case 186: -#line 1949 "awkgram.y" /* yacc.c:1645 */ +#line 2061 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); } -#line 4108 "awkgram.c" /* yacc.c:1645 */ +#line 4267 "awkgram.c" /* yacc.c:1645 */ break; case 187: -#line 1951 "awkgram.y" /* yacc.c:1645 */ +#line 2063 "awkgram.y" /* yacc.c:1645 */ { (yyval) = list_merge((yyvsp[-1]), (yyvsp[0])); } -#line 4116 "awkgram.c" /* yacc.c:1645 */ +#line 4275 "awkgram.c" /* yacc.c:1645 */ break; case 188: -#line 1958 "awkgram.y" /* yacc.c:1645 */ +#line 2070 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[-1]); } -#line 4122 "awkgram.c" /* yacc.c:1645 */ +#line 4281 "awkgram.c" /* yacc.c:1645 */ break; case 189: -#line 1963 "awkgram.y" /* yacc.c:1645 */ +#line 2075 "awkgram.y" /* yacc.c:1645 */ { char *var_name = (yyvsp[0])->lextok; @@ -4130,22 +4289,22 @@ regular_print: (yyvsp[0])->memory = variable((yyvsp[0])->source_line, var_name, Node_var_new); (yyval) = list_create((yyvsp[0])); } -#line 4134 "awkgram.c" /* yacc.c:1645 */ +#line 4293 "awkgram.c" /* yacc.c:1645 */ break; case 190: -#line 1971 "awkgram.y" /* yacc.c:1645 */ +#line 2083 "awkgram.y" /* yacc.c:1645 */ { char *arr = (yyvsp[-1])->lextok; (yyvsp[-1])->memory = variable((yyvsp[-1])->source_line, arr, Node_var_new); (yyvsp[-1])->opcode = Op_push_array; (yyval) = list_prepend((yyvsp[0]), (yyvsp[-1])); } -#line 4145 "awkgram.c" /* yacc.c:1645 */ +#line 4304 "awkgram.c" /* yacc.c:1645 */ break; case 191: -#line 1981 "awkgram.y" /* yacc.c:1645 */ +#line 2093 "awkgram.y" /* yacc.c:1645 */ { INSTRUCTION *ip = (yyvsp[0])->nexti; if (ip->opcode == Op_push @@ -4157,73 +4316,85 @@ regular_print: } else (yyval) = (yyvsp[0]); } -#line 4161 "awkgram.c" /* yacc.c:1645 */ +#line 4320 "awkgram.c" /* yacc.c:1645 */ break; case 192: -#line 1993 "awkgram.y" /* yacc.c:1645 */ +#line 2105 "awkgram.y" /* yacc.c:1645 */ { (yyval) = list_append((yyvsp[-1]), (yyvsp[-2])); if ((yyvsp[0]) != NULL) mk_assignment((yyvsp[-1]), NULL, (yyvsp[0])); } -#line 4171 "awkgram.c" /* yacc.c:1645 */ +#line 4330 "awkgram.c" /* yacc.c:1645 */ break; case 193: -#line 2002 "awkgram.y" /* yacc.c:1645 */ +#line 2114 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[0])->opcode = Op_postincrement; } -#line 4179 "awkgram.c" /* yacc.c:1645 */ +#line 4338 "awkgram.c" /* yacc.c:1645 */ break; case 194: -#line 2006 "awkgram.y" /* yacc.c:1645 */ +#line 2118 "awkgram.y" /* yacc.c:1645 */ { (yyvsp[0])->opcode = Op_postdecrement; } -#line 4187 "awkgram.c" /* yacc.c:1645 */ +#line 4346 "awkgram.c" /* yacc.c:1645 */ break; case 195: -#line 2009 "awkgram.y" /* yacc.c:1645 */ +#line 2122 "awkgram.y" /* yacc.c:1645 */ { (yyval) = NULL; } -#line 4193 "awkgram.c" /* yacc.c:1645 */ +#line 4352 "awkgram.c" /* yacc.c:1645 */ + break; + + case 196: +#line 2126 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = (yyvsp[0]); } +#line 4358 "awkgram.c" /* yacc.c:1645 */ break; case 197: -#line 2017 "awkgram.y" /* yacc.c:1645 */ - { yyerrok; } -#line 4199 "awkgram.c" /* yacc.c:1645 */ +#line 2130 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = (yyvsp[0]); yyerrok; } +#line 4364 "awkgram.c" /* yacc.c:1645 */ break; case 198: -#line 2021 "awkgram.y" /* yacc.c:1645 */ +#line 2134 "awkgram.y" /* yacc.c:1645 */ { yyerrok; } -#line 4205 "awkgram.c" /* yacc.c:1645 */ +#line 4370 "awkgram.c" /* yacc.c:1645 */ + break; + + case 199: +#line 2139 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = NULL; } +#line 4376 "awkgram.c" /* yacc.c:1645 */ break; case 201: -#line 2030 "awkgram.y" /* yacc.c:1645 */ +#line 2144 "awkgram.y" /* yacc.c:1645 */ { yyerrok; } -#line 4211 "awkgram.c" /* yacc.c:1645 */ +#line 4382 "awkgram.c" /* yacc.c:1645 */ break; case 202: -#line 2034 "awkgram.y" /* yacc.c:1645 */ +#line 2148 "awkgram.y" /* yacc.c:1645 */ { (yyval) = (yyvsp[0]); yyerrok; } -#line 4217 "awkgram.c" /* yacc.c:1645 */ +#line 4388 "awkgram.c" /* yacc.c:1645 */ break; case 203: -#line 2038 "awkgram.y" /* yacc.c:1645 */ - { yyerrok; } -#line 4223 "awkgram.c" /* yacc.c:1645 */ +#line 2152 "awkgram.y" /* yacc.c:1645 */ + { (yyval) = (yyvsp[0]); yyerrok; } +#line 4394 "awkgram.c" /* yacc.c:1645 */ break; -#line 4227 "awkgram.c" /* yacc.c:1645 */ +#line 4398 "awkgram.c" /* yacc.c:1645 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -4450,7 +4621,7 @@ yyreturn: #endif return yyresult; } -#line 2040 "awkgram.y" /* yacc.c:1903 */ +#line 2154 "awkgram.y" /* yacc.c:1903 */ struct token { @@ -4529,8 +4700,8 @@ static const struct token tokentab[] = { {"exp", Op_builtin, LEX_BUILTIN, A(1), do_exp, MPF(exp)}, {"fflush", Op_builtin, LEX_BUILTIN, A(0)|A(1), do_fflush, 0}, {"for", Op_K_for, LEX_FOR, BREAK|CONTINUE, 0, 0}, -{"func", Op_func, LEX_FUNCTION, NOT_POSIX|NOT_OLD, 0, 0}, -{"function",Op_func, LEX_FUNCTION, NOT_OLD, 0, 0}, +{"func", Op_func, LEX_FUNCTION, NOT_POSIX|NOT_OLD, 0, 0}, +{"function", Op_func, LEX_FUNCTION, NOT_OLD, 0, 0}, {"gensub", Op_sub_builtin, LEX_BUILTIN, GAWKX|A(3)|A(4), 0, 0}, {"getline", Op_K_getline_redir, LEX_GETLINE, NOT_OLD, 0, 0}, {"gsub", Op_sub_builtin, LEX_BUILTIN, NOT_OLD|A(2)|A(3), 0, 0}, @@ -4889,11 +5060,12 @@ mk_program() cp = end_block; else cp = list_merge(begin_block, end_block); - if (program_comment != NULL) { - (void) list_prepend(cp, program_comment); + + if (interblock_comment != NULL) { + (void) list_append(cp, interblock_comment); + interblock_comment = NULL; } - if (comment != NULL) - (void) list_append(cp, comment); + (void) list_append(cp, ip_atexit); (void) list_append(cp, instruction(Op_stop)); @@ -4926,12 +5098,16 @@ mk_program() if (begin_block != NULL) cp = list_merge(begin_block, cp); - if (program_comment != NULL) { - (void) list_prepend(cp, program_comment); + if (outer_comment != NULL) { + cp = list_merge(list_create(outer_comment), cp); + outer_comment = NULL; } - if (comment != NULL) { - (void) list_append(cp, comment); + + if (interblock_comment != NULL) { + (void) list_append(cp, interblock_comment); + interblock_comment = NULL; } + (void) list_append(cp, ip_atexit); (void) list_append(cp, instruction(Op_stop)); @@ -4939,10 +5115,6 @@ out: /* delete the Op_list, not needed */ tmp = cp->nexti; bcfree(cp); - /* these variables are not used again but zap them anyway. */ - comment = NULL; - function_comment = NULL; - program_comment = NULL; return tmp; #undef begin_block @@ -5117,33 +5289,35 @@ add_srcfile(enum srctype stype, char *src, SRCFILE *thisfile, bool *already_incl /* include_source --- read program from source included using `@include' */ -static int -include_source(INSTRUCTION *file) +static bool +include_source(INSTRUCTION *file, void **srcfile_p) { SRCFILE *s; char *src = file->lextok; int errcode; bool already_included; + *srcfile_p = NULL; + if (do_traditional || do_posix) { error_ln(file->source_line, _("@include is a gawk extension")); - return -1; + return false; } if (strlen(src) == 0) { if (do_lint) lintwarn_ln(file->source_line, _("empty filename after @include")); - return 0; + return true; } s = add_srcfile(SRC_INC, src, sourcefile, &already_included, &errcode); if (s == NULL) { if (already_included) - return 0; + return true; error_ln(file->source_line, _("can't open source file `%s' for reading (%s)"), src, errcode ? strerror(errcode) : _("reason unknown")); - return -1; + return false; } /* save scanner state for the current sourcefile */ @@ -5162,42 +5336,49 @@ include_source(INSTRUCTION *file) lasttok = 0; lexeof = false; eof_warned = false; - return 0; + *srcfile_p = (void *) s; + return true; } /* load_library --- load a shared library */ -static int -load_library(INSTRUCTION *file) +static bool +load_library(INSTRUCTION *file, void **srcfile_p) { SRCFILE *s; char *src = file->lextok; int errcode; bool already_included; + *srcfile_p = NULL; + if (do_traditional || do_posix) { error_ln(file->source_line, _("@load is a gawk extension")); - return -1; + return false; } + if (do_pretty_print && ! do_profile) + return true; + if (strlen(src) == 0) { if (do_lint) lintwarn_ln(file->source_line, _("empty filename after @load")); - return 0; + return true; } s = add_srcfile(SRC_EXTLIB, src, sourcefile, &already_included, &errcode); if (s == NULL) { if (already_included) - return 0; + return true; error_ln(file->source_line, _("can't open shared library `%s' for reading (%s)"), src, errcode ? strerror(errcode) : _("reason unknown")); - return -1; + return false; } load_ext(s->fullpath); - return 0; + *srcfile_p = (void *) s; + return true; } /* next_sourcefile --- read program from the next source in srcfiles */ @@ -5605,37 +5786,23 @@ pushback(void) (! lexeof && lexptr && lexptr > lexptr_begin ? lexptr-- : lexptr); } -/* check_comment --- check for block comment */ - -void -check_comment(void) -{ - if (comment != NULL) { - if (first_rule) { - program_comment = comment; - } else - block_comment = comment; - comment = NULL; - } - first_rule = false; -} - /* * get_comment --- collect comment text. * Flag = EOL_COMMENT for end-of-line comments. - * Flag = FULL_COMMENT for self-contained comments. + * Flag = BLOCK_COMMENT for self-contained comments. */ -int -get_comment(int flag) +static int +get_comment(enum commenttype flag, INSTRUCTION **comment_instruction) { int c; int sl; + char *p1; + char *p2; + tok = tokstart; tokadd('#'); sl = sourceline; - char *p1; - char *p2; while (true) { while ((c = nextc(false)) != '\n' && c != END_FILE) { @@ -5671,9 +5838,6 @@ get_comment(int flag) break; } - if (comment != NULL) - prior_comment = comment; - /* remove any trailing blank lines (consecutive \n) from comment */ p1 = tok - 1; p2 = tok - 2; @@ -5683,49 +5847,18 @@ get_comment(int flag) tok--; } - comment = bcalloc(Op_comment, 1, sl); - comment->source_file = source; - comment->memory = make_str_node(tokstart, tok - tokstart, 0); - comment->memory->comment_type = flag; + (*comment_instruction) = bcalloc(Op_comment, 1, sl); + (*comment_instruction)->source_file = source; + (*comment_instruction)->memory = make_str_node(tokstart, tok - tokstart, 0); + (*comment_instruction)->memory->comment_type = flag; return c; } -/* split_comment --- split initial comment text into program and function parts */ - -static void -split_comment(void) -{ - char *p; - int l; - NODE *n; - - p = comment_to_save->memory->stptr; - l = comment_to_save->memory->stlen - 3; - /* have at least two comments so split at last blank line (\n\n) */ - while (l >= 0) { - if (p[l] == '\n' && p[l+1] == '\n') { - function_comment = comment_to_save; - n = function_comment->memory; - function_comment->memory = make_string(p + l + 2, n->stlen - l - 2); - /* create program comment */ - program_comment = bcalloc(Op_comment, 1, sourceline); - program_comment->source_file = comment_to_save->source_file; - p[l + 2] = 0; - program_comment->memory = make_str_node(p, l + 2, 0); - comment_to_save = NULL; - freenode(n); - break; - } - else - l--; - } -} - /* allow_newline --- allow newline after &&, ||, ? and : */ static void -allow_newline(void) +allow_newline(INSTRUCTION **new_comment) { int c; @@ -5737,8 +5870,8 @@ allow_newline(void) } if (c == '#') { if (do_pretty_print && ! do_profile) { - /* collect comment byte code iff doing pretty print but not profiling. */ - c = get_comment(EOL_COMMENT); + /* collect comment byte code iff doing pretty print but not profiling. */ + c = get_comment(EOL_COMMENT, new_comment); } else { while ((c = nextc(false)) != '\n' && c != END_FILE) continue; @@ -5805,6 +5938,7 @@ yylex(void) bool intlstr = false; AWKNUM d; bool collecting_typed_regexp = false; + static int qm_col_count = 0; #define GET_INSTRUCTION(op) bcalloc(op, 1, sourceline) @@ -5969,18 +6103,25 @@ retry: return lasttok = NEWLINE; case '#': /* it's a comment */ + yylval = NULL; if (do_pretty_print && ! do_profile) { /* * Collect comment byte code iff doing pretty print * but not profiling. */ + INSTRUCTION *new_comment; + if (lasttok == NEWLINE || lasttok == 0) - c = get_comment(FULL_COMMENT); + c = get_comment(BLOCK_COMMENT, & new_comment); else - c = get_comment(EOL_COMMENT); + c = get_comment(EOL_COMMENT, & new_comment); - if (c == END_FILE) - return lasttok = NEWLINE_EOF; + yylval = new_comment; + + if (c == END_FILE) { + pushback(); + return lasttok = NEWLINE; + } } else { while ((c = nextc(false)) != '\n') { if (c == END_FILE) @@ -6009,7 +6150,10 @@ retry: * Use it at your own risk. We think it's a bad idea, which * is why it's not on by default. */ + yylval = NULL; if (! do_traditional) { + INSTRUCTION *new_comment; + /* strip trailing white-space and/or comment */ while ((c = nextc(true)) == ' ' || c == '\t' || c == '\r') continue; @@ -6021,9 +6165,11 @@ retry: lintwarn( _("use of `\\ #...' line continuation is not portable")); } - if (do_pretty_print && ! do_profile) - c = get_comment(EOL_COMMENT); - else { + if (do_pretty_print && ! do_profile) { + c = get_comment(EOL_COMMENT, & new_comment); + yylval = new_comment; + return lasttok = c; + } else { while ((c = nextc(false)) != '\n') if (c == END_FILE) break; @@ -6044,11 +6190,20 @@ retry: } break; - case ':': case '?': + qm_col_count++; + // fall through + case ':': yylval = GET_INSTRUCTION(Op_cond_exp); - if (! do_posix) - allow_newline(); + if (qm_col_count > 0) { + if (! do_posix) { + INSTRUCTION *new_comment = NULL; + allow_newline(& new_comment); + yylval->comment = new_comment; + } + if (c == ':') + qm_col_count--; + } return lasttok = c; /* @@ -6470,7 +6625,10 @@ retry: case '&': if ((c = nextc(true)) == '&') { yylval = GET_INSTRUCTION(Op_and); - allow_newline(); + INSTRUCTION *new_comment = NULL; + allow_newline(& new_comment); + yylval->comment = new_comment; + return lasttok = LEX_AND; } pushback(); @@ -6480,11 +6638,15 @@ retry: case '|': if ((c = nextc(true)) == '|') { yylval = GET_INSTRUCTION(Op_or); - allow_newline(); + INSTRUCTION *new_comment = NULL; + allow_newline(& new_comment); + yylval->comment = new_comment; + return lasttok = LEX_OR; } else if (! do_traditional && c == '&') { yylval = GET_INSTRUCTION(Op_symbol); yylval->redir_type = redirect_twoway; + return lasttok = (in_print && in_parens == 0 ? IO_OUT : IO_IN); } pushback(); @@ -6674,8 +6836,11 @@ out: yylval->lextok = tokkey; #define SMART_ALECK 1 - if (SMART_ALECK && do_lint - && ! goto_warned && strcasecmp(tokkey, "goto") == 0) { + if (SMART_ALECK + && do_lint + && ! goto_warned + && tolower(tokkey[0]) == 'g' + && strcasecmp(tokkey, "goto") == 0) { goto_warned = true; lintwarn(_("`goto' considered harmful!")); } @@ -7148,13 +7313,15 @@ mk_function(INSTRUCTION *fi, INSTRUCTION *def) /* add any pre-function comment to start of action for profile.c */ - if (function_comment != NULL) { - function_comment->source_line = 0; - (void) list_prepend(def, function_comment); - function_comment = NULL; + if (interblock_comment != NULL) { + interblock_comment->source_line = 0; + merge_comments(interblock_comment, fi->comment); + fi->comment = interblock_comment; + interblock_comment = NULL; } - /* add an implicit return at end; + /* + * Add an implicit return at end; * also used by 'return' command in debugger */ @@ -7162,6 +7329,11 @@ mk_function(INSTRUCTION *fi, INSTRUCTION *def) def->lasti->memory = dupnode(Nnull_string); (void) list_append(def, instruction(Op_K_return)); + if (trailing_comment != NULL) { + (void) list_append(def, trailing_comment); + trailing_comment = NULL; + } + if (do_pretty_print) (void) list_prepend(def, instruction(Op_exec_count)); @@ -7865,12 +8037,11 @@ append_rule(INSTRUCTION *pattern, INSTRUCTION *action) (rp + 1)->lasti = action->lasti; (rp + 2)->first_line = pattern->source_line; (rp + 2)->last_line = lastline; - if (block_comment != NULL) { - ip = list_prepend(list_prepend(action, block_comment), rp); - block_comment = NULL; - } else - ip = list_prepend(action, rp); - + ip = list_prepend(action, rp); + if (interblock_comment != NULL) { + ip = list_prepend(ip, interblock_comment); + interblock_comment = NULL; + } } else { rp = bcalloc(Op_rule, 3, 0); rp->in_rule = Rule; @@ -7896,14 +8067,20 @@ append_rule(INSTRUCTION *pattern, INSTRUCTION *action) (rp + 2)->last_line = find_line(pattern, LAST_LINE); action = list_create(instruction(Op_K_print_rec)); if (do_pretty_print) - (void) list_prepend(action, instruction(Op_exec_count)); + action = list_prepend(action, instruction(Op_exec_count)); } else (rp + 2)->last_line = lastline; if (do_pretty_print) { - (void) list_prepend(pattern, instruction(Op_exec_count)); - (void) list_prepend(action, instruction(Op_exec_count)); + pattern = list_prepend(pattern, instruction(Op_exec_count)); + action = list_prepend(action, instruction(Op_exec_count)); + } + + if (interblock_comment != NULL) { // was after previous action + pattern = list_prepend(pattern, interblock_comment); + interblock_comment = NULL; } + (rp + 1)->firsti = action->nexti; (rp + 1)->lasti = tp; ip = list_append( @@ -8275,8 +8452,9 @@ mk_for_loop(INSTRUCTION *forp, INSTRUCTION *init, INSTRUCTION *cond, forp->target_break = tbreak; forp->target_continue = tcont; ret = list_prepend(ret, forp); - } /* else - forp is NULL */ + } + /* else + forp is NULL */ return ret; } @@ -8490,26 +8668,6 @@ list_merge(INSTRUCTION *l1, INSTRUCTION *l2) return l1; } -/* add_pending_comment --- add a pending comment to a statement */ - -static inline INSTRUCTION * -add_pending_comment(INSTRUCTION *stmt) -{ - INSTRUCTION *ret = stmt; - - if (prior_comment != NULL) { - if (function_comment != prior_comment) - ret = list_append(stmt, prior_comment); - prior_comment = NULL; - } else if (comment != NULL && comment->memory->comment_type == EOL_COMMENT) { - if (function_comment != comment) - ret = list_append(stmt, comment); - comment = NULL; - } - - return ret; -} - /* See if name is a special token. */ int @@ -8749,3 +8907,91 @@ set_profile_text(NODE *n, const char *str, size_t len) return n; } + +/* + * merge_comments --- merge c2 into c1 and free c2 if successful. + * Allow c2 to be NULL, in which case just merged chained + * comments in c1. + */ + +static void +merge_comments(INSTRUCTION *c1, INSTRUCTION *c2) +{ + assert(c1->opcode == Op_comment); + + if (c1->comment == NULL && c2 == NULL) // nothing to do + return; + + size_t total = c1->memory->stlen; + if (c1->comment != NULL) + total += 1 /* \n */ + c1->comment->memory->stlen; + + if (c2 != NULL) { + assert(c2->opcode == Op_comment); + total += 1 /* \n */ + c2->memory->stlen; + if (c2->comment != NULL) + total += c2->comment->memory->stlen + 1; + } + + char *buffer; + emalloc(buffer, char *, total + 1, "merge_comments"); + + strcpy(buffer, c1->memory->stptr); + if (c1->comment != NULL) { + strcat(buffer, "\n"); + strcat(buffer, c1->comment->memory->stptr); + } + + if (c2 != NULL) { + strcat(buffer, "\n"); + strcat(buffer, c2->memory->stptr); + if (c2->comment != NULL) { + strcat(buffer, "\n"); + strcat(buffer, c2->comment->memory->stptr); + } + + unref(c2->memory); + if (c2->comment != NULL) { + unref(c2->comment->memory); + bcfree(c2->comment); + c2->comment = NULL; + } + bcfree(c2); + } + + c1->memory->comment_type = BLOCK_COMMENT; + free(c1->memory->stptr); + c1->memory->stptr = buffer; + c1->memory->stlen = strlen(buffer); + + // now free everything else + if (c1->comment != NULL) { + unref(c1->comment->memory); + bcfree(c1->comment); + c1->comment = NULL; + } +} + +/* make_braced_statements --- handle `l_brace statements r_brace' with comments */ + +static INSTRUCTION * +make_braced_statements(INSTRUCTION *lbrace, INSTRUCTION *stmts, INSTRUCTION *rbrace) +{ + INSTRUCTION *ip; + + if (stmts == NULL) + ip = list_create(instruction(Op_no_op)); + else + ip = stmts; + + if (lbrace != NULL) { + INSTRUCTION *comment2 = lbrace->comment; + if (comment2 != NULL) { + ip = list_prepend(ip, comment2); + lbrace->comment = NULL; + } + ip = list_prepend(ip, lbrace); + } + + return ip; +} |