www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Any book recommendation for writing a compiler?

reply Dr. Assembly <netorib94 gmail.com> writes:
Hey guys, if I were to get into dmd's source code to play a 
little bit (just for fun, no commercial use at all), which 
books/resources do you recommend to start out?
Nov 01
next sibling parent reply Dr. Assembly <netorib94 gmail.com> writes:
On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly wrote:
 Hey guys, if I were to get into dmd's source code to play a 
 little bit (just for fun, no commercial use at all), which 
 books/resources do you recommend to start out?
I'd like something on back-end too, for example, code generation, convert the AST to actual assembly/machine code. On my research I found mostly front-end related stuff, like recursive descent parser.
Nov 01
parent Alexandre <alebencz gmail.com> writes:
On Wednesday, 1 November 2017 at 20:56:22 UTC, Dr. Assembly wrote:
 On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly 
 wrote:
 Hey guys, if I were to get into dmd's source code to play a 
 little bit (just for fun, no commercial use at all), which 
 books/resources do you recommend to start out?
I'd like something on back-end too, for example, code generation, convert the AST to actual assembly/machine code. On my research I found mostly front-end related stuff, like recursive descent parser.
Look at this book: https://www.t3x.org/reload/index.html Some cool open source languages: * Elena programming language: https://github.com/ELENA-LANG/elena-lang * DotNetPeLib: https://github.com/LADSoft/DotNetPELib * OrangeC/C++ compiler: https://github.com/LADSoft/OrangeC I have some cool projects: * A simple C compiler that generates a EXE/DLL: https://gist.github.com/bencz/79d4738afe962b5479d1 * CoffLib ( a lib to generate x86 EXE/DLL in .Net ) : https://github.com/bencz/CoffLib * Zinnia-lang: https://github.com/bencz/Zinnia-lang * dncpp: https://github.com/bencz/dncpp * Pythonish-Compiler: https://github.com/bencz/Pythonish-Compiler
Nov 01
prev sibling next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 11/01/2017 01:53 PM, Dr. Assembly wrote:
 Hey guys, if I were to get into dmd's source code to play a little bit 
 (just for fun, no commercial use at all), which books/resources do you 
 recommend to start out?
I haven't read it but one compiler bible is "the dragon book": https://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811 You should also watch Walter's presentation on dmd internals: http://dconf.org/2016/talks/bright.html Ali
Nov 01
prev sibling next sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, November 01, 2017 20:53:44 Dr. Assembly via Digitalmars-d-
learn wrote:
 Hey guys, if I were to get into dmd's source code to play a
 little bit (just for fun, no commercial use at all), which
 books/resources do you recommend to start out?
Well, if you're looking to actually buy a book, this is the one that I used in college and it was good: https://www.amazon.com/Compiler-Construction-Principles-Kenneth-Louden/dp/0534939724/ref=sr_1_1?ie=UTF8&qid=1509574006&sr=8-1&keywords=louden+compiler However, the one that folks generally mention is the "dragon book:" https://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811 I haven't read it though, so I can't comment on its contents, just that it's commonly recommended. Neither book is exactly cheap though. There may be some good online resources for learning about compilers, but I don't know them. However, if you're really serious about it, you'll probably want to read a textbook, since it's the sort of area where a good theoretical background to things can be quite useful. Certainly, at minimum, you're going to want to know the differences between things like a lexer and parser and what an abstract syntax tree is. - Jonathan M Davis
Nov 01
parent rikki cattermole <rikki cattermole.co.nz> writes:
On 01/11/2017 11:13 PM, Jonathan M Davis wrote:
 On Wednesday, November 01, 2017 20:53:44 Dr. Assembly via Digitalmars-d-
 learn wrote:
 Hey guys, if I were to get into dmd's source code to play a
 little bit (just for fun, no commercial use at all), which
 books/resources do you recommend to start out?
Well, if you're looking to actually buy a book, this is the one that I used in college and it was good: https://www.amazon.com/Compiler-Construction-Principles-Kenneth-Louden/dp/0534939724/ref=sr_1_1?ie=UTF8&qid=1509574006&sr=8-1&keywords=louden+compiler
Out of stock: https://www.thriftbooks.com/w/compiler-construction-principles-and-practice_kenneth-c-louden/263600/#isbn=0534939724
 However, the one that folks generally mention is the "dragon book:"
 
 https://www.amazon.com/Compilers-Principles-Techniques-Tools-2nd/dp/0321486811
https://www.thriftbooks.com/w/compiladores-principios-tecnicas-y-herramientas_alfred-v-aho/248872/#isbn=0201100886
 I haven't read it though, so I can't comment on its contents, just that it's
 commonly recommended. Neither book is exactly cheap though. There may be
 some good online resources for learning about compilers, but I don't know
 them. However, if you're really serious about it, you'll probably want to
 read a textbook, since it's the sort of area where a good theoretical
 background to things can be quite useful. Certainly, at minimum, you're
 going to want to know the differences between things like a lexer and parser
 and what an abstract syntax tree is.
 
 - Jonathan M Davis
