Hacker News new | past | comments | ask | show | jobs | submit login

Why not go for the full C language. C was made to make compilers easy to build. Also it might expose/help to see difficulties in the chosen approach.

They went with a subset of C, its enough to write a working executable. Generally for a introduction tutorial to something as complex as writing a compiler a subset like what they presented in the article is enough to show how all the pieces work together to produce a working compiler.

Yup, for the purposes of a demo like this, a simplified top-to-bottom "vertical slice" is of far more value than total feature coverage.

Unless you are talking about something like "A Retargetable C Compiler: Design and Implementation", it is definitly not easy.


During the early 80's, the best home computers could get was Small-C.


Small-C was the best one with open source, but there were many others. This one was my favorite: https://www.bdsoft.com/resources/bdsc.html

What I got back in the day came in book form, it was also another flavour.

"A book on C"


It uses a K&R C subset with bytecodes and a bytecode-> machine language translation.

I just never bothered to type it in though.

A conforming ISO C compiler seems extremely difficulty to build and I don’t think ease of writing a compiler is a part of the design these days.

They could stick to ANSI C.

ANSI C and ISO C are the same thing, at least for the 1989/90 revision. It’s still not a particularly easy language to implement, at any stage.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact