News for hackers. Stuff that matters.
Re:How to create an OS from scratch – tutorial by simula67 on Thursday September 20, 2018 @10:24PM (#18036783)
Can anyone recommend good resources on writing a compiler from scratch ?
Re:How to create an OS from scratch – tutorial by charlysl on Thursday September 20, 2018 @11:42PM (#18037026)
Stanford CS143 - Compilers [1] and [2] MOOC: This self-paced course will discuss the major ideas used today in the implementation of programming language compilers, including lexical analysis, parsing, syntax-directed translation, abstract syntax trees, types and type checking, intermediate languages, dataflow analysis, program optimization, code generation, and runtime systems. As a result, you will learn how a program written in a high-level language designed for humans is systematically translated into a program written in low-level assembly more suited to machines. Along the way we will also touch on how programming languages are designed, programming language semantics, and why there are so many different kinds of programming languages.

MIT 6.035 - Computer Language Engineering [3]: This course analyzes issues associated with the implementation of higher-level programming languages. Topics covered include: fundamental concepts, functions, and structures of compilers, the interaction of theory and practice, and using tools in building software. The course includes a multi-person project on compiler design and implementation.

[1] https://lagunita.stanford.edu/courses/Engineering/Compilers/...

[2] http://web.stanford.edu/class/cs143/

[3] https://ocw.mit.edu/courses/electrical-engineering-and-compu...

Re:How to create an OS from scratch – tutorial by pjmlp on Friday September 21, 2018 @03:04AM (#18037714)
Wirth's book, "Compiler Construction"

https://www.inf.ethz.ch/personal/wirth/

On the way you can also grab "Project Oberon" from there, both 1992 and 2013 editions, to see how to write an OS from scratch, including an FPGA board, in a GC enabled systems programming language.

There are also the tiger books, in C, Java and ML variants.

https://www.cs.princeton.edu/~appel/modern/

Re:How to create an OS from scratch – tutorial by faitswulff on Thursday September 20, 2018 @11:23PM (#18036971)
Destroy All Software has (as usual) an excellent screencast on it: https://www.destroyallsoftware.com/screencasts/catalog/a-com...
Re:How to create an OS from scratch – tutorial by GeorgeTirebiter on Friday September 21, 2018 @01:33AM (#18037370)
I think the best first book is: James E. Hendrix, The Small-C Handbook, Reston 1984, ISBN 0-8359-7012-4

He explains every detail, goes through every routine, and you can see exactly what the compiler does. It's 'Small-C' so it doesn't have any fancy features, like floats or structs. But the basic machinery is there, and one can add features as desired. It does compile itself. The compiler outputs x86 assembly, which must be assembled and linked with standard programs.

The original Small-C was done by Ron Cain, and produced 8080 code. I like Mr. Hendrix' better because I have lots of x86 around (I specifically wanted it for my HP-200 LX palmtop, which I still have and works great!); and because the book is fantastic.

It's fully understandable in a small quantity of time. And, the back end is re-targetable, so you could, say, output to ARM or RISC-V or whatever.

I spoke with Mr. Hendrix some years ago, maybe 10 or so, and asked if he would consider putting the compiler into the public domain. He did.

Re:How to create an OS from scratch – tutorial by bogomipz on Friday September 21, 2018 @10:23AM (#18039880)
Thanks for this suggestion.

In case anyone else is interested, there is a freely available ISO of the the book available from Dr Dobbs Journal. From the README in the ISO:

>"Welcome to Dr. Dobb's Small-C Resource CD-ROM, the definitive collection of Small-C related information and source code. This CD-ROM includes the full text to James Hendrix's book "A Small-C Compiler: Language, Usage, Theory, and Design," selected articles on Small-C from "Dr. Dobb's Journal" magazine, and Small-C implementations for a number of processor platforms, including the 8080, Z80, 6502, and others."

It's available here:

http://www.drdobbs.com/developer-network-small-c-compiler-bo...

Re:How to create an OS from scratch – tutorial by IronBacon on Friday September 21, 2018 @04:30AM (#18038092)
There are already a lot of suggestions here, I've added to my always increasing reading list this one[1] because, being based on Scheme (Racket to be exact), I'm curious on how a Lisp dialect compiler works internally.

[1] https://github.com/IUCompilerCourse/Essentials-of-Compilatio...

Re:How to create an OS from scratch – tutorial by oxryly1 on Friday September 21, 2018 @11:54AM (#18040590)
Here's a great description of compiling from a largish subset of Scheme all the way to x86 assembly language: http://schemeworkshop.org/2006/11-ghuloum.pdf
Re:How to create an OS from scratch – tutorial by IronBacon on Friday September 21, 2018 @01:55PM (#18041446)
The author is mentioned it that book in the introduction chapter and in the acknowledgments.

Thanks, I'll put in the pile of things to read.

Re:How to create an OS from scratch – tutorial by gilmi on Friday September 21, 2018 @03:35AM (#18037861)
Re:How to create an OS from scratch – tutorial by arundelo on Thursday September 20, 2018 @10:53PM (#18036877)
Re:How to create an OS from scratch – tutorial by earenndil on Thursday September 20, 2018 @10:35PM (#18036816)
Crafting interpreters, also the dragon book.