From ae882f68193e00deebce41c32df644b6cb2f2a47 Mon Sep 17 00:00:00 2001 From: Aleksey Veresov Date: Mon, 4 Jan 2021 15:03:31 +0300 Subject: . --- examples/translator.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'examples/translator.c') 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 #include +#include 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(); -- cgit v1.2.3