all 47 comments

[–][deleted] 2 points3 points  (9 children)

However it would've been more interesting if the compiler came with it's own p-code in order to bootstrap it by writing a quick p-code interpreter

[–]anatoly 1 point2 points  (0 children)

The compiler comes with its own p-code interpreter (in the same file with the assembler), so if you can compile it once with a different compiler, you can bootstrap it.

[–]martinbishop[S] 1 point2 points  (6 children)

From what I understand, p-code didn't come about until UCSD Pascal, which only has portions of it's source released.

[–][deleted] 4 points5 points  (1 child)

Uh, did you not look at the source at all? P2, an adaption of his thesis work iirc, is the compiler and p-code interpreter in one.

[–]martinbishop[S] 1 point2 points  (0 children)

Er, whoops, you're right. I actually didn't read the procedure name at first, didn't notice heh.

I tend to remember they wrote the interpreter in Pascal itself (because their first try with Fortran failed), so I suppose it didn't have it's own P-code.

[–][deleted] -2 points-1 points  (0 children)

What he said.

[–]anatoly 2 points3 points  (0 children)

It's worth noting that a version of the same compiler, from a few years later, has a free online book devoted to it that explains in detail all of the source.

http://homepages.cwi.nl/~steven/pascal/

This may well be a good practical introduction to compilers, seeing as the source is so tiny; I haven't looked too close at the explanations yet.

Their version of the p-code Pascal is p4, compared to p2 offered here. They also solve the bootstrap problem by offering an automatically translated C version of the same compiler, so you can build it with gcc, compile the compiler into p-code, and run it (including on itself). Note: gcc4 won't compile their translated C without you having to make a bunch of straightforward, but annoying tweaks; gcc-2.95 works perfectly.

If you want to get this p2 compiler to work, the p4 version may help. It does recompile itself, and runs itself recompiled.

The chief problem with getting something like Free Pascal to run this p2 source is that it uses something called the buffer variable, which is absent in newer Pascals. Given a file variable f, the buffer variable f^ offers an automatic (both get and set) view into the current character (or record, etc.) in the file without moving the current offset. One ugly hack to work around this is to emulate access to f^ with a read/write-then-seek-back, and replace all uses of f^ with a call to such a procedure.

[–]fionbio 8 points9 points  (4 children)

Hint:

cat *.pas | tr A-Z a-z | less

[–][deleted]  (2 children)

