Hi,
On Apr 28, 1:09 am, Nils M Holm <
news2...@t3x.org> wrote:
>
> I thought you might be interested in my latest textbook,
I've barely noticed you before, and you seem like you know what you're
doing! Way more than me, at least. ;-)
Sounds almost interesting, though I'm not very skilled at C. In fact,
I'd consider ANSI C to be "too hard" to implement, personally, but
kudos for getting this far (quite well done!).
I almost, for some odd reason, expected this to be written in Scheme
or something else. Please ignore this ramble, but I'm a little sad
it's not written in Pascal (or Oberon?) or something else, heheh.
Though admittedly it's better in a lot of ways to write it in itself.
> See also:
>
>
http://www.t3x.org/reload/ (Contents, Source code, etc)
>
> The book illuminates the practical side of compiler
> construction and takes the reader on a tour through
> the full source code of a compiler for a C subset.
Indeed, quite complete (to my eyes), though not full, but still very
good and impressive.
> It is a book for seasoned programmers with little
> or no background in compiler-writing.
Seasoned, ugh, heheh.
> Theory will be covered when necessary, but the focus
> is always on actual code. The compiler discussed in
> the book is a clean and simple implementation that
> does not "bend the rules" like many other small C
> compilers. Its sources pass gcc -Wall -pedantic with
> little or no warnings (depending on the gcc version).
"make lint" doesn't work out of the box, but that's an easy fix. It
does whine once or twice about some stuff, but nothing major. But
yeah, "-ansi -pedantic -Wall" (what, no "-Wextra"?).
> The compiler and runtime environment is designed to run
> on FreeBSD on a 386 processor, but a post-book version
> of SubC has already been ported to FreeBSD/x86-64,
> NetBSD/x86-64 as well as Linux/386. Porting it to other
> Unix-like systems should be easy.
Needs GAS and LD, blech. Heh, I'd almost rather have a DJGPP targeted
version, but I'm too lazy. ;-)
Honestly, while I understand that C will always need a linker, in this
case I think it'd almost be better to just use FASM, which can output
ELF reloc (for later use) or executable directly. It runs on all those
OSes and assembles itself (and as such is much easier to bootstrap
than BinUtils). Though I guess it's not that important overall.
It's pretty good, I played with it a very tiny bit. Lacks most CPP
stuff (#if) and doesn't understand "long" or "L" suffix (though all
ints are 32-bit anyways) or the "l" in printf("%ld"), or "typedef" or
"unsigned", but otherwise seems very useful. Seems to come with a
subset of a libc too, and it can compile itself (statically!).
You managed to do this in relatively (very) few lines of code. Of
course, self-hosting makes this easier. Congrats! ;-)