|
|
1.1 root 1: #include "awk.h"
2: #define NULL 0
3: struct xx
4: { int token;
5: char *name;
6: char *pname;
7: } proc[] = {
8: { PROGRAM, "program", NULL},
9: { BOR, "boolop", " || "},
10: { AND, "boolop", " && "},
11: { NOT, "boolop", " !"},
12: { NE, "relop", " != "},
13: { EQ, "relop", " == "},
14: { LE, "relop", " <= "},
15: { LT, "relop", " < "},
16: { GE, "relop", " >= "},
17: { GT, "relop", " > "},
18: { ARRAY, "array", NULL},
19: { INDIRECT, "indirect", "$("},
20: { SUBSTR, "substr", "substr"},
21: { INDEX, "sindex", "sindex"},
22: { SPRINTF, "asprintf", "sprintf "},
23: { ADD, "arith", " + "},
24: { MINUS, "arith", " - "},
25: { MULT, "arith", " * "},
26: { DIVIDE, "arith", " / "},
27: { MOD, "arith", " % "},
28: { UMINUS, "arith", " -"},
29: { PREINCR, "incrdecr", "++"},
30: { POSTINCR, "incrdecr", "++"},
31: { PREDECR, "incrdecr", "--"},
32: { POSTDECR, "incrdecr", "--"},
33: { CAT, "cat", " "},
34: { PASTAT, "pastat", NULL},
35: { PASTAT2, "dopa2", NULL},
36: { MATCH, "matchop", " ~ "},
37: { NOTMATCH, "matchop", " !~ "},
38: { PRINTF, "aprintf", "printf"},
39: { PRINT, "print", "print"},
40: { SPLIT, "split", "split"},
41: { ASSIGN, "assign", " = "},
42: { ADDEQ, "assign", " += "},
43: { SUBEQ, "assign", " -= "},
44: { MULTEQ, "assign", " *= "},
45: { DIVEQ, "assign", " /= "},
46: { MODEQ, "assign", " %= "},
47: { IF, "ifstat", "if("},
48: { WHILE, "whilestat", "while("},
49: { FOR, "forstat", "for("},
50: { IN, "instat", "instat"},
51: { NEXT, "jump", "next"},
52: { EXIT, "jump", "exit"},
53: { BREAK, "jump", "break"},
54: { CONTINUE, "jump", "continue"},
55: { FNCN, "fncn", "fncn"},
56: { GETLINE, "getline", "getline"},
57: { 0, ""},
58: };
59: #define SIZE LASTTOKEN - FIRSTTOKEN
60: char *table[SIZE];
61: char *names[SIZE];
62: main()
63: { struct xx *p;
64: int i;
65: printf("#include \"awk.def\"\n");
66: printf("obj nullproc();\n");
67: for(p=proc;p->token!=0;p++)
68: if(p==proc || strcmp(p->name, (p-1)->name))
69: printf("extern obj %s();\n",p->name);
70: for(p=proc;p->token!=0;p++)
71: table[p->token-FIRSTTOKEN]=p->name;
72: printf("obj (*proctab[%d])() = {\n", SIZE);
73: for(i=0;i<SIZE;i++)
74: if(table[i]==0) printf("/*%s*/\tnullproc,\n",tokname(i+FIRSTTOKEN));
75: else printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
76: printf("};\n");
77: printf("char *printname[%d] = {\n", SIZE);
78: for(p=proc; p->token!=0; p++)
79: names[p->token-FIRSTTOKEN] = p->pname;
80: for(i=0; i<SIZE; i++)
81: printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
82: printf("};\n");
83: exit(0);
84: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.