Shop OBEX P1 Docs P2 Docs Learn Events
Let's build a forth compiler — Parallax Forums

Let's build a forth compiler

Mike HuseltonMike Huselton Posts: 746
edited 2008-07-10 21:22 in Propeller 1
I just read a blog entry from James Hague concerning a well done approach to compiler design.
Jack W. Crenshaw wrote the Let's Build a Compiler article series from 1988 - 1995. This document is a formatted version of that excellent non-technical introduction to compiler construction. These web pages were created in 2005, and port Mr. Crenshaw's original Pascal code for the 68000 under SK*OS to the Forth language on a 80x86 CPU, under Windows XP. said...

home.iae.nl/users/mhx/crenshaw/tiny.html

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH

Comments

  • prof_brainoprof_braino Posts: 4,313
    edited 2008-07-10 03:00
    Hi Quantum

    Have you made any progress?
  • waltcwaltc Posts: 158
    edited 2008-07-10 05:02
    I have Crenshaw's original paper on Compiler design and its a good one. He uses Turbo Pascal to write a simple compiler and avoids the heavy theory and 3rd hand English of the Dragon book.

    Though this paper seems to be a bizarre graft by a unscrupulous Forth toad trying promote Forth under Crenshaw's name.

    I'd skip it and check out Camel Forth by Brad Rodriguez instead if you want to build a Forth implementation from scratch or even E-Forth.
  • heaterheater Posts: 3,370
    edited 2008-07-10 10:34
    Jack Crenshaw's papers are a wonderful thing for those who would like to have some idea about how compilers do their magic without spending a couple of years on a CS course or two. His writing style is captivating and the example code a breeze to follow. Sadly the series never reaches completion of compilers for either Tiny, the "toy" demo language, or KISS which could actually be useful here and there. However I guess there is enough information scattered through out the papers for an enthusiastic soul to complete either of them. Also techniques in there can be useful for other general programming tasks not just compiler writing.

    From time to time over the years I have looked into the famous Dragon book hoping to glean something about compilers and each time found it totally inscrutable and given up. BUT after working through Crenshaw I now go back to the Dragon and find some parts of it have a light shone on them. For example the first 50 or so pages of the Dragon book talk about analysing source into "parse trees" or "syntax trees". All of which seems too heavy for a hobby project. But at he end of all that section is the statement that for many cases none of that is necessary at all !!. Which of course was the approach demonstrated so elegantly by Crenshaw.

    waltc: I have to say that "unscrupulous Forth toad" might be a bit uncalled for. After all the guy does title his version as "A tribute to this great article series by Jack W. Crenshaw.." and Jack himself did encourage people to build on his work for example by inviting us to implement code generators for Intel processors.

    As it happens a couple of months ago I worked through Crenshaws papers creating my own versions of his code in C. The end result was a compiler for his TINY language into Propeller LMM (Lage Memory Model) Assembler which can be assembled and run via Propasm. If anyone is interested I could dig that out and post it here. I tried to make it as simple and direct as Jacks original code.

    I hope that would not make me an "Unscrupulous Propeller toad" smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • BeanBean Posts: 8,129
    edited 2008-07-10 11:06
    For anyone interested here is a nicely formatted PDF of the original (pascal) series.



    Bean.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson

    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com
  • heaterheater Posts: 3,370
    edited 2008-07-10 21:22
    Thanks Mr Bean smile.gif for that PDF version. I've just been scanning through it and I think I found out why Marcel Hendrix created his Forth version of Jack Crenshaws work. In section 12.3 Jack says:

    "After all, it’s nice to have a small, simple compiler, but it would be of little use if the resulting language were cryptic and hard to program. The language FORTH comes to mind (a premature OUCH! for the barrage I know that one’s going to fetch me)."

    By the way who created that PDF?. It would be nice if they could fix up some of the formatting bugs were the text has been formatted as code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
Sign In or Register to comment.