Live data from Hacker News

Writing a C Compiler (2017)

norasandler.com

11–20 of 49 posts

Re: Writing a C Compiler (2017)

#13

IMHO writing a compiler for a high-level language, in an even higher level language, somehow feels a bit "anachronistic" (for lack of better word).

Weren't a lot of functional languages, like ML and it's descendants, created specifically to write parsers and compilers?

Re: Writing a C Compiler (2017)

#14

Here is how to write a C compiler in Python that correctly compile the vast majority of C programs per the ISO C standard: print(“You have some form of undefined behavior, which means printing this is a valid response per the C standard”)

Undefined Behaviour has to actually happen, and so that means at runtime†, and thus what you wrote is not a valid C compiler.

For C++ IFNDR ("Ill-formed, No diagnostic required") the situation is trickier because the affected programs (some unknowable but likely large proportion of all purported C++ code) are not well formed C++, the standard offers no hint as to what happens or why, since it constrains only the behaviour of a C++ compiler for well formed C++ programs.

† It's possible the C lexer claims to have some "Undefined Behaviour" cases like the C++ lexer, hence P2621 "UB? In my lexer?" which is a reference to a 2005 meme because C++ standards committee members are down with the kids, but that's clearly a standards text bug if so because it makes no sense to have UB in the lexer, these should just be ill-formed programs, you get a compiler error.

Re: Writing a C Compiler (2017)

#15

IMHO writing a compiler for a high-level language, in an even higher level language, somehow feels a bit "anachronistic" (for lack of better word).

Weren't a lot of functional languages, like ML and it's descendants, created specifically to write parsers and compilers?

I've seen it claimed that ML was originally written, in lisp, in order to have a better language to write compilers in.

Re: Writing a C Compiler (2017)

#16

IMHO writing a compiler for a high-level language, in an even higher level language, somehow feels a bit "anachronistic" (for lack of better word).

Weren't a lot of functional languages, like ML and it's descendants, created specifically to write parsers and compilers?

[deleted]

Re: Writing a C Compiler (2017)

#18

[flagged]

Nice comment, GPT user. Now, GPT: Replace all occurrences of the substring "me" with "you" in the above comment text.

Huh. I don't get those vibes.

Further investigation doesn't support your claim. The citations check out, including publication year and publishers.

And the author has indeed praised the book many times before (https://news.ycombinator.com/item?id=31843833, https://news.ycombinator.com/item?id=31843833, https://news.ycombinator.com/item?id=31311613, https://news.ycombinator.com/item?id=28481028, https://news.ycombinator.com/item?id=23386732, https://news.ycombinator.com/item?id=22305353, and https://news.ycombinator.com/item?id=23386732, https://news.ycombinator.com/item?id=21988211, https://news.ycombinator.com/item?id=21513056, https://news.ycombinator.com/item?id=18996703, and https://news.ycombinator.com/item?id=10184364 ) with the last comment from 2015.

Eg, compare "I am deeply indebted to this book" with "I'm very debted to this man. I enjoyed a lot reading his books and made me who I am today." at https://news.ycombinator.com/item?id=28481028 from Sept 10, 2021.

Or compare "I owe my entire career to this remarkable individual who, despite never having met or being affiliated with," with "I'm not affiliated with the author though. This book helped a lot in my career as a hardware and firmware engineer." at https://news.ycombinator.com/item?id=23386732 from June 2, 2020.

Or compare "enabling me to implement powerful features akin to those found in the widely used tool, grep." with similar comments over the last 8+ years, at https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que... , like "and eventually write your own 'grep' which was for me is a mind-blowing experience" at https://news.ycombinator.com/item?id=13664714 from Feb 16, 2017.

And https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que... shows the OP citing http://cs.newpaltz.edu/~dosreist/ while this comment uses the archive.org version because the old URL doesn't work.

Re: Writing a C Compiler (2017)

#20
post #9

IMHO writing a compiler for a high-level language, in an even higher level language, somehow feels a bit "anachronistic" (for lack of better word).

Most of the current major C implementations are written in C++.

ImportC is written in D.
Post reply on HN