Update: So turns out all I had to do to make bison generate t.tab.c
was to use the -y
switch. However, my original assumption of a problem with the code when the problem gave me a segfault seems correct according to the answers posted. Here is what it all looks like now:
The source is exactly the same as downloaded from the O'reilly website and I triple checked the ch1-04 code that this is based on. It's all extremely simple stuff. A program that recognises a sentence as a subject VERB and object
Here is the code : ch1-05.l, ch1-05.y, ch1-05y.h
Original Question:
So succinctly I'm working my way to learning how to build a compiler.
I'm not very used to C\C++ and have never used lex and yacc before, this I'm following this book:
Now, in the book on page 21 this is what it says:
Now being on fedora 2 I don't have yacc. I installed bison.
Here is what the scene on my fedora looks like:
Do notice I am using -d.
If you'd really like to see the code here is : ch1-05.l, ch1-05.y, ch1-05y.h
I was actually silly enough and thought y.tab.c
was an mistake in the book and they actually meant ch1-05.tab.c
. I tried compiling with that and it gave me a segmentation fault :/ It took me a day to realize there is supposed to be a y.tab.c
there.
I'm quite constantly checking SO so anything you need from me I will respond quick. I'd really like to get this done with because I'm on holiday due to a brain haemorrhage and I'd like to get this book complete soon. I have quite a list of books and quite a holiday :D
Thinking that bison would produce
ch1-05.tab.c
instead ofy.tab.c
wasn't silly at all, in fact that's what it did. Bison is GNU's version of Yacc, and though it is compatible with it in terms of grammar description, there are some differences in usage.If you want to revert to conservative Yacc mode, try
bison -y [...]
:If you get a segfault running you program, it's more likely due to a programming error on your side. How did you link you binary ?
( ... some googling later ... )
Try this in
ch1-05.y
: