Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

type information in a lisp: DA STANDARD way

Name: Anonymous 2017-01-20 19:12

so I'm making a toy s-expression parser in C which may or may not become a minimal toy lisp interpreter and I'm trying to figure out the best way to do types. I know the classic way is to use the end of the pointer as tag bits but it doesn't really look standard-conforming or portable.

is there a way of doing it that doesn't rely on undefined behavior? the only thing I can think of is making a struct that holds value/pointer and type information but this seems very wasteful.

Name: L. A. Calculus !jYCj6s4P.g 2017-01-21 23:35

>>1

Y NOT JUST KEEP DEM AS STRINGS? DEN U JUST NEED 2 KNO HOW 2 SPLIT PAIRS & INTERPRET DA ATOMS ON A CASE BY CASE BASIS

int splitpair(char *car, char *cdr, char *pair);

char s[] = "(1 2 3)";
char car[32], cdr[sizeof s];

while (splitpair(car, cdr, s)) {
assert(!splitpair(NULL, NULL, car)); /* not a pair */
printf("%d\n", atoi(car));
fprintf(stderr, "%s\n", strcpy(s, cdr));
}

stdout:
1
2
3

stderr:
(2 3)
(3)
()

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List