1 /*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 char copyright[] =
10 "@(#) Copyright (c) 1991 The Regents of the University of California.\n\
11 All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)proc.c 4.4 (Berkeley) 04/17/91";
16 #endif /* not lint */
17
18 #include "awk.h"
19 #define NULL 0
20 struct xx
21 { int token;
22 char *name;
23 char *pname;
24 } proc[] = {
25 { PROGRAM, "program", NULL},
26 { BOR, "boolop", " || "},
27 { AND, "boolop", " && "},
28 { NOT, "boolop", " !"},
29 { NE, "relop", " != "},
30 { EQ, "relop", " == "},
31 { LE, "relop", " <= "},
32 { LT, "relop", " < "},
33 { GE, "relop", " >= "},
34 { GT, "relop", " > "},
35 { ARRAY, "array", NULL},
36 { INDIRECT, "indirect", "$("},
37 { SUBSTR, "substr", "substr"},
38 { INDEX, "sindex", "sindex"},
39 { SPRINTF, "asprintf", "sprintf "},
40 { ADD, "arith", " + "},
41 { MINUS, "arith", " - "},
42 { MULT, "arith", " * "},
43 { DIVIDE, "arith", " / "},
44 { MOD, "arith", " % "},
45 { UMINUS, "arith", " -"},
46 { PREINCR, "incrdecr", "++"},
47 { POSTINCR, "incrdecr", "++"},
48 { PREDECR, "incrdecr", "--"},
49 { POSTDECR, "incrdecr", "--"},
50 { CAT, "cat", " "},
51 { PASTAT, "pastat", NULL},
52 { PASTAT2, "dopa2", NULL},
53 { MATCH, "matchop", " ~ "},
54 { NOTMATCH, "matchop", " !~ "},
55 { PRINTF, "aprintf", "printf"},
56 { PRINT, "print", "print"},
57 { SPLIT, "split", "split"},
58 { ASSIGN, "assign", " = "},
59 { ADDEQ, "assign", " += "},
60 { SUBEQ, "assign", " -= "},
61 { MULTEQ, "assign", " *= "},
62 { DIVEQ, "assign", " /= "},
63 { MODEQ, "assign", " %= "},
64 { IF, "ifstat", "if("},
65 { WHILE, "whilestat", "while("},
66 { FOR, "forstat", "for("},
67 { IN, "instat", "instat"},
68 { NEXT, "jump", "next"},
69 { EXIT, "jump", "exit"},
70 { BREAK, "jump", "break"},
71 { CONTINUE, "jump", "continue"},
72 { FNCN, "fncn", "fncn"},
73 { GETLINE, "getline", "getline"},
74 { 0, ""},
75 };
76 #define SIZE LASTTOKEN - FIRSTTOKEN
77 char *table[SIZE];
78 char *names[SIZE];
main()79 main()
80 { struct xx *p;
81 int i;
82 printf("#include \"awk.def\"\n");
83 printf("obj nullproc();\n");
84 for(p=proc;p->token!=0;p++)
85 if(p==proc || strcmp(p->name, (p-1)->name))
86 printf("extern obj %s();\n",p->name);
87 for(p=proc;p->token!=0;p++)
88 table[p->token-FIRSTTOKEN]=p->name;
89 printf("obj (*proctab[%d])() = {\n", SIZE);
90 for(i=0;i<SIZE;i++)
91 if(table[i]==0) printf("/*%s*/\tnullproc,\n",tokname(i+FIRSTTOKEN));
92 else printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
93 printf("};\n");
94 printf("char *printname[%d] = {\n", SIZE);
95 for(p=proc; p->token!=0; p++)
96 names[p->token-FIRSTTOKEN] = p->pname;
97 for(i=0; i<SIZE; i++)
98 printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),
99 names[i]?names[i]:"");
100 printf("};\n");
101 exit(0);
102 }
103