orangeduck/BuildYourOwnLisp

Segfault being caused by mpc_parse_run

Closed this issue · 4 comments

Program (Lisp) crashing when calling load function. On Chapter 13. Here is the GDB Error output and my implementation of the lisp. I could not figure out why the error was happening. It would be great if you could tell me if its an issue with the parser or my code.

image
main.zip

After researching for a while I found out that it is an issue with the variable Byolisp or Lispy that is being passed into mpc_parse_contents. The value of Byolisp/Lispy in my version is 0x0 or NULL. I haven't been able to figure out the solution yet. Any help would be appreciated.

Hi,

The name you give to mpc_new needs to match the name you use in the grammer. My guess is that these do not match and so it is not assigning the rule anything.

Dan

Oh yes, Thanks Dan. Actually after carefully comparing your version and mine, I was re declaring the grammar in main function after declaring them in the global scope as well. Thus the Lispy variable became 0x0 (NULL) and caused a segfault.

Thanks for writing this book, I really appreciate your work and have gained good amount of knowledge about C. And lastly thanks for replying even years after writing of the book.

Glad you enjoyed it good luck with the rest of the book!