←back to thread

517 points petercooper | 1 comments | | HN request time: 0.001s | source
Show context
TazeTSchnitzel ◴[] No.8559029[source]
Pretty damn impressive.

Though I must wonder: how complete is it? What does it and does it not support? It's at least complete enough to be self-hosting, but beyond that? The code doesn't use that much of C.

replies(2): >>8559058 #>>8559068 #
cbhl ◴[] No.8559058[source]
Judging from the comments in c4.cpp, it probably only supports enough of a subset to compile itself.

Granted, while building a parser that can parse (let alone compiling) the full C language is nontrivial, any undergrad should be able to build a parser and compiler for a sufficiently simple subset of it. (In my undergrad, we used this subset to build a "compiler" in second year: https://www.student.cs.uwaterloo.ca/~cs241/wlp4/WLP4.html)

replies(2): >>8559064 #>>8560966 #
JoeAltmaier ◴[] No.8559064[source]
You can build a C parser in an afternoon. It only has a few language constructs. Declarations are the hardest. Scanners are readily available for expressions and constants.
replies(2): >>8559077 #>>8560875 #
rui314 ◴[] No.8560875{3}[source]
C is not a simple language as a CIL guy says [1]. I wrote my own C compiler [2] and I can say that writing a parser was harder than I thought. It would take more than half a day at least.

[1] http://www.cs.berkeley.edu/~necula/cil/cil016.html [2] https://github.com/rui314/8cc

replies(2): >>8560897 #>>8561106 #
1. zik ◴[] No.8560897{4}[source]
Yes, I also wrote my own C interpreter and the parser was a lot more than a day's work.