Shop OBEX P1 Docs P2 Docs Learn Events
Meta2 Compiler-Compiler — Parallax Forums

Meta2 Compiler-Compiler

Mike GreenMike Green Posts: 23,101
edited 2007-11-29 21:20 in Propeller 1
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

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2007-11-29 05:27
    Mike,

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-29 05:40
    Not quite. This compiles currently to Spin source code which has to be transferred to a PC for compilation using the Propeller Tool, but it's a step in the right direction. I've used this compiler-compiler for transforming data and scripting information as well. For example, you could take some kind of complex table and turn it into a sequence of decimal numbers, one per line of text. A Spin program could then just read the list of numbers without having to do complex parsing of a data file.

    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
  • AleAle Posts: 2,363
    edited 2007-11-29 06:30
    Now this is interesting !, I wonder if this can be modified to produce assembler language.... you would not need to transfer it to the pc.

    I sadly have very little experience in compilers..., except assemblers smile.gif, and not that much.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-29 06:44
    It doesn't need any modification to produce assembly language. It basically takes a text file and transforms it into another text file. It has provisions for keeping an indent level because of Spin's use of indenting to handle block structures, but you don't have to use it. It makes up its output lines from pieces of literal text (strings) and scanned tokens (strings, identifiers, or numbers).
  • AleAle Posts: 2,363
    edited 2007-11-29 08:11
    This needs more investigation from my part... After a fast read of your description I coudn't grasp the basics of this language, not even looking at the source files.... I'm for a posterior era, we had already BASIC and z80s smile.gif. Any source of info (wikipedia has nothing on Meta2 :-( ) ?
  • toru173toru173 Posts: 17
    edited 2007-11-29 11:10
    I second the request for more info! It sounds interesting
  • LeonLeon Posts: 7,620
    edited 2007-11-29 13:27
    Try looking for Meta II. I remember playing with it some years ago, I found a version somewhere that ran on a PC.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle

    Post Edited (Leon) : 11/29/2007 1:44:19 PM GMT
  • rjo_rjo_ Posts: 1,825
    edited 2007-11-29 14:27
    It looks to me that one of the potential applications... which is dear to my heart... would be a string based numeric compiler, which would un-bind numeric computations from the architecture of the processor... allowing for un-scaled computations.

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-29 15:33
    If you do a web search for Meta2, you will find several different Meta2's. This one is unrelated and predates the others.

    I'll try to document it better as I have time.
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-11-29 16:38
    Is this it?

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-29 17:40
    That's it. Thanks for looking it up. I don't know what the developers of YACC used for their model.
    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.
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-11-29 21:20
    Mike, Ouroboros comes to mind as a name for your program.· http://en.wikipedia.org/wiki/Ouroboros
Sign In or Register to comment.