4 ms·
Would anyone be interested in a simple tiny compiler ebook?
https://github.com/deepanprabhu/simple-expression-compiler
Guys, would anybody be interested to read a simple, pithy ebook, that describes fundamentals of building a simple tiny compiler in Java to begin with ? I would also take the reader through building a simple compiler themselves, step by step, using Java. The exercise simple enough that i chose is, taking a mathematical expression like 6 * 5 + 3 * ( 2 -1 ), and generating NASM assembly code, that we would compile and execute using NASM. Please give me your thoughts !
- PhilWright 9y agoI think the best tutorial would not be for a toy language or just for simple expressions. But for a subset of a real language. That way the details learnt are directly applicable to the real world. Create a compiler for a subset of C or a subset of Java. Then it is possible for the reader to continue developing that compiler to include more and more features.
- bootcat 9y agoYou are right, people would be interested to implement a real compiler for an actual language. I have tried it. But when you actually sit down to implement, its atleast months. But if you choose a simple language, you can get the entire compiler done in perhaps a week/month at most. Indeed, that prepares you for implementing an actual language. My 2 cents, what do you think ?
- jetti 9y agoSomething like C could be seen as a simple language. You don't have to do everything in the language and you don't have to handle the edge cases. But being able to use functions and variables would be awesome and I would totally pay for something like that.
- bootcat 9y agoI would consider Java to be simpler, but i see this is subjective and C seems like a popular language to proceed with. In java most of functionality we need is available as standard library.
- jetti 9y agoDepends on the target. It would be much harder to implement Java with a assembly target and some of the standard library because you would have to implement that from scratch. Not only that, but you have to deal with vtables from inheritance and class layouts. C doesn't require any of that complexity. That being said, I think it would be very valuable to see somebody implement at least a partial version of Java with standard library (such as generics or at least collections) with assembly as the target.
- bootcat 9y agoSorry i did not completely understand your comment. You mean to say, to implement a subset of C. I have already answered that question. Before we implement a real language or a part of it, implementing mathematical expressions has to come in place with actual code. Reason is, before we jump to implementing an actual language, we can learn all the phases of a compiler, simply compiling expressions into assembly. Extrapolating, we can implement a subset of C, which is not easy to begin with, but with experience, it is achievable.
- jetti 9y agoOne thing that I would be more interested in is either targeting LLVM IR, JVM or .NET instead of doing straight assembly with NASM.
- bootcat 9y agoSeems like a nice idea. The reason i picked NASM language is its easy to watch your simple assembly code assembled and converted to an executable and actually watch it run ! But I would have this in mind.
- kotrunga 9y agoThat would be awesome! However, I think something that's not Java... maybe, a "simple" book on building a compiler in C or something.
- bootcat 9y agoA second comment, wanting me to implement in C rather than Java !
- deleted 9y ago[deleted]