15ea9e707SThomas Veerman #if HAVE_NBTOOL_CONFIG_H
25ea9e707SThomas Veerman #include "nbtool_config.h"
35ea9e707SThomas Veerman #endif
45ea9e707SThomas Veerman
55ea9e707SThomas Veerman #include <stdio.h>
65ea9e707SThomas Veerman #include "awk.h"
75ea9e707SThomas Veerman #include "awkgram.h"
85ea9e707SThomas Veerman
95ea9e707SThomas Veerman static const char * const printname[94] = {
10*84d9c625SLionel Sambuc "FIRSTTOKEN", /* 57346 */
11*84d9c625SLionel Sambuc "PROGRAM", /* 57347 */
12*84d9c625SLionel Sambuc "PASTAT", /* 57348 */
13*84d9c625SLionel Sambuc "PASTAT2", /* 57349 */
14*84d9c625SLionel Sambuc "XBEGIN", /* 57350 */
15*84d9c625SLionel Sambuc "XEND", /* 57351 */
16*84d9c625SLionel Sambuc "NL", /* 57352 */
17*84d9c625SLionel Sambuc "ARRAY", /* 57353 */
18*84d9c625SLionel Sambuc "MATCH", /* 57354 */
19*84d9c625SLionel Sambuc "NOTMATCH", /* 57355 */
20*84d9c625SLionel Sambuc "MATCHOP", /* 57356 */
21*84d9c625SLionel Sambuc "FINAL", /* 57357 */
22*84d9c625SLionel Sambuc "DOT", /* 57358 */
23*84d9c625SLionel Sambuc "ALL", /* 57359 */
24*84d9c625SLionel Sambuc "CCL", /* 57360 */
25*84d9c625SLionel Sambuc "NCCL", /* 57361 */
26*84d9c625SLionel Sambuc "CHAR", /* 57362 */
27*84d9c625SLionel Sambuc "OR", /* 57363 */
28*84d9c625SLionel Sambuc "STAR", /* 57364 */
29*84d9c625SLionel Sambuc "QUEST", /* 57365 */
30*84d9c625SLionel Sambuc "PLUS", /* 57366 */
31*84d9c625SLionel Sambuc "EMPTYRE", /* 57367 */
32*84d9c625SLionel Sambuc "AND", /* 57368 */
33*84d9c625SLionel Sambuc "BOR", /* 57369 */
34*84d9c625SLionel Sambuc "APPEND", /* 57370 */
35*84d9c625SLionel Sambuc "EQ", /* 57371 */
36*84d9c625SLionel Sambuc "GE", /* 57372 */
37*84d9c625SLionel Sambuc "GT", /* 57373 */
38*84d9c625SLionel Sambuc "LE", /* 57374 */
39*84d9c625SLionel Sambuc "LT", /* 57375 */
40*84d9c625SLionel Sambuc "NE", /* 57376 */
41*84d9c625SLionel Sambuc "IN", /* 57377 */
42*84d9c625SLionel Sambuc "ARG", /* 57378 */
43*84d9c625SLionel Sambuc "BLTIN", /* 57379 */
44*84d9c625SLionel Sambuc "BREAK", /* 57380 */
45*84d9c625SLionel Sambuc "CLOSE", /* 57381 */
46*84d9c625SLionel Sambuc "CONTINUE", /* 57382 */
47*84d9c625SLionel Sambuc "DELETE", /* 57383 */
48*84d9c625SLionel Sambuc "DO", /* 57384 */
49*84d9c625SLionel Sambuc "EXIT", /* 57385 */
50*84d9c625SLionel Sambuc "FOR", /* 57386 */
51*84d9c625SLionel Sambuc "FUNC", /* 57387 */
52*84d9c625SLionel Sambuc "SUB", /* 57388 */
53*84d9c625SLionel Sambuc "GSUB", /* 57389 */
54*84d9c625SLionel Sambuc "IF", /* 57390 */
55*84d9c625SLionel Sambuc "INDEX", /* 57391 */
56*84d9c625SLionel Sambuc "LSUBSTR", /* 57392 */
57*84d9c625SLionel Sambuc "MATCHFCN", /* 57393 */
58*84d9c625SLionel Sambuc "NEXT", /* 57394 */
59*84d9c625SLionel Sambuc "NEXTFILE", /* 57395 */
60*84d9c625SLionel Sambuc "ADD", /* 57396 */
61*84d9c625SLionel Sambuc "MINUS", /* 57397 */
62*84d9c625SLionel Sambuc "MULT", /* 57398 */
63*84d9c625SLionel Sambuc "DIVIDE", /* 57399 */
64*84d9c625SLionel Sambuc "MOD", /* 57400 */
65*84d9c625SLionel Sambuc "ASSIGN", /* 57401 */
66*84d9c625SLionel Sambuc "ASGNOP", /* 57402 */
67*84d9c625SLionel Sambuc "ADDEQ", /* 57403 */
68*84d9c625SLionel Sambuc "SUBEQ", /* 57404 */
69*84d9c625SLionel Sambuc "MULTEQ", /* 57405 */
70*84d9c625SLionel Sambuc "DIVEQ", /* 57406 */
71*84d9c625SLionel Sambuc "MODEQ", /* 57407 */
72*84d9c625SLionel Sambuc "POWEQ", /* 57408 */
73*84d9c625SLionel Sambuc "PRINT", /* 57409 */
74*84d9c625SLionel Sambuc "PRINTF", /* 57410 */
75*84d9c625SLionel Sambuc "SPRINTF", /* 57411 */
76*84d9c625SLionel Sambuc "ELSE", /* 57412 */
77*84d9c625SLionel Sambuc "INTEST", /* 57413 */
78*84d9c625SLionel Sambuc "CONDEXPR", /* 57414 */
79*84d9c625SLionel Sambuc "POSTINCR", /* 57415 */
80*84d9c625SLionel Sambuc "PREINCR", /* 57416 */
81*84d9c625SLionel Sambuc "POSTDECR", /* 57417 */
82*84d9c625SLionel Sambuc "PREDECR", /* 57418 */
83*84d9c625SLionel Sambuc "VAR", /* 57419 */
84*84d9c625SLionel Sambuc "IVAR", /* 57420 */
85*84d9c625SLionel Sambuc "VARNF", /* 57421 */
86*84d9c625SLionel Sambuc "CALL", /* 57422 */
87*84d9c625SLionel Sambuc "NUMBER", /* 57423 */
88*84d9c625SLionel Sambuc "STRING", /* 57424 */
89*84d9c625SLionel Sambuc "REGEXPR", /* 57425 */
90*84d9c625SLionel Sambuc "GETLINE", /* 57426 */
91*84d9c625SLionel Sambuc "GENSUB", /* 57427 */
92*84d9c625SLionel Sambuc "RETURN", /* 57428 */
93*84d9c625SLionel Sambuc "SPLIT", /* 57429 */
94*84d9c625SLionel Sambuc "SUBSTR", /* 57430 */
95*84d9c625SLionel Sambuc "WHILE", /* 57431 */
96*84d9c625SLionel Sambuc "CAT", /* 57432 */
97*84d9c625SLionel Sambuc "NOT", /* 57433 */
98*84d9c625SLionel Sambuc "UMINUS", /* 57434 */
99*84d9c625SLionel Sambuc "POWER", /* 57435 */
100*84d9c625SLionel Sambuc "DECR", /* 57436 */
101*84d9c625SLionel Sambuc "INCR", /* 57437 */
102*84d9c625SLionel Sambuc "INDIRECT", /* 57438 */
103*84d9c625SLionel Sambuc "LASTTOKEN", /* 57439 */
1045ea9e707SThomas Veerman };
1055ea9e707SThomas Veerman
1065ea9e707SThomas Veerman
1075ea9e707SThomas Veerman Cell *(*proctab[94])(Node **, int) = {
1085ea9e707SThomas Veerman nullproc, /* FIRSTTOKEN */
1095ea9e707SThomas Veerman program, /* PROGRAM */
1105ea9e707SThomas Veerman pastat, /* PASTAT */
1115ea9e707SThomas Veerman dopa2, /* PASTAT2 */
1125ea9e707SThomas Veerman nullproc, /* XBEGIN */
1135ea9e707SThomas Veerman nullproc, /* XEND */
1145ea9e707SThomas Veerman nullproc, /* NL */
1155ea9e707SThomas Veerman array, /* ARRAY */
1165ea9e707SThomas Veerman matchop, /* MATCH */
1175ea9e707SThomas Veerman matchop, /* NOTMATCH */
1185ea9e707SThomas Veerman nullproc, /* MATCHOP */
1195ea9e707SThomas Veerman nullproc, /* FINAL */
1205ea9e707SThomas Veerman nullproc, /* DOT */
1215ea9e707SThomas Veerman nullproc, /* ALL */
1225ea9e707SThomas Veerman nullproc, /* CCL */
1235ea9e707SThomas Veerman nullproc, /* NCCL */
1245ea9e707SThomas Veerman nullproc, /* CHAR */
1255ea9e707SThomas Veerman nullproc, /* OR */
1265ea9e707SThomas Veerman nullproc, /* STAR */
1275ea9e707SThomas Veerman nullproc, /* QUEST */
1285ea9e707SThomas Veerman nullproc, /* PLUS */
1295ea9e707SThomas Veerman nullproc, /* EMPTYRE */
1305ea9e707SThomas Veerman boolop, /* AND */
1315ea9e707SThomas Veerman boolop, /* BOR */
1325ea9e707SThomas Veerman nullproc, /* APPEND */
1335ea9e707SThomas Veerman relop, /* EQ */
1345ea9e707SThomas Veerman relop, /* GE */
1355ea9e707SThomas Veerman relop, /* GT */
1365ea9e707SThomas Veerman relop, /* LE */
1375ea9e707SThomas Veerman relop, /* LT */
1385ea9e707SThomas Veerman relop, /* NE */
1395ea9e707SThomas Veerman instat, /* IN */
1405ea9e707SThomas Veerman arg, /* ARG */
1415ea9e707SThomas Veerman bltin, /* BLTIN */
1425ea9e707SThomas Veerman jump, /* BREAK */
1435ea9e707SThomas Veerman closefile, /* CLOSE */
1445ea9e707SThomas Veerman jump, /* CONTINUE */
1455ea9e707SThomas Veerman awkdelete, /* DELETE */
1465ea9e707SThomas Veerman dostat, /* DO */
1475ea9e707SThomas Veerman jump, /* EXIT */
1485ea9e707SThomas Veerman forstat, /* FOR */
1495ea9e707SThomas Veerman nullproc, /* FUNC */
1505ea9e707SThomas Veerman sub, /* SUB */
1515ea9e707SThomas Veerman gsub, /* GSUB */
1525ea9e707SThomas Veerman ifstat, /* IF */
1535ea9e707SThomas Veerman sindex, /* INDEX */
1545ea9e707SThomas Veerman nullproc, /* LSUBSTR */
1555ea9e707SThomas Veerman matchop, /* MATCHFCN */
1565ea9e707SThomas Veerman jump, /* NEXT */
1575ea9e707SThomas Veerman jump, /* NEXTFILE */
1585ea9e707SThomas Veerman arith, /* ADD */
1595ea9e707SThomas Veerman arith, /* MINUS */
1605ea9e707SThomas Veerman arith, /* MULT */
1615ea9e707SThomas Veerman arith, /* DIVIDE */
1625ea9e707SThomas Veerman arith, /* MOD */
1635ea9e707SThomas Veerman assign, /* ASSIGN */
1645ea9e707SThomas Veerman nullproc, /* ASGNOP */
1655ea9e707SThomas Veerman assign, /* ADDEQ */
1665ea9e707SThomas Veerman assign, /* SUBEQ */
1675ea9e707SThomas Veerman assign, /* MULTEQ */
1685ea9e707SThomas Veerman assign, /* DIVEQ */
1695ea9e707SThomas Veerman assign, /* MODEQ */
1705ea9e707SThomas Veerman assign, /* POWEQ */
1715ea9e707SThomas Veerman printstat, /* PRINT */
1725ea9e707SThomas Veerman awkprintf, /* PRINTF */
1735ea9e707SThomas Veerman awksprintf, /* SPRINTF */
1745ea9e707SThomas Veerman nullproc, /* ELSE */
1755ea9e707SThomas Veerman intest, /* INTEST */
1765ea9e707SThomas Veerman condexpr, /* CONDEXPR */
1775ea9e707SThomas Veerman incrdecr, /* POSTINCR */
1785ea9e707SThomas Veerman incrdecr, /* PREINCR */
1795ea9e707SThomas Veerman incrdecr, /* POSTDECR */
1805ea9e707SThomas Veerman incrdecr, /* PREDECR */
1815ea9e707SThomas Veerman nullproc, /* VAR */
1825ea9e707SThomas Veerman nullproc, /* IVAR */
1835ea9e707SThomas Veerman getnf, /* VARNF */
1845ea9e707SThomas Veerman call, /* CALL */
1855ea9e707SThomas Veerman nullproc, /* NUMBER */
1865ea9e707SThomas Veerman nullproc, /* STRING */
1875ea9e707SThomas Veerman nullproc, /* REGEXPR */
1885ea9e707SThomas Veerman awkgetline, /* GETLINE */
1895ea9e707SThomas Veerman gensub, /* GENSUB */
1905ea9e707SThomas Veerman jump, /* RETURN */
1915ea9e707SThomas Veerman split, /* SPLIT */
1925ea9e707SThomas Veerman substr, /* SUBSTR */
1935ea9e707SThomas Veerman whilestat, /* WHILE */
1945ea9e707SThomas Veerman cat, /* CAT */
1955ea9e707SThomas Veerman boolop, /* NOT */
1965ea9e707SThomas Veerman arith, /* UMINUS */
1975ea9e707SThomas Veerman arith, /* POWER */
1985ea9e707SThomas Veerman nullproc, /* DECR */
1995ea9e707SThomas Veerman nullproc, /* INCR */
2005ea9e707SThomas Veerman indirect, /* INDIRECT */
2015ea9e707SThomas Veerman nullproc, /* LASTTOKEN */
2025ea9e707SThomas Veerman };
2035ea9e707SThomas Veerman
tokname(int n)2045ea9e707SThomas Veerman const char *tokname(int n)
2055ea9e707SThomas Veerman {
2065ea9e707SThomas Veerman static char buf[100];
2075ea9e707SThomas Veerman
2085ea9e707SThomas Veerman if (n < FIRSTTOKEN || n > LASTTOKEN) {
2095ea9e707SThomas Veerman snprintf(buf, sizeof(buf), "token %d", n);
2105ea9e707SThomas Veerman return buf;
2115ea9e707SThomas Veerman }
2125ea9e707SThomas Veerman return printname[n-FIRSTTOKEN];
2135ea9e707SThomas Veerman }
214