Book "Compiler Construction using Flex and Bison" - problems, discussions, steps, ...
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
When specifying your grammar, I think that it is very important that you explicitlystate the precedence of all operators, and left/right bindings and so on. "Don't rely on any defaults: say it."
I also strongly suggest that you study the code that is produced. Study the source-code of the actual parsing engine as it works through the data structures that are the output of the compiled grammar. It needs to "stop being a mystery, to stop being 'a black box' in your mind," as soon as possible.
Last edited by sundialsvcs; 09-19-2016 at 01:07 PM.
When specifying your grammar, I think that it is very important that you explicitlystate the precedence of all operators, and left/right bindings and so on. "Don't rely on any defaults: say it."
I also strongly suggest that you :study: study :study: the code that is produced. Study the source-code of the actual parsing engine as it works through the data structures that are the output of the compiled grammar. It needs to "stop being a mystery, to stop being 'a black box' in your mind," as soon as possible.
Writing them all would be my choice, sundialsvcs. :)
Studying the generated code... seems good. I will try it sometime. For now, my aim is to get a full working flex+bison+cc compiler with some optimization for any not complicated language. I imagine that using it for more complex languages/tasks/optimizations can be smooth.
The book itself is VERY incomplete - basically unusable.
Even the stack machine included is incomplete (it doesn't detect stack overflow/underflow for one, missing PC out of range, memory range limits too).
The book LOOKS like a draft copy, not a final copy.
1. The problems you have seen are due to poor choice of grammar. It is not necessary (though sometimes simpler) to use %left/%right anywhere - but you do have to be careful with the grammar rules.
2. The incorrect use of some terminology... It is almost like this was being translated from something done earlier, but hasn't yet been polished.
3. Missing examples - Optimization is an important section - yet it is nearly empty other than a little introductory text. Completely left out is algebraic optimization, a little constant folding (barely mentioned)...
4. code generation is mostly skipped.
5. Unspecified references for "further reading"...
You get better examples from the "Lex and Yacc" book, though they won't go into optimization (which is a rather complex subject on its own).
Even the stack machine included is incomplete (it doesn't detect stack overflow or underflow for one).
The book LOOKS like a draft copy, not a final copy.
I agree with you, but I probably cannot see it as clearly as you (because I am trying to learn from it).
I have done some work to produce the files I showed here, with things until chapter 4. If they are close to being a full compiler, I would like the help of people that are reading this thread. If they are not so close, please point that detail, so I do not expend more time with this idea.
I haven't gone through this - but the organization behind it do know what they are doing.
Thank you! I have read its first page, the only thing that I would not choose is the use of llvm - but I will try that, anyway. llvm is something that have been close to me for sometime...
"gnuu" is a domain I have not seen before. Funny...
These are among the various (widely-held ...) sentiments that prompt me to encourage you to "use the Source, Luke!"
I have read a great many books on compilers, and, with the possible(??) exception of Aho's book, I have yet to read a single decent one.
Therefore, I say, Get Jiggy Wit It, as soon as possible. Surf GitHub for existing projects which actually(!)use(!!) Bison. Find their grammar files, and the associated code which uses the Bison-generated parser. "This is the Real Deal, baby!"
Take the output of the Bison step and actually look at it. Study the actual source-code of the runtime engine. Rip the hood and both fenders off of the damned thing, and look at it, until you can see for yourself how it actually w-o-r-k-s.
You've spent more than enough time "reading books about swimming." Go find some actual examples. Then, after tightly securing your life-vest and your foam noodles, get into the water!
Last edited by sundialsvcs; 09-19-2016 at 07:21 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.