orangeduck / BuildYourOwnLisp

Learn C and build your own programming language in under 1000 lines of code!
http://www.buildyourownlisp.com/
Other
2.93k stars 396 forks source link

Errata with online text, Chapter 10 #116

Closed yingw787 closed 6 years ago

yingw787 commented 7 years ago

Well I got driven crazy over the last two days trying to find out a bug, and I fixed it and thought other people might benefit from this. I was getting a segmentation fault (core dump) in chapter_10 when trying to read in q_expressions, and on macOS Sierra it doesn't support valgrind and I tried/failed to use gdb (apparently I needed to install it from source, and then had to sign it using Apple's keychain access...went with EC2 instance instead).

The bug was that in lval_read(), not only do you need to add in if (strstr(t->tag, "qexpr")) { x = lval_qexpr(); },

but you also needed to add

        if (strcmp(t->children[i]->contents, "{") == 0) { continue; }
        if (strcmp(t->children[i]->contents, "}") == 0) { continue; }

Otherwise it can't parse the '{' and '}' correctly.

At least it's in the reference file, which is where I got this :)

and coming fresh from JS, gdb and valgrind sure are barebones...

orangeduck commented 7 years ago

Thanks for the report. I didn't notice this was missing from the chapter and I've added a short mention.