News for hackers. Stuff that matters.
Re:Introduction to Compilers and Language Design (2021) by isaacfrond on Wednesday May 18, 2022 @03:38AM (#31420178)
Great initiative. More professors should do this; write your own material suitable to teach a course, and make it freely available.

What I also like is that if you find errata, you have a place to send them, with a reasonable expectation that they will be picked up in a new version.

Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @04:33AM (#31420464)
A shame that it uses C though, imo, instead of being language agnostic.
Re:Introduction to Compilers and Language Design (2021) by metalloid on Wednesday May 18, 2022 @05:28AM (#31420717)
In the introduction (1.4. What language should I use?) - the author explains why he used C. Please read it.
Re:Introduction to Compilers and Language Design (2021) by episode0x01 on Wednesday May 18, 2022 @04:37AM (#31420487)
I mean isn't C ubiquitous enough that it is essentially language agnostic? Or is your suggestion that is should be purely pseudocode?
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @08:26AM (#31421905)
With C you need to pay attention to things like manual memory management which aren't necessary with other languages or to understand the material.
Re:Introduction to Compilers and Language Design (2021) by s_dev on Wednesday May 18, 2022 @10:55AM (#31423564)
Aye but these lads are building a compiler. Probably shouldn't hide things like 'memory management' at the introduction stage as use of memory is inherent to all computing and programming.
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @11:06AM (#31423713)
Sure, that makes sense, but you can write a compiler in languages that don't require it themselves. That's what I meant.
Re:Introduction to Compilers and Language Design (2021) by arinlen on Wednesday May 18, 2022 @05:04PM (#31427642)
> Sure, that makes sense, but you can write a compiler in languages that don't require it themselves.

I don't follow your rationale. With C the developer manages heap memory by basically calling malloc and free.

This means that once you have the memory model set, all you need to do to roll your compiler is to implement the interface.

A language that "don't require it themselves" is a language which provides only high level constructs and dumps all the memory management logic to the compiler/runtime, from object allocation/deallocation to lifetime management.

How is that simpler to pull off by a compiler writer?

Re:Introduction to Compilers and Language Design (2021) by Koshkin on Wednesday May 18, 2022 @07:51PM (#31429021)
The target language generally has nothing to do with the language of the compiler, where automatic memory management is just as useful (and also helps to minimize the amount of unrelated technical detail) as anywhere else.
Re:Introduction to Compilers and Language Design (2021) by programmer_dude on Wednesday May 18, 2022 @09:31AM (#31422536)
Manual memory management is optional. IIRC some version of the D compiler was written assuming an infinite virtual address space (basically they just did not bother calling free() ever)!
Re:Introduction to Compilers and Language Design (2021) by duped on Wednesday May 18, 2022 @11:12AM (#31423797)
There's a chapter in the book dedicated to memory layout of programs that discusses program segments, paging, implementation of malloc/free, etc that is more or less required before getting to the assembler and codegen stages.

Even if you can write a compiler assuming infinite memory that generates programs that also assume it, it would be a disservice to readers to ignore that for brevity. It's an important part of understanding how programs are created.

Re:Introduction to Compilers and Language Design (2021) by melony on Wednesday May 18, 2022 @11:06AM (#31423721)
Is that why D is so prevalent among (some) quant shops?
Re:Introduction to Compilers and Language Design (2021) by Koshkin on Wednesday May 18, 2022 @07:54PM (#31429039)
Yes. Pseudocode is better for teaching than C. Plus, translating pseudocode into a language of choice is a good exercise.

Another good idea is to write a compiler in the target language.

Re:Introduction to Compilers and Language Design (2021) by programmer_dude on Wednesday May 18, 2022 @04:47AM (#31420541)
Pseudocode can be easy to understand but you (also) need a real language to cement your understanding of the subject.
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @08:57AM (#31422172)
> you (also) need a real language to cement your understanding of the subject.

That's why I'd like to use a language that I already know instead of learning a new one while also learning new material.

Re:Introduction to Compilers and Language Design (2021) by d_tr on Wednesday May 18, 2022 @11:15AM (#31423839)
Well you can. If you understand the algorithm you can write it in any language you know. Additionally, C is at basic level just loops, conditionals and function calls so it will be easy to translate from it if you need to. And then there are other books using other languages out there and people can choose.
Re:Introduction to Compilers and Language Design (2021) by Koshkin on Wednesday May 18, 2022 @08:00PM (#31429093)
It is also manual memory management, lack of generics, of polymorphism, and what not else. Even C++ would be a better choice.
Re:Introduction to Compilers and Language Design (2021) by programmer_dude on Wednesday May 18, 2022 @09:33AM (#31422553)
Basic C is not that hard. Probably one of the easiest languages to get into.
Re:Introduction to Compilers and Language Design (2021) by Koshkin on Wednesday May 18, 2022 @08:01PM (#31429104)
Sure, but it’s a hard language to write good code in.
Re:Introduction to Compilers and Language Design (2021) by lelanthran on Wednesday May 18, 2022 @04:54AM (#31420575)
> A shame that it uses C though, imo, instead of being language agnostic.

What did you have in mind?

Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @08:25AM (#31421887)
Honestly, I think I'd prefer pseudocode that I can read to understand the idea and then work in my language of choice rather than C.
Re:Introduction to Compilers and Language Design (2021) by ethanwillis on Wednesday May 18, 2022 @10:06AM (#31422937)
Psuedocode means ambiguity which means misunderstandings. As soon as you remove all ambiguity any Pseudocode just becomes a language.
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @11:01AM (#31423654)
Good point, although I think it should be doable when describing input and output well enough.
Re:Introduction to Compilers and Language Design (2021) by setr on Wednesday May 18, 2022 @02:09PM (#31425837)
That's been delegated to the diagrams and algebra -- and there's also the usual english-psuedocode interspersed throughout the chapters (presumably more so on the theoretical chapters e.g. chapter 4)
Re:Introduction to Compilers and Language Design (2021) by arinlen on Wednesday May 18, 2022 @04:58PM (#31427569)
> Honestly, I think I'd prefer pseudocode that I can read to understand the idea and then work in my language of choice rather than C.

What stops you from understanding the idea by reading C? It's a tried-and-true language whose K&R version fits entirely in an easy to read ~180pg book which has real world applications, unlike pseudocode.

Re:Introduction to Compilers and Language Design (2021) by Koshkin on Wednesday May 18, 2022 @08:20PM (#31429214)
C code is usually rife with unrelated technical detail like manual memory management. It also lacks ways to build useful abstractions that exist in other languages.
Re:Introduction to Compilers and Language Design (2021) by globuous on Wednesday May 18, 2022 @08:59AM (#31422186)
Agreed! I would have used ML faminly languages. Of course, that implies learning ML before reading the book whereas C is definitely known by more developers as it’s been in all of our courses
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @09:03AM (#31422248)
Sure, then it would be the same thing just with ML (which I pers. would prefer to C, but yeah). Pseudocode to explain the idea would be ideal, then you can work through the book in a familiar language.

C is fine, it's just not ideal for me to learn C which I have no use for and learn a new skill at the same time.

Re:Introduction to Compilers and Language Design (2021) by capitalsigma on Wednesday May 18, 2022 @10:17AM (#31423083)
ML-like pseudocode would be much different from C-like or python-like pseudocode (e.g. heavy use of ADTs)
Re:Introduction to Compilers and Language Design (2021) by chrisseaton on Wednesday May 18, 2022 @06:57AM (#31421251)
I think C is basically language agnostic, isn't it? Approximately everyone working at the level of a course on compilers knows C.
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @08:24AM (#31421878)
I don't know C and have no intention of learning it, so I'd prefer pseudocode that I can read without already knowing C or investing time into learning C just for this book.
Re:Introduction to Compilers and Language Design (2021) by chrisseaton on Wednesday May 18, 2022 @08:29AM (#31421932)
I really struggle how someone can be ready to learn about compilers without already having enough context where they know C. If you know enough to be doing compilers, you can pick up C in 15 mins.
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @08:38AM (#31422010)
I don't know how this is difficult to imagine. I have no need for C and am interested in interpreters and compilers.
Re:Introduction to Compilers and Language Design (2021) by chrisseaton on Wednesday May 18, 2022 @08:45AM (#31422063)
> have no need for C and am interested in interpreters and compilers

But you do have a need for it, because it’s the lingua franca of conversations about compilers and interpreters… as you’ve just found out with this course.

Like saying you want to work in the Vatican but you have no need for Latin.

Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @08:55AM (#31422153)
> because it’s the lingua franca of conversations about compilers and interpreters

There are many materials, compilers, and interpreters that use ocaml and haskell, for example. C isn't the only one. That's why I'd prefer pseudo code instead of C, so that I could use this book without learning a specific language only for it.

Re:Introduction to Compilers and Language Design (2021) by chrisseaton on Wednesday May 18, 2022 @09:05AM (#31422267)
I really don’t understand what you’re planning to do the first time someone says to ‘check the header file’ to understand how some system call works.
Re:Introduction to Compilers and Language Design (2021) by rhn_mk1 on Wednesday May 18, 2022 @09:40AM (#31422626)
For that, you don't need to know C the language, but C the calling convention https://gankra.github.io/blah/c-isnt-a-language/
Re:Introduction to Compilers and Language Design (2021) by chrisseaton on Wednesday May 18, 2022 @09:46AM (#31422690)
This doesn't make any sense. Even you knew the C calling convention, but not C, where are you going to get documentation for system calls that doesn't use C code? The Linux, macOS, etc documentation uses C.
Re:Introduction to Compilers and Language Design (2021) by t-3 on Wednesday May 18, 2022 @12:46PM (#31424908)
Reading the headers and prototypes in the man pages doesn't require "knowing" C. You just need to know the very simple subset of C's syntactical rules and the calling conventions. Anyway, reading C is far easier than writing C, most popular languages use the same syntax and operators.
Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @09:47AM (#31422715)
I don't know what that has to do with learning about compilers and interpreters.
Re:Introduction to Compilers and Language Design (2021) by chrisseaton on Wednesday May 18, 2022 @10:09AM (#31422976)
> I don't know what that has to do with learning about compilers and interpreters.

Compilers and interpreters, unless they're running on bare metal, which is very niche, talk to the operating system using something called 'system calls' to ask for resources that they can't provide themselves, like virtual memory space and IO. These system calls are documented in C.

For example I wrote a Ruby compiler in Ruby, but I still need to know about the mmap system call, which is documented in C, to allocate my memory.

https://github.com/chrisseaton/rhizome/blob/main/doc/memory....

https://man7.org/linux/man-pages/man2/mmap.2.html

https://github.com/chrisseaton/rhizome/blob/main/lib/rhizome...

Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @10:47AM (#31423460)
Now I can finally reply: that makes sense, and in hindsight is quite obvious, thanks. My general lack of knowledge in this area is a part of why I'd like to study it more, but preferably I'd like to use a language I'm already comfortable with. C is just very far removed from everything I have use for and am interested in.
Re:Introduction to Compilers and Language Design (2021) by Koshkin on Wednesday May 18, 2022 @08:09PM (#31429151)
> These system calls are documented in C.

Sure, but the compiler will still have to generate machine code for those.

Re:Introduction to Compilers and Language Design (2021) by ethanwillis on Wednesday May 18, 2022 @10:04AM (#31422916)
Well, the author shouldn't have to potentially learn another language just to write a book on compilers and interpreters.

Maybe... MAYBE you don't have to read this book.

Re:Introduction to Compilers and Language Design (2021) by dunefox on Wednesday May 18, 2022 @10:48AM (#31423482)
> Maybe... MAYBE you don't have to read this book.

Where did I say I have to read it or that the author should learn another language? Nowhere. I said I wish it wasn't using C so that I could read it more easily.

Re:Introduction to Compilers and Language Design (2021) by d_tr on Wednesday May 18, 2022 @11:36AM (#31424080)
You will have to learn whatever it is you do not like about C anyway if you want to generate machine code.