blob: eebe644d9864d4246c09dbd19348c7ea33da753f (
plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int c;
int indent = 0;
int items();
void prindent()
{
int i;
printf("\n ");
for (i = 0; i != indent; ++i) {
printf(" ");
}
}
void name(char a)
{
prindent();
printf("N(\"");
if (a) putchar(a);
while (c != EOF && !isspace(c) && c != '[' && c != ']') {
if (c == '"' || c == '\\') putchar('\\');
putchar(c);
c = getchar();
}
printf("\")");
}
void num(char a, char b)
{
prindent();
printf("I(");
if (a) putchar(a);
if (b) putchar(b);
c = getchar();
while (c != EOF && isdigit(c)) {
putchar(c);
c = getchar();
}
printf(")");
}
void list()
{
prindent();
printf("L(");
if (items()) prindent();
printf("0)");
c = getchar();
}
void dot()
{
if ((c = getchar()) == '[') {
prindent();
printf("D(");
items();
prindent();
printf("0)");
c = getchar();
} else name('=');
}
void quote()
{
prindent();
printf("L(qt,\n");
c = getchar();
if (c == '[') list();
else if (c == '=') dot();
else if (c == '\'') quote();
else name(0);
printf(",\n");
prindent();
printf("0)");
}
void skip()
{
while (isspace(c) || c == '{') {
if (isspace(c)) while (isspace(c = getchar()));
if (c == '{') {
int level = 1;
while (level && c != EOF) {
while ((c = getchar()) != '{' && c != '}' && c != EOF);
if (c == '{') ++level;
if (c == '}') --level;
}
if (c != EOF) c = getchar();
}
}
}
int items()
{
int first = 1;
++indent;
c = getchar();
skip();
while (c != EOF && c != ']') {
if (first) first = 0; else putchar(',');
if (c == '[') list();
else if (c == '-')
if (isdigit(c = getchar())) num('-', c);
else name('-');
else if (isdigit(c)) num(c, 0);
else if (c == '=') dot();
else if (c == '"') {
prindent();
printf("S(\"");
c = getchar();
while (c != EOF && c != '"') {
if (c == '\\') c = getchar();
if (c == '"' || c == '\\') putchar('\\');
putchar(c);
c = getchar();
}
printf("\")");
c = getchar();
} else if (c == '\'') quote();
else name(0);
skip();
}
if (!first) putchar(',');
--indent;
return !first;
}
int main()
{
printf("#include <csxbind.h>\n\nint main()\n{\n");
printf(" csxbind_init();\n R(L(_do,");
items();
printf("\n 0));\n \n csxbind_free();\n return 0;\n}\n");
return 0;
}
|