This is a fascinating tool. I wrote a python Meta II engine (attached.) It regenerates the asm source for the metacompiler but I haven't (yet) written a python-emitting metacompiler, just a VM for Meta II. (I'm actually targeting AVR microcontrollers but I'll almost certainly write a python META just for kicks.)
Warm regards and gratitude! ~Simon On Sun, Nov 25, 2012 at 10:48 AM, Long Nguyen <[email protected]> wrote: > Thanks, Robert. Here is a fixed version of support.h with improved error > handling. > > Long > > On Sat, Nov 24, 2012 at 11:37 PM, Robert Feldt <[email protected]> > wrote: >> >> Thanks Long, this was a great meta-II to build on. >> >> I had to fix a bug in support.h (see diff at bottom) but then used your >> code to bootstrap the following, self-contained (i.e. contains its own >> support code (a bit hackish but good for learning)) Ruby version in 28 >> non-empty lines: >> >> .syntax RMetaII >> >> arg = '$' <'@o.print @t'> >> | .string <'@o.print ' $>; >> >> output = '<' *arg '>' <'@o.print "\n"'>; >> >> exp3 = .id <'compile_' $> >> | .string <'@i.scan /\s*/; s=' $> >> <'@f = (@i.peek(s.length) == s) ? (@t=s; @i.pos += s.length) : >> nil'> >> | '.id' <'@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/'> >> | '.string' <'@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/'> >> | '(' exp1 ')' >> | '.e' <'@f = true'> >> | '*' <'begin'> exp3 <'end while @f'> <'@f = true'>; >> >> exp2 = ( exp3 <'if @f'> | output <'if true'> ) >> *( exp3 <'raise("error at: " + @i.rest.split("\n")[0]) if !@f'> >> | output ) <'end'>; >> >> exp1 = <'begin'> exp2 >> *( '|' <'break if @f'> exp2 ) >> <'end while false'>; >> >> stat = .id <'def compile_' $> '=' exp1 ';' <'end'>; >> >> program = '.syntax' .id >> <'#!/usr/bin/env ruby'> <'require "strscan"'> >> <'class ' $> <'def compile(str, out)'> >> <'@i, @o = StringScanner.new(str), out'> >> <'compile_program'> <'end'> >> *stat '.end' <'end'> >> <'puts "Usage: meta_compiler <input> <output>" unless ARGV.length == 2'> >> <'File.open(ARGV[1], "w") {|f| RMetaII.new.compile(File.read(ARGV[0]), >> f)}'>; >> >> .end >> >> Very little error handling and I'm sure there are bugs but it's a start... >> :) >> >> The reverse order of the rules are really just an artefact of basing it on >> Long's version. Ruby does not require a certain order so can be reformatted >> to be top-down. >> >> Found at: https://github.com/robertfeldt/meta_compile >> >> Cheers, >> >> Robert Feldt >> >> >> Diff to Long's support.h : >> >> 103c103 >> < if (('A' <= source[pos] && source[pos] <= 'A') || >> --- >> > if (('A' <= source[pos] && source[pos] <= 'Z') || >> 112c112 >> < while (('A' <= source[pos] && source[pos] <= 'A') || >> --- >> > while (('A' <= source[pos] && source[pos] <= 'Z') || >> >> >> _______________________________________________ >> fonc mailing list >> [email protected] >> http://vpri.org/mailman/listinfo/fonc >> > > > _______________________________________________ > fonc mailing list > [email protected] > http://vpri.org/mailman/listinfo/fonc > -- My blog: http://firequery.blogspot.com/ http://twitter.com/SimonForman http://www.dendritenetwork.com/ "The history of mankind for the last four centuries is rather like that of an imprisoned sleeper, stirring clumsily and uneasily while the prison that restrains and shelters him catches fire, not waking but incorporating the crackling and warmth of the fire with ancient and incongruous dreams, than like that of a man consciously awake to danger and opportunity." --H. P. Wells, "A Short History of the World"
metaii.py
Description: Binary data
metaii.asm
Description: Binary data
metaii.metaii
Description: Binary data
_______________________________________________ fonc mailing list [email protected] http://vpri.org/mailman/listinfo/fonc
