diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-03 00:42:59 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-03 00:42:59 +0300 |
commit | faab24e5a6766880c7e4a33433cb4146e3f8a302 (patch) | |
tree | a28052605028bd26167050bcf9f06913480e593a | |
parent | cff0c84f6b14f37497ff22c54948380af64e8106 (diff) | |
download | csx-faab24e5a6766880c7e4a33433cb4146e3f8a302.tar csx-faab24e5a6766880c7e4a33433cb4146e3f8a302.tar.xz csx-faab24e5a6766880c7e4a33433cb4146e3f8a302.zip |
Translator added.
-rw-r--r-- | examples/translator.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/examples/translator.c b/examples/translator.c new file mode 100644 index 0000000..448d052 --- /dev/null +++ b/examples/translator.c @@ -0,0 +1,56 @@ +#include <stdio.h> +#include <ctype.h> + + +void readlist() +{ + int first = 1; + int c = getchar(); + while (c != EOF && c != ']') { + if (c == '[') { + if (first) first = 0; + else putchar(','); + printf("csx_list("); + readlist(); + printf("0)"); + c = getchar(); + } else if (isdigit(c)) { + if (first) first = 0; + else putchar(','); + printf("csx_num("); + putchar(c); + c = getchar(); + while (c != EOF && isdigit(c)) { + putchar(c); + c = getchar(); + } + printf(")"); + } else if (isspace(c)) { + while (isspace(c = getchar())); + } else { + if (first) first = 0; + else putchar(','); + printf("csx_name(\""); + while (c != EOF && !isspace(c) && c != '[' && c != ']') { + if (c == '"' || c == '\\') putchar('\\'); + putchar(c); + c = getchar(); + } + printf("\")"); + } + } + if (!first) putchar(','); +} + +int main() +{ + puts("#include <csx.h>"); + puts("int main()"); + puts("{"); + printf("csx_eval(csx_list(csx_name(\"do\"),"); + readlist(); + puts("0));"); + puts("return 0;"); + puts("}"); + return 0; +} |