Ero

From Esolang
Jump to navigation Jump to search
This article is not detailed enough and needs to be expanded. Please help us by adding some more information.
This is still a work in progress. It may be changed in the future.
|::
Designed by User:InLuaIKnow
Appeared in 2026
Computational class Unknown
Major implementations Lua

is a esolang written in Lua.

Syntax:

:|: statement terminator

:.(opcode) makes a statement

|:: signals that arguments are after this

>> is argument seperator.

Example(s):

:.1|::1>>"Hello,world!":|:
:.8|::1>>1:|:
:.1|::1>>1:|::.1|::2>>1:|::.2|::1>>2>>3:|::.8|::1>>3:|:

Current intrepeter

--|:: intrepeter
local reg={}
local pc = 1
local functions = {[1]=print,[2]=error}
local opc = {
   [1]=function(a,b)-- :.1|::1>>"Hello,world!":|:
       reg[a]=b
   end;
   [2]=function(a,b,c)--add
       reg[c]=(reg[a]+reg[b])
   end;
   [3]=function(a,b,c)--sub
       reg[c]=(reg[a]-reg[b])
   end;
   [4]=function(a,b,c)--mul
       reg[c]=(reg[a]*reg[b])
   end;
   [5]=function(a,b,c)--div
       reg[c]=(reg[a]/reg[b])
   end;
   [6]=function(a,b,c)--pow
       reg[c]=(reg[a]^reg[b])
   end;
   [7]=function(a,b,c)--mod
       reg[c]=(reg[a]%reg[b])
   end;
   [8]=function(a,...)--call
       local args = {}
       for i,v in ipairs({...}) do
          args[i]=reg[v]
       end
       functions[a](table.unpack(args))
   end;
   [9]=function(n)--jump
       pc=pc-n
   end;
   [10]=function(r,n)--jump if true
       if reg[r] == true then
           pc=pc-n
       end
   end
}


function compile(source)
   local inst = {}
   for stmt in source:gmatch("(.-):|:") do
       local opco = stmt:match("^%.:([0-9]+)|::")
       if opco then
           opco = tonumber(opco)
          -- print(opco)
           local argst = stmt:match("|::(.*)")
           local args = {}
          -- print(argst)
           if argst then
               local argcount = 0
               for argf in argst:gmatch("([^>>]+)") do
                  -- print(argf)
                   argcount=argcount+1
                   local fl = argf:sub(1,1)..argf:sub(-1)
                   local num = tonumber(argf)
                   if num then
                       args[#args+1] =  num
                   elseif fl=="" or fl=='""' then
                       args[#args+1] = argf:sub(2,-2)
                   elseif argf=="true" then args[#args+1] = true elseif argf=="false" then args[#args+1] = false 
                   else error("invalid argument #"..argcount) end
               end
           end
           inst[#inst+1]={opcode=opco, args=args}
       end
   end
   return inst
end
function intrepet(p)
   pc = 1
   while p[pc] ~= nil do
       while pc <= #p do
           local instr = p[pc]
           local op = opc[instr.opcode]
           if op then
               op(table.unpack(instr.args))
           end
           pc = pc + 1
       end
   end
end

if arg[1] == nil then
    print("|:: (Ero), the esoteric language")
    while true do
        io.write(">")
        local inp=io.read()
        local ok,res =pcall(compile,inp)
        --print(ok,table.concat(res," "))
        if not ok then io.stderr:write(res) else intrepet(res) end
    end
end