How do I create my own programming language and a compiler for it
programmers.stackexchange.com
programmers.stackexchange.com
Pretty much people would say, "I know [VB6|Python|Javascript|HTML] and I want to make an OS. Tell me how"... Like compiler design, building a kernel is one of the most complicated types programming, and none of them had anywhere near the coding skill or experience to do it (or the patience usually - coding an OS for the most part is far less exciting than it sounds - the breakthroughs are great but they usually take intense debugging and reading great deals of the Intel and AMD manuals).
This guy has actually done some research (including reading books!), which was unheard of from most newbies there, so he's doing far better. But if he doesn't know how libraries are made, he should get some experience doing that in C or C++, and will need a good grasp of Assembler if he's going to do code generation.
Watch this video:
http://video.google.com/videoplay?docid=7654043762021156507#
Barely anyone knows how to make a lathe from scratch. A lathe might not be a particularly good example but if you look at society as a whole you can see that a lot of our infrastructure depends on existing infrastructure to make improvements, and that we don't have documents to show how to go from subsistence farming to modern civilization as a bunch of things that we used to need can no longer be made.
IIRC, there is an 'open source' project to create this so that countries can bootstrap themselves out of their developmental quandaries. The idea is that you can build modern society from a few simple machines you can make by hand.
Self-hosting is the nature of the universe, it's only via consumerism that we find this processing unnatural.
Now, this makes perfect sense if you understand the concept of sequence points, but you wouldnt see that explanation in most books.
To me, it seems like that would be evaluated by operator precedence...
++ has a higher precedence than +
So let i=1. The expression then becomes:
j = i++ + ++i;
j = {1}++ + ++{1};
j = 1 + 2; OR, j = 1 + 3;
Aha. And that's the undefined behavior.Ew. That seems like the type of problem which shouldn't have to be debugged, because the code shouldn't have been written like that to begin with.
Heck, it seems like the compiler shouldn't even allow that code to compile in the first place... But I guess there are technical problems with disallowing that? (Not the least of which is, it would break existing code.)
And if you want to get even funkier, try this in other languages (python yields 2, bash yields 4)
$ python -V
Python 2.6.1
$ python -c 'x=1;y=x++ + ++x; print y'
2
$ x=1; echo $((x++ + ++x))
4 y = x + (+(+(+(+x))))Concerning python's lack of pre and post increment, the decision was made primarily because there are a lot of confusing situations, such as the aforementioned, with the increment and decrement operators. However, the decision to allow x++x to be valid, and parsed as x + (+ x) = x + x, is itself terribly confusing and germane to the original discussion
I wish that, if someone is overcome by the vapors of the NIH disease, such a person would confine their reinvention of the wheel to their personal time and not introduce such silliness to the workplace.
Of course, I wish for lots of things.
For example, ruby: http://linuxdevcenter.com/pub/a/linux/2001/11/29/ruby.html
(In this interview he uses the magical phrase "principle of least surprise")
That being said, I found EOPL 3ed also didn't live up to it's reputation. I don't really know what I'm looking for in an introductory PL text, something that could bridge the divide between the end of SICP and the more advanced, serious PL stuff. I don't know if such a text exists.
There's also "design concepts in programming languages".
[1] http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/
I actually think that skipping parsing altogether, the way a lot of Lispy texts do is the way to go for intro PL stuff, because you can get to interesting stuff much faster.
My gripe about PLP is that after deciding to cover parsing and scanning, he goes too fast. I might have been happier if he'd skipped it altogether.