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.
The Structure and Interpretation of Computer Programs is more or less all about getting you to the point where you can write a LISP interpreter. Here's one of the many online copies:
It might be helpful if you can elaborate a little on your current knowledge/expertise level and what your goals actually are.
The input side of interpreters and compilers are essentially the same - tokenizer (aka lexer, scanner) and parser (aka syntax checker) designed for your particular grammar, which together produce an intermediate representation (commonly some form of AST - abstract syntax tree) of the input language stream. The output side, interpreter, compiler or other processing all work from that intermediate representation, ideally.
So, how much of the total picture are you interested in?
The best printed resource I know of for the total picture is Modern Compiler Design. The first 5 chapters of that book, together with the same author's Parsing Techniques: A Practical Guide, will cover just about anything you have in mind, in depth, but very readable and usable! There is a free download of the first edition of Parsing Techniques on the linked page.
If you are really just starting out, I recommend Levine's Flex & Bison from O'Reilly. You may find some poor reviews on this book, I do not fully understand why. I suspect that the subject matter is just inherently complex and unfamiliar and many people are looking for instant point-and-click style of learning. But the book provides a very useful and readable introduction to the subject and the tools, plus excellent examples with downloadable source code... it will be time well spent to work your way through it - more than once as your understanding grows. You will need some supplemental reading for BNF notation of context-free grammars if not already familiar, plenty online but one of the best written and most useful I have recently seen here.
So, try to clearly identify your current level and the scope of your project - and get down to business!
If you are new to the subject then Flex is a good place to start!
The Flex manual is mostly complete and easy enough to read. (As I recall, it seems to just dive right in on first pass and makes the head spin, but becomes clear very quickly if you stick with it).
Download the source and extract the examples directory - it has some good ones! (You don't have to build the package to use the examples, just use whatever Flex comes with your distro).
Once you get oriented to what Flex actually does it is extremely easy to quickly generate test cases and experiment - I'll be happy to suggest a few once you have begun working through the manual.
Flex is a lexer generator - that is, it generates compilable C code for lexers (tokenizers) from your specification file. So you will need to know or learn some basic C and how to use gcc, the GNU compiler.
And regular expressions - you will need to become moderately proficient with them if not already as they are the primary input to a Flex specification.
Once you know what Flex does, you can move on quickly to integrating it with Bison.
Good luck and keep us posted!
Last edited by astrogeek; 09-06-2016 at 01:46 AM.
Reason: typos
Yes, I've written one ... and, made money from it. (I still do.)
Today, probably the easiest thing to do is to lookat an existing compiler or interpreter, e.g. on GitHub. Study exactly what they did. Whack-a-mole what they did to turn it into what you want.
Yes, I've written one ... and, made money from it. (I still do.)
Today, probably the easiest thing to do is to lookat an existing compiler or interpreter, e.g. on GitHub. Study exactly what they did. Whack-a-mole what they did to turn it into what you want.
Hi Sundialsvcs, I'm trying to do it via Java and utilize javacc. I'm still trying to check the process or steps.
Like if I have the BNF, what steps should I do next. Is there a link somewhere that gives an overview some sort of a block diagram or flowchart?
The process for making an interpreter and a compiler is different?
probably you missed my previous post, there were two links about "how to build an interpreter in java".
An interpreter need not process the complete file, just one line at a time, the compiler will always process everything and will create an executable.
The compilers have much better optimizers, they uses different passes to generate byte code, optimize, generate binary, linking, whatever.
The interpreters usually much simpler, but they may handle variables differently.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.