Meta2 Compiler-Compiler
Mike Green
Posts: 23,101
For those of you with experience in compiler writing ... Here's a little work-in-progress. This is a compiler-compiler that runs on a Propeller (5MHz xtal, 128K EEPROM, attached SD card, programming port as console). It reads a source program from a file on the SD card and compiles it into Spin in another file on the SD card. The language involved is a simple compiler writing language called Meta2 that dates back to the 1960's and has been used to bootstrap several compilers including a Pascal compiler. It needs a little work before I consider it suitable for compiling anything other than itself, particularly the addition of a simple symbol dictionary, but I thought it might be interesting for others to see it now that it can compile itself. The support library (object) may also be generally useful since it has routines to scan Spin and C type comments, convert Spin constant formats to binary, and recognize identifiers and string constants. The actual input and output files are 32K areas in the EEPROM. The EEPROM writing is buffered to minimize the amount of writing. There's a very very simple descriptive document included.
Comments
If I read this correctly, you are only an spin-based editor away from being able to create code & compile on the prop?
<shock>Wow</shock> [noparse]:)[/noparse]
OBC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Just getting started with Propeller?
Propeller Cookbook
PropDOS
It would be relatively easy to make a compiler that would put out Spin byte codes in hexadecimal and make a very very simple assembler that would do a 2nd pass to resolve forward references and adjust links to methods and VAR areas, etc. You'd still need an assembler for any I/O drivers that need assembly language, but, again, this is a start.
Typically, one uses a tool like this to get a minimal "real" compiler going for the language involved (the target), then you rewrite your compiler in the target language and that eventually becomes your finished tool. That's what was done to get a Pascal compiler running on a small 8-bit computer system using a processor much like the Intel 8080.
Post Edited (Mike Green) : 11/29/2007 5:51:02 AM GMT
I sadly have very little experience in compilers..., except assemblers , and not that much.
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Post Edited (Leon) : 11/29/2007 1:44:19 PM GMT
And I think Mike has chosen a minimalist level of abstraction, too!
AND he has stated the prior art[noparse]:)[/noparse]
Rich
Add this one to your "Greatest Threads" list.
I'll try to document it better as I have time.
delivery.acm.org/10.1145/810000/808896/pd1-3-schorre.pdf?key1=808896&key2=6687536911&coll=&dl=ACM&CFID=15151515&CFTOKEN=6184618
Looks like a predecessor to YACC?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Help to build the Propeller wiki - propeller.wikispaces.com
Prop Room Robotics - my web store for Roomba spare parts in the UK
There were a variety of similar tools developed during the 1960's. TMG (stands for transmogrify) is
another presented at the same conference which was used to bootstrap the first C compiler. BCPL
was the predecessor to C and the first BCPL compiler was written in TMG. Meta2 happens to be a
bit easier to implement and less demanding of memory (which is why I chose it here), but it's less
powerful than TMG.