1. 59

  2. 12

    Is it a coincidence that “Barely C Programming Language” abbreviates to BCPL?

    I’m not really clear on what happened in between the “lex it like Forth” step and the “Profit!” Step, but it’s cool.

    1. 5

      BCPL was too large and sophisticated to be implementable on early Unix systems. The first C compiler emitted machine code directly from the parser (as does SectorC), because there wasn’t enough memory to build a parse tree. According to Dennis Richie, BCPL couldn’t be implemented that way, because of advanced features such as: you can call a procedure before it is declared, and block expressions (these were called valof expressions in BCPL).

      Richie describes B (the predecessor of C) as “BCPL squeezed into 8K bytes and filtered through [Ken] Thompson’s brain”. B also had only 1 type, a 16 bit word, and SectorC seems to be the same, although it calls this type “int”. So SectorC is much closer to B than it is to BCPL.

      See: https://www.lysator.liu.se/c/chistory.ps

    2. 7

      This is absolutely horrifying, and I love it!

      All the best,

      1. 4

        This is an amazing feat. But shouldn’t the post title be “SectorC: A C Compiler in 512 bytes”?

        1. 1

          In how many of the systems programming languages lot can something like this be possible? (single person hobby, of a compiler that covers a very useful set of the features of the language in 512 bytes)

          1. 5

            The Turbo Pascal environment for DOS, with a compiler, pseudographical IDE, debugger, a set of libraries all fit in 300 KB, if I remember correctly. I suspect its subset could be implemented succinctly as well.

            It just becomes a game of “how many features I can leave out while it’s still resembling something serious”, a code golf to compress compiler concepts and language features.