News for hackers. Stuff that matters.
Re:Writing a C compiler in 500 lines of Python by WalterBright on Monday September 04, 2023 @05:30PM (#37385280)
This looks a lot like the Tiny Pascal compiler that BYTE published a listing of back in 1978.

http://www.trs-80.org/tiny-pascal/

I figured out the basics of how a compiler works by going through it line by line.

Re:Writing a C compiler in 500 lines of Python by vgel on Monday September 04, 2023 @05:35PM (#37385328)
Oh, that's neat (funny that they skipped out on similar things to me, like GOTO and structs :-)

I didn't see a link to the source in the article, but this seems to be it: https://sourceforge.net/p/tiny-pascal/code/HEAD/tree/NorthSt...

Re:Writing a C compiler in 500 lines of Python by dugmartin on Monday September 04, 2023 @05:36PM (#37385334)
I think Borland’s Turbo Pascal was also a single pass compiler that emitted machine code as COM files.
Re:Writing a C compiler in 500 lines of Python by kwhitefoot on Monday September 04, 2023 @05:51PM (#37385459)
Surely it is a feature of all Pascal compilers that they are single pass. I thought that it was part of the specification of the language that it be possible to compile in a single pass.
Re:Writing a C compiler in 500 lines of Python by eru on Monday September 04, 2023 @10:55PM (#37387331)
There's a bunch of LLVM-based Pascal compilers these days. I doubt they are single pass, given how LLVM works. (And in general, any optimizing compiler is most likely doing multiple passes.)

You are right about Pascal's original design. Though I'm not sure if that's still true about modern versions of the language?

Re:Writing a C compiler in 500 lines of Python by pjmlp on Tuesday September 05, 2023 @02:16AM (#37388443)
Not even old ones, if we taken optimising compilers like VMS Pascal into account.
Re:Writing a C compiler in 500 lines of Python by drewolbrich on Tuesday September 05, 2023 @12:19AM (#37387799)
It's disturbing to me that I remembered this, but the IBM Pascal Compiler for DOS (1981) had two passes. https://winworldpc.com/product/ibm-pascal-compiler/100
Re:Writing a C compiler in 500 lines of Python by pjmlp on Tuesday September 05, 2023 @02:13AM (#37388425)
Not all, although the language was designed that way.

Some dialects and optimising compilers, had multiple passes.

Re:Writing a C compiler in 500 lines of Python by elvis70 on Tuesday September 05, 2023 @11:47AM (#37393374)
Microsoft Pascal was a two-pass compiler. It was slower to compile than Turbo Pascal and that pissed off Bill Gates when he realized than Turbo was the most successful.
Re:Writing a C compiler in 500 lines of Python by bemmu on Tuesday September 05, 2023 @02:38AM (#37388581)
It makes development so much more fun when you see the results right away.

Pressing "build" in Turbo Pascal on my 386sx it was already done before you could even perceive any delay. Instant.

Re:Writing a C compiler in 500 lines of Python by pantulis on Tuesday September 05, 2023 @03:44AM (#37388985)
I think Turbo Pascal had the capability of generating code directly to memory without generating disk files.
Re:Writing a C compiler in 500 lines of Python by ForOldHack on Tuesday September 05, 2023 @04:16AM (#37389148)
It did that on floppy based systems too. The '87 equipped pcs in the physics building were much faster at 4500 line project, which I worked on for a year. So... First thing to test on a new 33Mhz 386 w/ wolf3d (install only, no source) my project loaded and 33mhz itt 387. Less than 2 seconds. If you brought everything into the ide,and hit run... It screamed.
Re:Writing a C compiler in 500 lines of Python by andrewmcwatters on Tuesday September 05, 2023 @03:35PM (#37396654)
Thanks for sharing this, Walter. I'm always curious where language developers get their experience from.
Re:Writing a C compiler in 500 lines of Python by WalterBright on Tuesday September 05, 2023 @07:20PM (#37399145)
Figuring out how recursive descent worked was just magical.