xref: /netbsd/external/historical/nawk/dist/proctab.c (revision 1def8acd)
135f471cbSchristos #include <stdio.h>
235f471cbSchristos #include "awk.h"
3*1def8acdSchristos #include "ytab.h"
435f471cbSchristos 
5*1def8acdSchristos static const char * const printname[96] = {
6*1def8acdSchristos 	"FIRSTTOKEN",	/* 257 */
7*1def8acdSchristos 	"PROGRAM",	/* 258 */
8*1def8acdSchristos 	"PASTAT",	/* 259 */
9*1def8acdSchristos 	"PASTAT2",	/* 260 */
10*1def8acdSchristos 	"XBEGIN",	/* 261 */
11*1def8acdSchristos 	"XEND",	/* 262 */
12*1def8acdSchristos 	"NL",	/* 263 */
13*1def8acdSchristos 	"ARRAY",	/* 264 */
14*1def8acdSchristos 	"MATCH",	/* 265 */
15*1def8acdSchristos 	"NOTMATCH",	/* 266 */
16*1def8acdSchristos 	"MATCHOP",	/* 267 */
17*1def8acdSchristos 	"FINAL",	/* 268 */
18*1def8acdSchristos 	"DOT",	/* 269 */
19*1def8acdSchristos 	"ALL",	/* 270 */
20*1def8acdSchristos 	"CCL",	/* 271 */
21*1def8acdSchristos 	"NCCL",	/* 272 */
22*1def8acdSchristos 	"CHAR",	/* 273 */
23*1def8acdSchristos 	"OR",	/* 274 */
24*1def8acdSchristos 	"STAR",	/* 275 */
25*1def8acdSchristos 	"QUEST",	/* 276 */
26*1def8acdSchristos 	"PLUS",	/* 277 */
27*1def8acdSchristos 	"EMPTYRE",	/* 278 */
28*1def8acdSchristos 	"ZERO",	/* 279 */
29*1def8acdSchristos 	"AND",	/* 280 */
30*1def8acdSchristos 	"BOR",	/* 281 */
31*1def8acdSchristos 	"APPEND",	/* 282 */
32*1def8acdSchristos 	"EQ",	/* 283 */
33*1def8acdSchristos 	"GE",	/* 284 */
34*1def8acdSchristos 	"GT",	/* 285 */
35*1def8acdSchristos 	"LE",	/* 286 */
36*1def8acdSchristos 	"LT",	/* 287 */
37*1def8acdSchristos 	"NE",	/* 288 */
38*1def8acdSchristos 	"IN",	/* 289 */
39*1def8acdSchristos 	"ARG",	/* 290 */
40*1def8acdSchristos 	"BLTIN",	/* 291 */
41*1def8acdSchristos 	"BREAK",	/* 292 */
42*1def8acdSchristos 	"CLOSE",	/* 293 */
43*1def8acdSchristos 	"CONTINUE",	/* 294 */
44*1def8acdSchristos 	"DELETE",	/* 295 */
45*1def8acdSchristos 	"DO",	/* 296 */
46*1def8acdSchristos 	"EXIT",	/* 297 */
47*1def8acdSchristos 	"FOR",	/* 298 */
48*1def8acdSchristos 	"FUNC",	/* 299 */
49*1def8acdSchristos 	"GENSUB",	/* 300 */
508eaba782Schristos 	"SUB",	/* 301 */
518eaba782Schristos 	"GSUB",	/* 302 */
528eaba782Schristos 	"IF",	/* 303 */
538eaba782Schristos 	"INDEX",	/* 304 */
548eaba782Schristos 	"LSUBSTR",	/* 305 */
558eaba782Schristos 	"MATCHFCN",	/* 306 */
568eaba782Schristos 	"NEXT",	/* 307 */
578eaba782Schristos 	"NEXTFILE",	/* 308 */
588eaba782Schristos 	"ADD",	/* 309 */
598eaba782Schristos 	"MINUS",	/* 310 */
608eaba782Schristos 	"MULT",	/* 311 */
618eaba782Schristos 	"DIVIDE",	/* 312 */
628eaba782Schristos 	"MOD",	/* 313 */
638eaba782Schristos 	"ASSIGN",	/* 314 */
648eaba782Schristos 	"ASGNOP",	/* 315 */
658eaba782Schristos 	"ADDEQ",	/* 316 */
668eaba782Schristos 	"SUBEQ",	/* 317 */
678eaba782Schristos 	"MULTEQ",	/* 318 */
688eaba782Schristos 	"DIVEQ",	/* 319 */
698eaba782Schristos 	"MODEQ",	/* 320 */
708eaba782Schristos 	"POWEQ",	/* 321 */
718eaba782Schristos 	"PRINT",	/* 322 */
728eaba782Schristos 	"PRINTF",	/* 323 */
738eaba782Schristos 	"SPRINTF",	/* 324 */
748eaba782Schristos 	"ELSE",	/* 325 */
758eaba782Schristos 	"INTEST",	/* 326 */
768eaba782Schristos 	"CONDEXPR",	/* 327 */
778eaba782Schristos 	"POSTINCR",	/* 328 */
788eaba782Schristos 	"PREINCR",	/* 329 */
798eaba782Schristos 	"POSTDECR",	/* 330 */
808eaba782Schristos 	"PREDECR",	/* 331 */
818eaba782Schristos 	"VAR",	/* 332 */
828eaba782Schristos 	"IVAR",	/* 333 */
838eaba782Schristos 	"VARNF",	/* 334 */
848eaba782Schristos 	"CALL",	/* 335 */
858eaba782Schristos 	"NUMBER",	/* 336 */
868eaba782Schristos 	"STRING",	/* 337 */
878eaba782Schristos 	"REGEXPR",	/* 338 */
888eaba782Schristos 	"GETLINE",	/* 339 */
898eaba782Schristos 	"RETURN",	/* 340 */
908eaba782Schristos 	"SPLIT",	/* 341 */
918eaba782Schristos 	"SUBSTR",	/* 342 */
928eaba782Schristos 	"WHILE",	/* 343 */
938eaba782Schristos 	"CAT",	/* 344 */
948eaba782Schristos 	"NOT",	/* 345 */
958eaba782Schristos 	"UMINUS",	/* 346 */
968eaba782Schristos 	"UPLUS",	/* 347 */
978eaba782Schristos 	"POWER",	/* 348 */
988eaba782Schristos 	"DECR",	/* 349 */
998eaba782Schristos 	"INCR",	/* 350 */
1008eaba782Schristos 	"INDIRECT",	/* 351 */
1018eaba782Schristos 	"LASTTOKEN",	/* 352 */
10235f471cbSchristos };
10335f471cbSchristos 
10435f471cbSchristos 
105*1def8acdSchristos Cell *(*proctab[96])(Node **, int) = {
10635f471cbSchristos 	nullproc,	/* FIRSTTOKEN */
10735f471cbSchristos 	program,	/* PROGRAM */
10835f471cbSchristos 	pastat,	/* PASTAT */
10935f471cbSchristos 	dopa2,	/* PASTAT2 */
11035f471cbSchristos 	nullproc,	/* XBEGIN */
11135f471cbSchristos 	nullproc,	/* XEND */
11235f471cbSchristos 	nullproc,	/* NL */
11335f471cbSchristos 	array,	/* ARRAY */
11435f471cbSchristos 	matchop,	/* MATCH */
11535f471cbSchristos 	matchop,	/* NOTMATCH */
11635f471cbSchristos 	nullproc,	/* MATCHOP */
11735f471cbSchristos 	nullproc,	/* FINAL */
11835f471cbSchristos 	nullproc,	/* DOT */
11935f471cbSchristos 	nullproc,	/* ALL */
12035f471cbSchristos 	nullproc,	/* CCL */
12135f471cbSchristos 	nullproc,	/* NCCL */
12235f471cbSchristos 	nullproc,	/* CHAR */
12335f471cbSchristos 	nullproc,	/* OR */
12435f471cbSchristos 	nullproc,	/* STAR */
12535f471cbSchristos 	nullproc,	/* QUEST */
12635f471cbSchristos 	nullproc,	/* PLUS */
12735f471cbSchristos 	nullproc,	/* EMPTYRE */
1288eaba782Schristos 	nullproc,	/* ZERO */
12935f471cbSchristos 	boolop,	/* AND */
13035f471cbSchristos 	boolop,	/* BOR */
13135f471cbSchristos 	nullproc,	/* APPEND */
13235f471cbSchristos 	relop,	/* EQ */
13335f471cbSchristos 	relop,	/* GE */
13435f471cbSchristos 	relop,	/* GT */
13535f471cbSchristos 	relop,	/* LE */
13635f471cbSchristos 	relop,	/* LT */
13735f471cbSchristos 	relop,	/* NE */
13835f471cbSchristos 	instat,	/* IN */
13935f471cbSchristos 	arg,	/* ARG */
14035f471cbSchristos 	bltin,	/* BLTIN */
14135f471cbSchristos 	jump,	/* BREAK */
14235f471cbSchristos 	closefile,	/* CLOSE */
14335f471cbSchristos 	jump,	/* CONTINUE */
14435f471cbSchristos 	awkdelete,	/* DELETE */
14535f471cbSchristos 	dostat,	/* DO */
14635f471cbSchristos 	jump,	/* EXIT */
14735f471cbSchristos 	forstat,	/* FOR */
14835f471cbSchristos 	nullproc,	/* FUNC */
149*1def8acdSchristos 	gensub,	/* GENSUB */
15035f471cbSchristos 	sub,	/* SUB */
15135f471cbSchristos 	gsub,	/* GSUB */
15235f471cbSchristos 	ifstat,	/* IF */
15335f471cbSchristos 	sindex,	/* INDEX */
15435f471cbSchristos 	nullproc,	/* LSUBSTR */
15535f471cbSchristos 	matchop,	/* MATCHFCN */
15635f471cbSchristos 	jump,	/* NEXT */
15735f471cbSchristos 	jump,	/* NEXTFILE */
15835f471cbSchristos 	arith,	/* ADD */
15935f471cbSchristos 	arith,	/* MINUS */
16035f471cbSchristos 	arith,	/* MULT */
16135f471cbSchristos 	arith,	/* DIVIDE */
16235f471cbSchristos 	arith,	/* MOD */
16335f471cbSchristos 	assign,	/* ASSIGN */
16435f471cbSchristos 	nullproc,	/* ASGNOP */
16535f471cbSchristos 	assign,	/* ADDEQ */
16635f471cbSchristos 	assign,	/* SUBEQ */
16735f471cbSchristos 	assign,	/* MULTEQ */
16835f471cbSchristos 	assign,	/* DIVEQ */
16935f471cbSchristos 	assign,	/* MODEQ */
17035f471cbSchristos 	assign,	/* POWEQ */
17135f471cbSchristos 	printstat,	/* PRINT */
17235f471cbSchristos 	awkprintf,	/* PRINTF */
17335f471cbSchristos 	awksprintf,	/* SPRINTF */
17435f471cbSchristos 	nullproc,	/* ELSE */
17535f471cbSchristos 	intest,	/* INTEST */
17635f471cbSchristos 	condexpr,	/* CONDEXPR */
17735f471cbSchristos 	incrdecr,	/* POSTINCR */
17835f471cbSchristos 	incrdecr,	/* PREINCR */
17935f471cbSchristos 	incrdecr,	/* POSTDECR */
18035f471cbSchristos 	incrdecr,	/* PREDECR */
18135f471cbSchristos 	nullproc,	/* VAR */
18235f471cbSchristos 	nullproc,	/* IVAR */
18335f471cbSchristos 	getnf,	/* VARNF */
18435f471cbSchristos 	call,	/* CALL */
18535f471cbSchristos 	nullproc,	/* NUMBER */
18635f471cbSchristos 	nullproc,	/* STRING */
18735f471cbSchristos 	nullproc,	/* REGEXPR */
18835f471cbSchristos 	awkgetline,	/* GETLINE */
18935f471cbSchristos 	jump,	/* RETURN */
19039562c1eSchristos 	split,	/* SPLIT */
19139562c1eSchristos 	substr,	/* SUBSTR */
19235f471cbSchristos 	whilestat,	/* WHILE */
19335f471cbSchristos 	cat,	/* CAT */
19435f471cbSchristos 	boolop,	/* NOT */
1955642d004Schristos 	arith,	/* UMINUS */
1968eaba782Schristos 	arith,	/* UPLUS */
19735f471cbSchristos 	arith,	/* POWER */
19835f471cbSchristos 	nullproc,	/* DECR */
1995642d004Schristos 	nullproc,	/* INCR */
20035f471cbSchristos 	indirect,	/* INDIRECT */
20135f471cbSchristos 	nullproc,	/* LASTTOKEN */
20235f471cbSchristos };
20335f471cbSchristos 
tokname(int n)2045642d004Schristos const char *tokname(int n)
20535f471cbSchristos {
20635f471cbSchristos 	static char buf[100];
20735f471cbSchristos 
20835f471cbSchristos 	if (n < FIRSTTOKEN || n > LASTTOKEN) {
2095642d004Schristos 		snprintf(buf, sizeof(buf), "token %d", n);
21035f471cbSchristos 		return buf;
21135f471cbSchristos 	}
21235f471cbSchristos 	return printname[n-FIRSTTOKEN];
21335f471cbSchristos }
214