Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- (laq 28) * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) require "re" -- (laq 24) mem = {} numberp = function (addr) return 0<=addr and addr<= 999 end stringp = function (addr) return 1000<=addr and addr<=2999 end symbolp = function (addr) return 3000<=addr and addr<=4999 end consp = function (addr) return 5000<=addr and addr<=9996 end nilp = function (addr) return addr==9999 end taup = function (addr) return addr==9998 end Lp = function (addr) return addr==9997 end stringws = {} symbolws = {} -- An "addr" is a string like "123", "$1234", "s4567", "c5678"; -- a "word" is a number between 0 and 9999. -- atow = function (addr) return addr:match("%d%d%d%d")+0 end wtoa = function (w, char) return (char or "")..format("%04d", w) end tostr0 = function (w) if numberp(w) then return w.."" end if nilp(w) then return "nil" end if taup(w) then return "tau" end if Lp(w) then return "L" end end tostr1 = function (w) if tostr0(w) then return tostr0(w) end if stringp(w) then return wtoa(w, "$") end if symbolp(w) then return wtoa(w, "@") end if consp(w) then return wtoa(w, "&") end end tostr2 = function (w) if tostr0(w) then return tostr0(w) end if stringp(w) then return format("%q", mem[w]) end if symbolp(w) then return mem[w][1] end end symbolws["nil"] = 9999 symbolws["tau"] = 9998 symbolws["L"] = 9997 firstfree = function (w) for i=w,9999 do if mem[w]==nil then return w end end end newstring0 = function (str) local w = firstfree(1000) mem[w] = str stringws[str] = w return w end newsymbol0 = function (str) local w = firstfree(3000) mem[w] = {str, 9999} symbolws[str] = w return w end newstring = function (str) return stringws[str] or newstring0(str) end newsymbol = function (str) return symbolws[str] or newsymbol0(str) end -- Addr = re.compile([[ [$@&]? { [0-9]+ } -> f ]], {f=tonumber}) -- String = re.compile([[ '"' { [^"]* } '"' -> f ]], {f=PP}) -- Symbol = re.compile([[ { [-!#$%&*+,/-~]+ } -> f ]], {f=PP}) Atom = re.compile([[ ( [$@&]? { [0-9]+ } -> tonumber ) / ( '"' { [^"]* } '"' -> tostring ) / ( { [-!#$%&*+,/-~]+ } -> tosymbol ) ]], {tonumber=tonumber, tostring=newstring, tosymbol=newsymbol}) PP(Atom:match "123") PP(Atom:match "$123") PP(Atom:match '"abcd"') = Addr:match "$1234 foo" = Symbol:match "+33/~" (find-einsert '((32 127))) 0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !#$%%&*+,%-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ parser = re.compile([[ add <- ( num ( { '+' } num ) * ) -> print num <- {%d+} ]], { read1 = function (str, pos) end ntoca = function (n) return ntoa(n, (number end addrtos0 = function (addr) if numberp(addr) then return ""..addr end if stringp(addr) then return format("%q", mem(addr)) end if symbolp(addr) then return format("%q", mem(addr)[1]) end if taup(addr) then return "tau" end if Lp(addr) then return "L" end end = aton("&5463") = ntoa(99) = ntoa(99, "@")