-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaketokens.c
69 lines (63 loc) · 1.39 KB
/
maketokens.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* dirty little program generate token names
* and normalized values
*/
#include <stdio.h>
#include "token.h"
char *tokenname[128];
#define check(a) tokenname[a] = #a;
int
main(int argc, char **argv)
{
int i;
char *s;
#include "enumlist.h"
printf("char *tokenname[] = {\n");
for (i = 0; i < 128; i++) {
printf("/* %d 0x%x \'%c\' */ ", i, i, (i > ' ') && (i < 0x7f) ? i : ' ');
if (tokenname[i]) {
printf("\"%s\"", tokenname[i]);
} else {
printf("0");
}
if (i < 128) printf(",\n");
}
printf("};\n");
printf("char *detoken[] = {\n");
for (i = 0; i < 128; i++) {
s = 0;
switch(i) {
case E_O_F: s = ""; break;
case SYM: s = "symbol"; break;
case NUMBER: s = "number"; break;
case STRING: s = "string"; break;
case BEGIN: s = "{"; break;
case END: s = "}"; break;
case SEMI: s = ";"; break;
case STRUCT: s = "struct"; break;
case INT: s = "int"; break;
case CHAR: s = "char"; break;
case SHORT: s = "short"; break;
case ASSIGN: s = "="; break;
case COMMA: s = ","; break;
case DOT: s = "."; break;
case STAR: s = "*"; break;
case LPAR: s = "("; break;
case RPAR: s = ")"; break;
case LBRACK: s = "["; break;
case RBRACK: s = "]"; break;
case PLUS: s = "+"; break;
case MINUS: s = "-"; break;
default:
break;
}
if (s) {
printf("\"%s \"", s);
} else {
printf("0");
}
if (i < 128) printf(",\n");
}
printf("};\n");
return 0;
};