#The Duodecuple Quine
#Interpriter and Compiler version
- node.js v10.25
- python 3.3.3
- ruby 2.0.0p195
- tcc 0.9.26
- g++ 4.7.2
- java 1.7.0_21
- gauche 0.9.3.3
- ghc 7.6.3
- cmd 6.2.9200
- perl 5.8.8
| module BF | |
| class State < Struct.new :buffer, :position | |
| def current | |
| buffer[position].to_i | |
| end | |
| def current= val | |
| buffer[position] = (val + 0x100) % 0x100 | |
| end | |
| def position= val | |
| raise "buffer underflow!" if val < 0 | |
| super | |
| end | |
| end | |
| class Opcode < Struct.new :operator, :operand | |
| def initialize(operator, operand = nil) | |
| super | |
| end | |
| end | |
| module Compiler | |
| def self.compile src | |
| code, src2 = compile_impl src.split "" | |
| raise "compile error: expected eof" unless src2.empty? | |
| code | |
| end | |
| private | |
| def self.compile_impl src | |
| code = [] | |
| while c = src.shift | |
| case c | |
| when *%w(+ - < > . ,) | |
| code << Opcode.new(c.intern) | |
| when ?[ | |
| code2, _ = compile_impl src | |
| raise "compile error: expected ']'" unless src.shift == "]" | |
| code << Opcode.new(:"[", code2) | |
| when ?] | |
| src.unshift c | |
| break | |
| end | |
| end | |
| return code, src | |
| end | |
| end | |
| module Executer | |
| def self.execute(code, state = State.new([], 0)) | |
| code.each do |c| | |
| case c.operator | |
| when :+ then state.current += 1 | |
| when :- then state.current -= 1 | |
| when :> then state.position += 1 | |
| when :< then state.position -= 1 | |
| when :"." then $stdout.putc state.current | |
| when :"," then state.current = $stdin.readchar.unpack('C').first | |
| when :"[" then execute c.operand, state until state.current == 0 | |
| end | |
| end | |
| end | |
| end | |
| end | |
| src = $<.read | |
| BF::Executer.execute BF::Compiler.compile src |
| eval((d=("\\"),s=["r=Math.random();c=',';q=JSON.stringify;n=eval(q('').slice(", | |
| "0,1)+d+'n'+q('').slice(1,2));console.log(['print','puts'][+(r<=0.5)]+'('+q('", | |
| "main(){puts('+q('#include <iostream>'+n+'int main(void){std::cout<<'+q('clas", | |
| "s quine{public static void main(String... args){String s='+q('(display'+q('m", | |
| "ain=putStrLn'+q('package main'+n+'import('+q('fmt')+n+q('strings')+')'+n+'fu", | |
| "nc main(){s:='+q('print join('+q(q('').charAt(0)+c+n)+',split(/'+q(c).slice(", | |
| "0,-1)+'/,'+q('eval((d=('+q(d)+'),s='+q(s.match(/^.{58}|.{1,76}/g))+'.join('+", | |
| "q('')+')))////')+'))')+';fmt.Print('+q('@echo ')+'+strings.Replace(strings.Joi", | |
| "n(strings.Split(s,'+q('')+'),'+q('^')+'),'+q('@')+c+q(d+'@')+c+'-1))}'))+')'", | |
| ")+';int b=0;for(int i=0;i<s.length();i++){int c=(int)s.charAt(i);if(c>b)for(", | |
| "int j=0;j<c-b;j++)System.out.print('+q('+')+');else for(int j=b-c;j>0;j--)Sy", | |
| "stem.out.print('+q('-')+');System.out.println('+q('.')+');b=c;}}}') +'<<std:", | |
| ":endl;}')+');}')+')');console.error(r<=0.5?'ruby':'python')"].join("")))//// |
| @REM node.js >> python or ruby >> c >> c++ >> java >> brainfuck | |
| @REM >> scheme >> haskell >> go >> bat >> perl >> node.js >> (...endless) | |
| @node quine.js 1> quine.pyrb 2> nextrun | |
| @for /F %%r in (nextrun) do @%%r quine.pyrb|tcc -run - > quine.cxx | |
| @g++ quine.cxx -o quine.exe | |
| @quine.exe > quine.java | |
| @javac quine.java | |
| @java quine | ruby brainfuck.rb | gosh | runghc > quine.go | |
| @go run quine.go > quine.bat | |
| @quine.bat | perl |