From bb41bf619dd4eb1eabe4719b13a5c18538acfb40 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Wed, 1 Feb 2023 20:34:04 -0800 Subject: [PATCH] Remove separate parser code. --- implementations/C/.gitignore | 1 - implementations/C/parser.c | 68 ------------------------------------ 2 files changed, 69 deletions(-) delete mode 100644 implementations/C/parser.c diff --git a/implementations/C/.gitignore b/implementations/C/.gitignore index 2046ae4..59a897d 100644 --- a/implementations/C/.gitignore +++ b/implementations/C/.gitignore @@ -1,2 +1 @@ joy -parser diff --git a/implementations/C/parser.c b/implementations/C/parser.c deleted file mode 100644 index e7241af..0000000 --- a/implementations/C/parser.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include -#include - - -const char *BLANKS = " \t"; -const char *TEXT = " 23 [dup *] i hi there fr [[] ie]nd] [] 23 "; - - -char * -trim_leading_blanks(char *str) -{ - size_t offset = strspn(str, BLANKS); - return (offset == strlen(str)) ? NULL : (str + offset); -} - - -int -main(void) -{ - char *rest, *text, *snip; - ptrdiff_t diff; - - text = trim_leading_blanks((char *)TEXT); - if (NULL == text) { - /* All blanks. */ - return 1; - } - - rest = strpbrk(text, " []"); - /* - rest now points to a space or '[' or ']' after a term, - -or- it is NULL if the rest of the string is a single term - with no spaces nor brackets. - */ - - while (NULL != rest) { - - /* How many chars have we got? */ - diff = rest - text; - /* - diff can be zero when there is more than one space in - a sequence in the input string. This won't happen on - the first iteration but it can on later iterations. - */ - - if (diff) { - /* Allocate space and copy out the substring. */ - snip = (char *)GC_malloc(diff + 1); - strncat(snip, text, diff); - printf("%s\n", snip); - } - - /* The next char is a space or '[' or ']'. */ - if ('[' == rest[0] || ']' == rest[0]) { - printf("%c\n", rest[0]); - } - - text = trim_leading_blanks(++rest); - - /* calling strpbrk on NULL caused segfault! */ - rest = (NULL != text) ? strpbrk(text, " []") : text; - } - if (text) { - printf("%s\n", text); - } -}