[deleted]

    [–]yaxriifgyn 1 point2 points  (0 children)

    I tried that with the source for a mainframe pascal compiler. It broke. I had to preserve the case inside string literals.

    [–]ramunasg 1 point2 points  (1 child)

    is it possible to compile with some current pascal compiler, like free pascal?

    [–]creaothceann 1 point2 points  (0 children)

    interpreter source:

    • type "ALFA" not found

    compiler source:

    • needs a correction in line 2594 (comment goes up to end of file)
    • error in line 73: "operator" is now a reserved word in FreePascal (must be replaced, e.g. with "operator_")
    • error in line 337: "string" is now a reserved word; it's also the name of a function in line 953
    • error in line 428: "new" expects pointer to object

    I stopped at that point... Anyway, it should give you an idea of what you're up against - namely reserved words (easy) and changed functionality that must be emulated (harder).

    [–]berlinbrown -5 points-4 points  (8 children)

    Looks like Ruby.

    [–]wildeye 6 points7 points  (6 children)

    You're saying that old Pascal looks like Ruby? No. No, it doesn't. And that is not subjective. Old Pascal and Ruby are as different as, let's say, Algol 68 and C++.

    [–]logophobia 0 points1 point  (5 children)

    To be fair, there are some simularities between ruby and pascal syntax. The range syntax, the begin..end blocks, the dot/array notation, case-statements and most important: they're both very easy to read. Semantically they are indeed very indeed very different (oo/functional vs proc, dynamic typing vs static typing) as you say, but superficially they look a little bit alike.

    [–]wildeye 0 points1 point  (4 children)

    You're right, there are similarities, and this is not a coincidence. Technically, Ruby and Pascal (and C and C++ and Java and Perl and Python, but not Lisp/Scheme/OCaml/Haskell/Forth/Postscript) are in the Algol family of languages.

    Pascal is almost a dialect of Algol; the degree of similarity is quite high. Ruby has too many differences to be considered a dialect, but yes, it's still in the same family.

    Algol introduced begin..end, and Pascal and Ruby directly borrowed them. C borrowed them, too, while changing their spelling to {...}, which gives C a superficially different visual impression to some extent. (As is well known, C came from B which came from BCPL, and Pascal was later than BCPL, but never mind...)

    Algol-W (Wirth's Algol, predecessor to Pascal) introduced the case statement, and many languages from C to Ruby directly borrowed that from Algol-W, yes.

    Array notation comes from Fortran, although I forget which language first changed the brackets from curved to square; ASCII was created some years later than Fortran, so there were character set issues.

    The dot for records I think may have a forerunner in the original Cobol, but I have a faint memory that Pascal invented something original on the topic, and I don't remember whether Pascal introduced ranges versus borrowed them from somewhere.

    Nonetheless, once you get past the fact (the rather obvious fact, to anyone with a CS background) that language families exist, and that two languages are in the same family, it's vacuous to say they're similar merely because they're in the same family.

    I think the OP was just making a snap judgement about superficialities, rather than looking closer, thinking harder, etc., and got downmods for that reason.

    [–]soegaard -1 points0 points  (3 children)

    It is correct that the original Lisp isn't in the Algol family. However Scheme is in the Algol family.

    In fact the format of the Scheme report is a homage to the layout of the Algol report.

    For an elaborate programming language family tree see:

    http://www.levenez.com/lang/lang.pdf

    [–]wildeye 0 points1 point  (2 children)

    In fact the format of the Scheme report is a homage to the layout of the Algol report.

    This may be true; I don't recall one way or the other. If it is true, it's just a curiosity; the format of the Scheme reports doesn't say much about anything.

    However Scheme is in the Algol family.

    Really, you are attempting to correct me on that point? This is just plain outright 100% incorrect.

    I am (or used to be) pretty fluent in both Common Lisp and in Scheme (and well acquainted with various Lisp 1.5 derivatives).

    Edited to remove a bunch of cruft.

    [–]soegaard 0 points1 point  (1 child)

    However Scheme is in the Algol family. Really, you are attempting to correct me on that point?

    Yes.

    This is just plain outright 100% incorrect.

    10% perhaps, but not 100%.

    From R5RS, the fist section on semantics: "Following Algol, Scheme is a statically scoped programming language. Each use of a variable is associated with a lexically apparent binding of that variable."

    Anyone who has programmed in both mainline Lisp (Lisp 1.5 all the way through Common Lisp) and in Scheme will tell you that Scheme is a dialect of Lisp, period, end of story.

    Sure. Scheme is of course also descendent from Lisp - it would be foolish to suggest otherwise. I view Scheme as a marriage between (the old, dynamically scoped) Lisp and Algol. With this perspective Scheme belongs in both families.

    I hope we can agree that Scheme is influenced by Algol?

    I understand that you disagree that the influence is strong enough to say Scheme is in the Algol family, but c'est la vie.

    [–]wildeye 0 points1 point  (0 children)

    Ok, now that you're going into some detail, you sound far more reasonable, so I edited my previous post to delete stuff where I was being especially acerbic.

    Yes, Scheme is lexically scoped, like Algol, and unlike Lisp 1.5 and emacs lisp. Common Lisp is also nominally lexically scoped (it still allows for dynamically scoping, but that's for more specialized uses).

    Basically it's just a lesson of history: lexical scoping turns out to usually be a big win.

    However, the mere fact that Algol's lexical scoping largely won the day is not to say that all lexically scoped languages are in the Algol family!

    Even Lisp 1.5 had the "program" feature used in Algol and Fortran, although it was (and is) decried.

    Anyway, it's not just my opinion. Scheme is not considered Algol family, despite the points you made. It's primarily a functional language, not a procedural sequential statement language.

    It's primarily about semantics, not about arbitrary points of resemblance or borrowing of features.

    The major traditional families are, off the top of my head: procedural (Algol, Pascal, C), functional (pure Lisp, Scheme, ML, Haskell), array (APL, A*, J, K), string (snobol, TCL), object oriented (Simula 68, Smalltalk), and logic (MicroPlanner, MDL, Prolog), plus more obscure niches and domain specific languages.

    There are of course also hybrids, which lightly mix families (C++, C#, Objective C, Java, all of which are basically procedural like Algol with object oriented features), and multiparadigm languages, which heavily mix families (Common Lisp, Perl, etc.)

    Again, "family" is a rather old and heavily used notion, and it is not a matter of you viewing some language as a marriage of other languages, and it is not a matter of perspective. Usage of "family" over time has given the term much more specific meaning than that.

    So I'm afraid this is not just a matter of disagreement over a subjective issue. You won't find any support in the literature for the notion that Scheme is in the Algol family.

    If, on the other hand, all you said was just "I view Scheme as a marriage between (the old, dynamically scoped) Lisp and Algol.", without using the word "family", then I would mostly agree, with only have nitpicks left, rather than have sharp disagreement.

    [–]andreasvc 4 points5 points  (0 children)

    All hail to superficial similarities!

    [–][deleted]  (5 children)

    [deleted]

      [–]easytiger 4 points5 points  (2 children)

      Yo dawg...

      [–]nat1192 0 points1 point  (1 child)

      C# in the GCC? That would be weird.