I'd call it cheap ;) It isn't too bad grounding in everything, but doesn't branch out much (which is fine) and yeah invest in the hard cover version, its well worth it.
Nov 01
prev sibling next sibling parent reply Michael V. Franklin <slavo5150 yahoo.com> writes:
On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly wrote:
 Hey guys, if I were to get into dmd's source code to play a 
 little bit (just for fun, no commercial use at all), which 
 books/resources do you recommend to start out?
I found this to be quite helpful: http://llvm.org/docs/tutorial/ Specifically the Kaleidoscope tutorial. Mike
Nov 01
parent Igor <stojkovic.igor gmail.com> writes:
On Thursday, 2 November 2017 at 03:55:27 UTC, Michael V. Franklin 
wrote:
 On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly 
 wrote:
 Hey guys, if I were to get into dmd's source code to play a 
 little bit (just for fun, no commercial use at all), which 
 books/resources do you recommend to start out?
I found this to be quite helpful: http://llvm.org/docs/tutorial/ Specifically the Kaleidoscope tutorial. Mike
If you are interested in using LLVM my little project might be helpful: https://github.com/igor84/summus
Nov 02
prev sibling next sibling parent reply Basile B. <b2.temp gmx.com> writes:
On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly wrote:
 Hey guys, if I were to get into dmd's source code to play a 
 little bit (just for fun, no commercial use at all), which 
 books/resources do you recommend to start out?
You don't need to read books to write a compiler, a bit of theory from "here or there" will be enough, particularly if you start from scratch, there's almost no chance that you ever touch the more edgy things (something like theory of types maybe ). A few ones written in D (sorted by URL length): - https://github.com/dlang/dmd - https://github.com/BBasile/yatol - https://github.com/higgsjs/Higgs - https://github.com/VoltLang/Volta - https://github.com/beast-lang/beast-dragon Otherwise a subreddit that's not been quoted yet: - https://www.reddit.com/r/ProgrammingLanguages/ and their homepage listing a few projects from people who have started "the journey": http://www.proglangdesign.net/
Nov 02
parent reply Basile B. <b2.temp gmx.com> writes:
On Thursday, 2 November 2017 at 14:24:01 UTC, Basile B. wrote:
 On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly 
 wrote:
 Hey guys, if I were to get into dmd's source code to play a 
 little bit (just for fun, no commercial use at all), which 
 books/resources do you recommend to start out?
You don't need to read books to write a compiler, a bit of theory from "here or there" will be enough, particularly if you start from scratch, there's almost no chance that you ever touch the more edgy things (something like theory of types maybe ). A few ones written in D (sorted by URL length): - https://github.com/dlang/dmd - https://github.com/BBasile/yatol - https://github.com/higgsjs/Higgs - https://github.com/VoltLang/Volta - https://github.com/beast-lang/beast-dragon Otherwise a subreddit that's not been quoted yet: - https://www.reddit.com/r/ProgrammingLanguages/ and their homepage listing a few projects from people who have started "the journey": http://www.proglangdesign.net/
Dr Assembly what i mean can be illustrated by this: You see this https://github.com/matijapretnar/eff ? http://www.eff-lang.org/ ? People who say that after reading the dragon book, you will program your own programming language are lying.
Nov 04
parent reply Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= writes:
On Saturday, 4 November 2017 at 15:51:30 UTC, Basile B. wrote:
 People who say that after reading the dragon book, you will 
 program your own programming language are lying.
Well, you most certainly can write your own programming language after reading about 30% of the dragon book, but I think you can find easier books to get started these days. For more advanced stuff I would recommend downloading power points or notes from university courses on master or ph.d. level. The books and articles on more advanced stuff are often heavy on formalisms and difficult to digest for most programmers.
Nov 04
parent Basile B. <b2.temp gmx.com> writes:
On Saturday, 4 November 2017 at 20:28:17 UTC, Ola Fosheim Grøstad 
wrote:
 On Saturday, 4 November 2017 at 15:51:30 UTC, Basile B. wrote:
 People who say that after reading the dragon book, you will 
 program your own programming language are lying.
Well, you most certainly can write your own programming language after reading about 30% of the dragon book, but I think you can find easier books to get started these days.
I've just read the dragon book. let's write a compiler https://imgur.com/1pFeat8 ;-)
Nov 06
prev sibling parent Eugene Wissner <belka caraus.de> writes:
On Wednesday, 1 November 2017 at 20:53:44 UTC, Dr. Assembly wrote:
 Hey guys, if I were to get into dmd's source code to play a 
 little bit (just for fun, no commercial use at all), which 
 books/resources do you recommend to start out?
A few more resources on writing a frontend (lexer, syntactic and semantic analizer). http://thinkingeek.com/gcc-tiny/ Tells how to create a GCC frontend for a Pascal-like language, tiny. Can be useful since you can look how it applies to a real dfrontend in GDC. https://ruslanspivak.com/lsbasi-part1/ Very clear tutorial on writing a Pascal interpreter in Python. Very beginner friendly, but not complete yet. http://buildyourownlisp.com/contents It is an online book that teaches C by writing an interpreter for a Lisp-like language, lispy. The code can be easely translated to D. If you want you can also look at some haskell books. A simple parser is one of the standard projects used to teach haskell.
Nov 04