Read the TeX WEB source (if you can't weave tex.web yourself, you can cheat: https://rfsber.home.xs4all.nl/Tex/tex.pdf ) Note that "WEB" here is not "web" as in website.
Knuth's programming style is highly idiosyncratic, and there are many points with which I'd disagree. Furthermore, the choice of Pascal required all sorts of strange compromises. That said, I highly commend reading the source of TeX, to see how a brilliant computer scientist attacked a problem that is not nicely structured, using very restricted programming tools. You will not get much that you can copy into your programs, but it is an excellent, well-documented attack on an interesting and complex problem. (By the way, Knuth's TeX was written long before modern typesetting things like Unicode, PDF, and OTF fonts; you don't want to use Knuth's TeX for modern work; I use LuaTeX. But Knuth's version remains as a useful subject of study.)
Another good thing to study is Lions's commentary on Unix V6. This is interesting because it shows many of Unix's key abstractions implemented in a few thousand lines of code.