Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #20373

Re: Ann: Practical Compiler Construction

From Nils M Holm <news2009@t3x.org>
Newsgroups comp.lang.c
Subject Re: Ann: Practical Compiler Construction
Date 2012-05-04 05:36 +0000
Organization TARFU
Message-ID <a0h86eFiq5U1@mid.individual.net> (permalink)
References <a01fskFf3gU1@mid.individual.net> <9e2c2e55-679a-4320-ae29-f1cdfac12796@t23g2000yqd.googlegroups.com>

Show all headers | View raw


Rugxulo <rugxulo@gmail.com> wrote:
> On Apr 28, 1:09 am, Nils M Holm <news2...@t3x.org> wrote:
> > PRACTICAL COMPILER CONSTRUCTION
> > A No-nonsense Tour through a C Compiler
> >
> > which is now available at Lulu.com:
> >
> > http://www.lulu.com/content/12610903    (Paperback book)
> > http://www.lulu.com/content/12685672    (PDF download)
> 
> 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!).

Thank you! I agree that C is not easy to implement. This is why I
chose a subset of the language for the textbook. A line-by-line
tour through a full C compiler probably would have filled a volume
of 2000 pages. ;-)

> I almost, for some odd reason, expected this to be written in Scheme
> or something else.

Shameless plug: if you are looking for something written in Scheme,
have a look at Scheme 9 from Empty Space, by the same author. :-)

> 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.

I have already gotten requests for books about Javascript and Logo.
Well, I guess, you have to set some priorities.

> "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"?).

I have deliberately ignored the warnings about mixing && and ||
without parentheses, because I find the additional parens ugly.
And then every version of GCC seems to add new warnings, and I am
using a rather old release. I did not know about -Wextra.

> 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.

GAS and LD have the big advantage of already being there on most systems.
You do not have to install any additional clutter. On *BSD, SubC also
uses the system call wrapper of the system's libc. The Linux version
is completely stand-alone, because the GNU libc is... well, a bit
special. To put it in a euphemistic way. The latest ports can be found
here: http://www.t3x.org/subc/current/

> 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!).

A lot of things are missing. There are only ints, chars, void pointers
in the book version. The current version adds structs and unions. A
complete list of omissions is in the book and in the preview (View
Introduction) on the book home page: http://www.t3x.org/reload/

The libc implementation of SubC is quite complete, but not very
efficient. It is small, though, so the static executables tend to be
small, too. The compiler itself, for example, has a static size of
about 190KB.

> You managed to do this in relatively (very) few lines of code. Of
> course, self-hosting makes this easier. Congrats!   ;-)

Thanks!

-- 
Nils M Holm  < n m h @ t 3 x . o r g >  www.t3x.org

Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Ann: Practical Compiler Construction Nils M Holm <news2009@t3x.org> - 2012-04-28 06:09 +0000
  Re: Ann: Practical Compiler Construction Rugxulo <rugxulo@gmail.com> - 2012-05-03 11:03 -0700
    Re: Ann: Practical Compiler Construction Nils M Holm <news2009@t3x.org> - 2012-05-04 05:36 +0000

csiph-web