aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-07-03 01:32:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-07-03 01:32:03 +0200
commit1f765709ed9c9595647853ac2cd7905f218c3044 (patch)
tree7abf7f55213c0e4ed7ec982ae9f56287e5657583
parent2b65e73db3254a7228802886546152c72217017d (diff)
downloadbusybox-w32-1f765709ed9c9595647853ac2cd7905f218c3044.tar.gz
busybox-w32-1f765709ed9c9595647853ac2cd7905f218c3044.tar.bz2
busybox-w32-1f765709ed9c9595647853ac2cd7905f218c3044.zip
awk: open-code TS_OPTERM, no logic changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/awk.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/editors/awk.c b/editors/awk.c
index c68416873..8c471d693 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -283,7 +283,6 @@ if ((n) & TC_NUMBER ) debug_printf_parse(" NUMBER" ); \
283 283
284#define TS_LVALUE (TC_VARIABLE | TC_ARRAY) 284#define TS_LVALUE (TC_VARIABLE | TC_ARRAY)
285#define TS_STATEMNT (TC_STATX | TC_WHILE) 285#define TS_STATEMNT (TC_STATX | TC_WHILE)
286#define TS_OPTERM (TC_SEMICOL | TC_NEWLINE)
287 286
288/* word tokens, cannot mean something else if not expected */ 287/* word tokens, cannot mean something else if not expected */
289#define TS_WORD (TC_IN | TS_STATEMNT | TC_ELSE \ 288#define TS_WORD (TC_IN | TS_STATEMNT | TC_ELSE \
@@ -291,13 +290,14 @@ if ((n) & TC_NUMBER ) debug_printf_parse(" NUMBER" ); \
291 | TC_FUNCDECL | TC_BEGIN | TC_END) 290 | TC_FUNCDECL | TC_BEGIN | TC_END)
292 291
293/* discard newlines after these */ 292/* discard newlines after these */
294#define TS_NOTERM (TC_COMMA | TC_LBRACE | TC_RBRACE \ 293#define TS_NOTERM (TS_BINOP | TC_COMMA | TC_LBRACE | TC_RBRACE \
295 | TS_BINOP | TS_OPTERM) 294 | TC_SEMICOL | TC_NEWLINE)
296 295
297/* what can expression begin with */ 296/* what can expression begin with */
298#define TS_OPSEQ (TS_OPERAND | TS_UOPPRE | TC_REGEXP) 297#define TS_OPSEQ (TS_OPERAND | TS_UOPPRE | TC_REGEXP)
299/* what can group begin with */ 298/* what can group begin with */
300#define TS_GRPSEQ (TS_OPSEQ | TS_OPTERM | TS_STATEMNT | TC_LBRACE) 299#define TS_GRPSEQ (TS_OPSEQ | TS_STATEMNT \
300 | TC_SEMICOL | TC_NEWLINE | TC_LBRACE)
301 301
302/* if previous token class is CONCAT_L and next is CONCAT_R, concatenation */ 302/* if previous token class is CONCAT_L and next is CONCAT_R, concatenation */
303/* operator is inserted between them */ 303/* operator is inserted between them */
@@ -642,7 +642,7 @@ struct globals2 {
642#define g_buf (G.g_buf ) 642#define g_buf (G.g_buf )
643#define INIT_G() do { \ 643#define INIT_G() do { \
644 SET_PTR_TO_GLOBALS((char*)xzalloc(sizeof(G1)+sizeof(G)) + sizeof(G1)); \ 644 SET_PTR_TO_GLOBALS((char*)xzalloc(sizeof(G1)+sizeof(G)) + sizeof(G1)); \
645 t_tclass = TS_OPTERM; \ 645 t_tclass = TC_NEWLINE; \
646 G.evaluate__seed = 1; \ 646 G.evaluate__seed = 1; \
647} while (0) 647} while (0)
648 648
@@ -1090,7 +1090,7 @@ static uint32_t next_token(uint32_t expected)
1090 const uint32_t *ti; 1090 const uint32_t *ti;
1091 uint32_t tc, last_token_class; 1091 uint32_t tc, last_token_class;
1092 1092
1093 last_token_class = t_tclass; /* t_tclass is initialized to TS_OPTERM */ 1093 last_token_class = t_tclass; /* t_tclass is initialized to TC_NEWLINE */
1094 1094
1095 debug_printf_parse("%s() expected(%x):", __func__, expected); 1095 debug_printf_parse("%s() expected(%x):", __func__, expected);
1096 debug_parse_print_tc(expected); 1096 debug_parse_print_tc(expected);
@@ -1470,7 +1470,8 @@ static node *parse_expr(uint32_t term_tc)
1470 case TC_LENGTH: 1470 case TC_LENGTH:
1471 debug_printf_parse("%s: TC_LENGTH\n", __func__); 1471 debug_printf_parse("%s: TC_LENGTH\n", __func__);
1472 tc = next_token(TC_LPAREN /* length(...) */ 1472 tc = next_token(TC_LPAREN /* length(...) */
1473 | TS_OPTERM /* length; (or newline)*/ 1473 | TC_SEMICOL /* length; */
1474 | TC_NEWLINE /* length<newline> */
1474 | TC_RBRACE /* length } */ 1475 | TC_RBRACE /* length } */
1475 | TC_BINOPX /* length <op> NUM */ 1476 | TC_BINOPX /* length <op> NUM */
1476 | TC_COMMA /* print length, 1 */ 1477 | TC_COMMA /* print length, 1 */
@@ -1516,7 +1517,7 @@ static void chain_expr(uint32_t info)
1516 1517
1517 n = chain_node(info); 1518 n = chain_node(info);
1518 1519
1519 n->l.n = parse_expr(TS_OPTERM | TC_RBRACE); 1520 n->l.n = parse_expr(TC_SEMICOL | TC_NEWLINE | TC_RBRACE);
1520 if ((info & OF_REQUIRED) && !n->l.n) 1521 if ((info & OF_REQUIRED) && !n->l.n)
1521 syntax_error(EMSG_TOO_FEW_ARGS); 1522 syntax_error(EMSG_TOO_FEW_ARGS);
1522 1523
@@ -1577,8 +1578,8 @@ static void chain_group(void)
1577 chain_until_rbrace(); 1578 chain_until_rbrace();
1578 return; 1579 return;
1579 } 1580 }
1580 if (tc & (TS_OPSEQ | TS_OPTERM)) { 1581 if (tc & (TS_OPSEQ | TC_SEMICOL | TC_NEWLINE)) {
1581 debug_printf_parse("%s: TS_OPSEQ | TS_OPTERM\n", __func__); 1582 debug_printf_parse("%s: TS_OPSEQ | TC_SEMICOL | TC_NEWLINE\n", __func__);
1582 rollback_token(); 1583 rollback_token();
1583 chain_expr(OC_EXEC | Vx); 1584 chain_expr(OC_EXEC | Vx);
1584 return; 1585 return;
@@ -1647,10 +1648,10 @@ static void chain_group(void)
1647 case OC_PRINTF: 1648 case OC_PRINTF:
1648 debug_printf_parse("%s: OC_PRINT[F]\n", __func__); 1649 debug_printf_parse("%s: OC_PRINT[F]\n", __func__);
1649 n = chain_node(t_info); 1650 n = chain_node(t_info);
1650 n->l.n = parse_expr(TS_OPTERM | TC_OUTRDR | TC_RBRACE); 1651 n->l.n = parse_expr(TC_SEMICOL | TC_NEWLINE | TC_OUTRDR | TC_RBRACE);
1651 if (t_tclass & TC_OUTRDR) { 1652 if (t_tclass & TC_OUTRDR) {
1652 n->info |= t_info; 1653 n->info |= t_info;
1653 n->r.n = parse_expr(TS_OPTERM | TC_RBRACE); 1654 n->r.n = parse_expr(TC_SEMICOL | TC_NEWLINE | TC_RBRACE);
1654 } 1655 }
1655 if (t_tclass & TC_RBRACE) 1656 if (t_tclass & TC_RBRACE)
1656 rollback_token(); 1657 rollback_token();
@@ -1689,14 +1690,14 @@ static void parse_program(char *p)
1689 uint32_t tclass; 1690 uint32_t tclass;
1690 1691
1691 tclass = next_token(TC_EOF | TS_OPSEQ | TC_LBRACE | 1692 tclass = next_token(TC_EOF | TS_OPSEQ | TC_LBRACE |
1692 TS_OPTERM | TC_BEGIN | TC_END | TC_FUNCDECL); 1693 TC_SEMICOL | TC_NEWLINE | TC_BEGIN | TC_END | TC_FUNCDECL);
1693 1694
1694 if (tclass == TC_EOF) { 1695 if (tclass == TC_EOF) {
1695 debug_printf_parse("%s: TC_EOF\n", __func__); 1696 debug_printf_parse("%s: TC_EOF\n", __func__);
1696 break; 1697 break;
1697 } 1698 }
1698 if (tclass & TS_OPTERM) { /* ; or <newline> */ 1699 if (tclass & (TC_SEMICOL | TC_NEWLINE)) {
1699 debug_printf_parse("%s: TS_OPTERM\n", __func__); 1700 debug_printf_parse("%s: TC_SEMICOL | TC_NEWLINE\n", __func__);
1700//NB: gawk allows many newlines, but does not allow more than one semicolon: 1701//NB: gawk allows many newlines, but does not allow more than one semicolon:
1701// BEGIN {...}<newline>;<newline>; 1702// BEGIN {...}<newline>;<newline>;
1702//would complain "each rule must have a pattern or an action part". 1703//would complain "each rule must have a pattern or an action part".
@@ -1762,7 +1763,7 @@ static void parse_program(char *p)
1762 debug_printf_parse("%s: TS_OPSEQ\n", __func__); 1763 debug_printf_parse("%s: TS_OPSEQ\n", __func__);
1763 rollback_token(); 1764 rollback_token();
1764 cn = chain_node(OC_TEST); 1765 cn = chain_node(OC_TEST);
1765 cn->l.n = parse_expr(TS_OPTERM | TC_EOF | TC_LBRACE); 1766 cn->l.n = parse_expr(TC_SEMICOL | TC_NEWLINE | TC_EOF | TC_LBRACE);
1766 if (t_tclass == TC_LBRACE) { 1767 if (t_tclass == TC_LBRACE) {
1767 debug_printf_parse("%s: TC_LBRACE\n", __func__); 1768 debug_printf_parse("%s: TC_LBRACE\n", __func__);
1768 rollback_token(); 1769 rollback_token();