Earlier quoted context omitted.
Exactly. You have to drop hooks into the lexer from the parser, and by the time you're done you end up with just as much code. Only it's slower than a recursive-descent parser would be, and a lot of the time parsing speed really matters because it shows up as user-visible latency.
While I have a strong dislike for lex/yacc and descendants, the "hooks" you need for C are trivial. As far as I remember the only thing you need is an ability for the lexer to check whether or not a given identifier is a variable or type. Even that is only needed if you want to report more specific information up to the parser. E.g. Clang doesn't. In Clang it is instead the parser that looks up the information in ord…
C4 – C in 4 functions
131–140 of 142 posts
Re: C4 – C in 4 functions
#132This shit doesn't scale: $ time ./c4 c4.c c4.c hello.c hello, world exit(0) cycle = 9 exit(0) cycle = 22614 exit(0) cycle = 9273075 real 0m0.067s user 0m0.067s sys 0m0.000s $ time ./c4 c4.c c4.c c4.c hello.c hello, world exit(0) cycle = 9 exit(0) cycle = 22614 exit(0) cycle = 9273075 exit(0) cycle = 933197195 real 0m5.834s user 0m5.827s sys 0m0.000s $ time ./c4 c4.c c4.c c4.c c4.c hello.c Just kidding. :) Amazingly c…
Re: C4 – C in 4 functions
#133On a first skim, this looks really nice; complaints that it's unreadable are unfounded. The background that makes it readable are Wirth's Compiler Construction http://www.ethoberon.ethz.ch/WirthPubl/CBEAll.pdf plus precedence climbing http://en.wikipedia.org/wiki/Operator-precedence_parser#Prec...
> complaints that it's unreadable are unfounded int *a, *b; int t, *d; I can't really see how anyone can say that code that uses one-letter variable names (with the exception of the "standard ones", whose meaning is defined at the top) is readable.
Re: C4 – C in 4 functions
#134On a first skim, this looks really nice; complaints that it's unreadable are unfounded. The background that makes it readable are Wirth's Compiler Construction http://www.ethoberon.ethz.ch/WirthPubl/CBEAll.pdf plus precedence climbing http://en.wikipedia.org/wiki/Operator-precedence_parser#Prec...
> On a first skim, this looks really nice; complaints that it's unreadable are unfounded. Man, I can't even tell what this is supposed to be. My confusion is entirely founded. My thought process with articles like this goes something like "C in four functions, huh? Sounds like it could be clever. I'll just click and read the explanation... Oh, there isn't an explanation. Well, maybe this file will explain things! ...…
I hope someone will write an explanation. I'm still working on one for my own (quite different) little compiler.
Re: C4 – C in 4 functions
#135Re: C4 – C in 4 functions
#136Earlier quoted context omitted.
I don't think we really do. It is impenetrable black magick if one "knows" C -- but quite clear if one /actually/ knows C.
Ah, the No True Scotsman finally arrives to the party.
Re: C4 – C in 4 functions
#137Earlier quoted context omitted.
I mostly strongly disagree. I see no value in naming a variable 'tk', 'pp', or 'bt'. It can only help to make the code more readable with less context. I do not need to understand compilers in detail to know what this program is doing, except, for the names being useless. And if I do understand them but have not spent half an hour or probably much more to digest the exact system by which it operates, I would be compl…
As you wish. From the program, line 19: tk, // current token
Re: C4 – C in 4 functions
#138This shit doesn't scale: $ time ./c4 c4.c c4.c hello.c hello, world exit(0) cycle = 9 exit(0) cycle = 22614 exit(0) cycle = 9273075 real 0m0.067s user 0m0.067s sys 0m0.000s $ time ./c4 c4.c c4.c c4.c hello.c hello, world exit(0) cycle = 9 exit(0) cycle = 22614 exit(0) cycle = 9273075 exit(0) cycle = 933197195 real 0m5.834s user 0m5.827s sys 0m0.000s $ time ./c4 c4.c c4.c c4.c c4.c hello.c Just kidding. :) Amazingly c…
$ time ./c4 c4.c c4.c c4.c c4.c hello.c
hello, world
exit(0) cycle = 9
exit(0) cycle = 22614
exit(0) cycle = 9273075
exit(0) cycle = 933197195
exit(0) cycle = -1428163377
real 9m23.409s
user 9m22.673s
sys 0m0.020s
:)Re: C4 – C in 4 functions
#139Earlier quoted context omitted.
In the sense that some people won't have an idea of what's going on, this community altogether isn't particularly inclusive at all. Personally, I really don't want the topics this site covers to cater to a lowest common denominator, and I'm sure that isn't what you had in mind either, but that's the effect of taking "more of us" to mean more than you personally.
The logical leap from adding a "few hints" to everything becomes "lowest common denominator" is the size of the Grand Canyon.
With code like this, the readability obviously isn't a high priority consideration and sometimes the exact opposite of the goal, with the impenetrability sometimes being part of its charm. This is Hacker News after all, and if your reaction to of a piece of code that describes itself as "an exercise in minimalism" is to leave a snarky comment about the lack of documentation, you should probably check your news elsewhere.
If you have any interest in the subject, the initial comment "just enough features to allow self-compilation and a bit more" should give the purpose of the code away. If not, it ought to have been a clear sign of dragons.
Re: C4 – C in 4 functions
#140Earlier quoted context omitted.
In the sense that some people won't have an idea of what's going on, this community altogether isn't particularly inclusive at all. Personally, I really don't want the topics this site covers to cater to a lowest common denominator, and I'm sure that isn't what you had in mind either, but that's the effect of taking "more of us" to mean more than you personally.
Actually, a lot of us probably don't understand what this is doing. I sure don't, but I really don't consider myself "lowest common denominator" either. I come here to learn, to be honest!
This submission in particular has dubious practical use, and the description, "an exercise in minimalism", is telling of a sort of artistic intent. If you don't understand what it does, how it does it, or if you don't like it, it won't lower my opinion of you in any way, but its inclusion on this site is part of why I like to come here every now and then. I get to discuss subjects that relate to my work and hobbies, but I also get to look at weird alien code and think hard in unfamiliar terms. From what you are saying, I think you can relate.
Personally, I could glance over it and get the idea that it is a C compiler, but if you were to show me some code in written with the latest JS MVC or FRP framework, don't hold your breath for me to tell you what it does. I can't say that I fully understand this, and that's why I enjoy the rich discussion the submission spawned here.