Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Ann: Practical Compiler Construction
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nils M Holm  
View profile  
 More options Apr 28 2012, 2:09 am
Newsgroups: comp.lang.c, comp.lang.misc
Followup-To: comp.lang.c
From: Nils M Holm <news2...@t3x.org>
Date: 28 Apr 2012 06:09:24 GMT
Local: Sat, Apr 28 2012 2:09 am
Subject: Ann: Practical Compiler Construction

I thought you might be interested in my latest textbook,

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)

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.

It is a book for seasoned programmers with little
or no background in compiler-writing.

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

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.

The complete code from the book is in the public domain
and can be downloaded at

http://www.t3x.org/subc/           (book version)
http://www.t3x.org/subc/current/   (post-book version)

Enjoy!

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rugxulo  
View profile  
 More options May 3 2012, 2:03 pm
Newsgroups: comp.lang.c
From: Rugxulo <rugx...@gmail.com>
Date: Thu, 3 May 2012 11:03:29 -0700 (PDT)
Local: Thurs, May 3 2012 2:03 pm
Subject: Re: Ann: Practical Compiler Construction
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.   ;-)

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

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.

> The complete code from the book is in the public domain
> and can be downloaded at

> http://www.t3x.org/subc/          (book version)http://www.t3x.org/subc/current/  (post-book version)

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nils M Holm  
View profile  
 More options May 4 2012, 1:36 am
Newsgroups: comp.lang.c
From: Nils M Holm <news2...@t3x.org>
Date: 4 May 2012 05:36:14 GMT
Local: Fri, May 4 2012 1:36 am
Subject: Re: Ann: Practical Compiler Construction

Rugxulo <rugx...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »