aboutsummaryrefslogtreecommitdiff
path: root/examples/translator.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/translator.c')
-rw-r--r--examples/translator.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/translator.c b/examples/translator.c
index 14b7482..8358a47 100644
--- a/examples/translator.c
+++ b/examples/translator.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <ctype.h>
+#include <stdlib.h>
void readlist()
@@ -27,11 +28,58 @@ void readlist()
printf(")");
} else if (isspace(c)) {
while (isspace(c = getchar()));
+ } else if (c == '.') {
+ if (getchar() != '[') exit(1);
+ if (first) first = 0;
+ else putchar(',');
+ printf("csx_dot(");
+ readlist();
+ printf("0)");
+ c = getchar();
+ } else if (c == '"') {
+ if (first) first = 0;
+ else putchar(',');
+ printf("csx_str(\"");
+ while (c != EOF && c != '"') {
+ if (c == '\\') c = getchar();
+ if (c == '"' || c == '\\') putchar('\\');
+ putchar(c);
+ c = getchar();
+ }
+ printf("\")");
+ } else if (c == '\'') {
+ if (first) first = 0;
+ else putchar(',');
+ printf("csx_list(csx_name(\"quote\"),");
+ c = getchar();
+ if (isspace(c)) exit(1);
+ else if (c != '[') {
+ printf("csx_name(\"");
+ while (c != EOF && !isspace(c) && c != '[' && c != ']') {
+ if (c == '"' || c == '\\') putchar('\\');
+ putchar(c);
+ c = getchar();
+ }
+ printf("\"),");
+ } else if (c == '.') {
+ if (getchar() != '[') exit(1);
+ printf("csx_dot(");
+ readlist();
+ printf("0)");
+ c = getchar();
+ } else {
+ printf("csx_list(");
+ readlist();
+ printf("0),");
+ c = getchar();
+ }
+ printf("0)");
} else {
if (first) first = 0;
else putchar(',');
printf("csx_name(\"");
while (c != EOF && !isspace(c) && c != '[' && c != ']') {
+ if (c == '\\') c = getchar();
if (c == '"' || c == '\\') putchar('\\');
putchar(c);
c = getchar();