A compiler in progress
Posted: Tue Sep 07, 2004 3:14 pm
Well, I appear to have chosen a course called PTI, Programming Language (taal) Implementation. Objective is, implement a language in 10 weeks, 8 hours a week work.
Objective for week one (that ends coming thursday) was to implement a compiler for the starting expression language. This language consisted of addition, substraction, multiplication, division, negation and precedence (parentheses handling, plus multiply-over-add). Since there are lots of people here who want to know how a compiler works, and I don't consider this one a load of work (it actually cost around 10 hours, which isn't too much) I'm releasing this compiler (for expressions) under the BSD license.
Combining this with the compiler tutorial here is hard since it's going to go to a C compiler written in C++, whereas the writer of the tutorial uses other languages, both for implementation and for source. The target language is nasm-compatible assembly, which at the time of writing is very shoddy (I had 2 days, only got the assignment on monday, had to be done by thursday) and abuses the x86 as a stack machine, and constantly cleans all registers. This should be gone by the 5th or 6th week, as I'll by then have looked at enough graph coloring algorithms to allow register allocation.
For a tutorial, wait until christmas, then I'll have some day off . Might be coming weekend. Anyway, the code is here, and it's open (just not open enough to call it PD, which only means that I'd like my name to go with it). By the later compiler iterations it'll probably go pd anyway.
The point is, people that are looking for a very simple compiler (10.5k source), try this one. It might not disappoint.
Note that of course, there are other ways to do X and this is only one way to do it. Some parts are done badly because of time constraints, and there is very little comment in the code (although I've tried to keep the code quite clear I wasn't able to add much comment. Will do so tomorrow and upload a new one).
PS: df, could we upload .tar.bz2's and .tar.gz's? .zip really sucks at code compression. The .bz2 was 66% of this size.
Objective for week one (that ends coming thursday) was to implement a compiler for the starting expression language. This language consisted of addition, substraction, multiplication, division, negation and precedence (parentheses handling, plus multiply-over-add). Since there are lots of people here who want to know how a compiler works, and I don't consider this one a load of work (it actually cost around 10 hours, which isn't too much) I'm releasing this compiler (for expressions) under the BSD license.
Combining this with the compiler tutorial here is hard since it's going to go to a C compiler written in C++, whereas the writer of the tutorial uses other languages, both for implementation and for source. The target language is nasm-compatible assembly, which at the time of writing is very shoddy (I had 2 days, only got the assignment on monday, had to be done by thursday) and abuses the x86 as a stack machine, and constantly cleans all registers. This should be gone by the 5th or 6th week, as I'll by then have looked at enough graph coloring algorithms to allow register allocation.
For a tutorial, wait until christmas, then I'll have some day off . Might be coming weekend. Anyway, the code is here, and it's open (just not open enough to call it PD, which only means that I'd like my name to go with it). By the later compiler iterations it'll probably go pd anyway.
The point is, people that are looking for a very simple compiler (10.5k source), try this one. It might not disappoint.
Note that of course, there are other ways to do X and this is only one way to do it. Some parts are done badly because of time constraints, and there is very little comment in the code (although I've tried to keep the code quite clear I wasn't able to add much comment. Will do so tomorrow and upload a new one).
PS: df, could we upload .tar.bz2's and .tar.gz's? .zip really sucks at code compression. The .bz2 was 66% of this size.