User:Conor O'Brien/Compilers/Quartic

Quartic is a language designed to compile to the language 4. Written in Ruby, the compiler can be found here, with a revised interpreter for the language.

Language Spec
Every line is a "statement"; each statement consists of one keyword and a list of parameters. Every parameter is one of the following:

an identifier    (matches /^[A-Za-z][A-Za-z0-9_]*$/) a number         (matches /^\d+$/) a character      (matches /'.'/)

The parameters are separated by spaces or commas.

Commands
Parameters marked with  must be a named variable. Parameters marked with  may be either a named variable or a literal.

function(arity) param[0], param[1], param[2], ..., param[arity]

becomes

function a, b, c, ...

There are also,  , and.

Deadfish interpreter
Character output.

decl c, equal, acc, n1 set n1, 0 dec n1 input c loop c  ; increment cmp equal, c, 'i'  if equal inc acc end ; decrement cmp equal, c, 'd'  if equal dec acc end ; square cmp equal, c, 's'  if equal square acc end ; output cmp equal, c, 'o'  if equal ; todo: actual print print acc end zero c  cmp equal, acc, n1   if equal set c, 1 end cmp equal, acc, 256 if equal set c, 1 end if c    zero acc end input c end

This compiles to:

3.60001602996010600101026030160599604010040405606016089960716007070861099609120090910612996139961158011111201111136230012323007208206900009090201909001290909062101890621006900096600006060218600222203660009690000909020190900429090906210189062100690009661000616121861122220666100969000090902019090072909090621018906210069000966200062622186222222226620096900009090201909009290909062101890621006900096630006363218635226630096200069000090902219090232909090621018906210069000966400064642186462001664009690000909022190901129090906210189062100690009665000656521865620016650096660006666208666220066600972094