Fix bug with no trailing spaces.

Gotta update that pointer, eh?
This commit is contained in:
Simon Forman 2023-02-02 10:58:03 -08:00
parent e393016a32
commit dee703ea52
2 changed files with 36 additions and 15 deletions

View File

@ -8,9 +8,6 @@
const char *BLANKS = " \t"; const char *BLANKS = " \t";
/*const char *TEXT = " 23 [dup *] i hi there fr [[] ie]nd [] 23 ";*/
/*const char *TEXT = " 23 33 [] ";*/
const char *TEXT = "ok [wow] [23 45][1[2]3]simple terms already work eh? ";
enum JoyTypeType { enum JoyTypeType {
@ -233,7 +230,11 @@ parse_node(char **text)
with no spaces nor brackets. If that's the case then we're with no spaces nor brackets. If that's the case then we're
done, and we can just return a list with one symbol in it. done, and we can just return a list with one symbol in it.
*/ */
if (NULL == rest) return make_symbol_node(*text, strlen(*text)); if (NULL == rest) {
thing = make_symbol_node(*text, strlen(*text));
*text = rest;
return thing;
}
/* How many chars have we got? */ /* How many chars have we got? */
diff = rest - *text; diff = rest - *text;
@ -276,22 +277,25 @@ text_to_expression(char *text)
int int
main(void) main(void)
{ {
mpz_t pi; char *line;
struct list_node* el; char *status;
char *text = (char *)TEXT;
mp_set_memory_functions( mp_set_memory_functions(
&GC_malloc, &GC_malloc,
&reallocate_function, &reallocate_function,
&deallocate_function &deallocate_function
); );
mpz_init_set_str(pi, "3141592653589793238462643383279502884", 10);
/*mpz_init_set_str(pi, "25d0c79fe247f31777d922627a74624", 16);*/
GC_register_finalizer(pi, my_callback, NULL, NULL, NULL);
el = push_integer_from_str("3141592653589793238462643383279502884", 0); line = (char *)GC_malloc(1025);
el->tail = text_to_expression(text);
print_list(el); while (1) {
printf("\n"); status = gets_s(line, 1025);
if (NULL == status) {
printf("bye\n");
break;
}
print_list(text_to_expression(line));
printf("\n");
}
return 0; return 0;
} }

View File

@ -201,4 +201,21 @@ text_to_expression(char *text)
} }
return result; return result;
} }
' '
/*mpz_t pi;*/
/*char *text = (char *)TEXT;*/
/*mpz_init_set_str(pi, "3141592653589793238462643383279502884", 10);*/
/*mpz_init_set_str(pi, "25d0c79fe247f31777d922627a74624", 16);*/
/*GC_register_finalizer(pi, my_callback, NULL, NULL, NULL);*/
/*el = push_integer_from_str("3141592653589793238462643383279502884", 0);*/
/*el->tail = text_to_expression(text);*/
/*el = text_to_expression(text);*/
/*print_list(el);*/
/*printf("\n");*/
/*const char *TEXT = " 23 [dup *] i hi there fr [[] ie]nd [] 23 ";*/
/*const char *TEXT = " 23 33 [] ";*/
const char *TEXT = "ok [wow] [23 45][1[2]3]simple terms already work eh? ";