가장 많은 언어로 어떤 코드가 컴파일됩니까? [닫은]


29

간단한 프로그램을 제외하고 어떤 코드가 가장 많은 언어로 컴파일됩니까?

( "사소한"이란 빈 프로그램이나 직접 반향되는 텍스트와 같은 답변을 제외한다는 의미입니다.)

다음 코드는 C, C ++, Perl, TeX, LaTeX, PostScript, sh, bash, zsh 및 Prolog와 같은 프로그래밍 언어로 컴파일됩니다 (각각 다른 언어로 인쇄).

%:/*:if 0;"true" +s ||true<</;#|+q|*/include<stdio.h>/*\_/
{\if(%)}newpath/Times-Roman findfont 20 scalefont setfont(
%%)pop 72 72 moveto(Just another PostScript hacker,)show((
t)}. t:-write('Just another Prolog hacker,'),nl,halt. :-t.
:-initialization(t). end_of_file. %)pop pop showpage(-: */
int main(){return 0&printf("Just another C%s hacker,\n",1%
sizeof'2'*2+"++");}/*\fi}\csname @gobble\endcsname{\egroup
\let\LaTeX\TeX\ifx}\if00\documentclass{article}\begin{doc%
ument}\fi Just another \LaTeX\ hacker,\end{document}|if 0;
/(J.*)\$sh(.*)"/,print"$1Perl$2$/"if$_.=q # hack the lang!
/
sh=sh;test $BASH_VERSION &&sh=bash;test $POSIXLY_CORRECT&&
sh=sh;test  $ZSH_VERSION && sh=zsh;awk 'BEGIN{x="%c[A%c[K"
printf(x,27,27)}';echo "Just another $sh hacker," #)pop%*/

10 가지 언어입니다. 나는 pts oldalai (C, C ++, Perl 및 TeX로 작성된 멋진 크리스마스시를 가지고 있음)를 통해 그것을 발견했습니다 . 누구든지 더 잘할 수 있습니까?


8
기술 용어 Polyglot
st0le

8
여기에 16 언어의 수개 국어
st0le는

7
sh, bash 및 zsh가 본질적으로 sh 만 사용하는 경우에도 다른 언어로 계산되면 다른 언어로 계산하는 것을 정확하게 지정해야한다고 생각합니다. 예를 들어 Perl 4와 Perl 5.10은 약간의 차이가 있습니다.
피터 테일러

7
거의 모든 문자 조합이 유효한 프로그램 인 언어 (예 : 공백, BrainF ** k 및 Perl)가 있습니다. 그들은 모든 프로그램에 의해 청구될 수 있습니다.
ugoren

답변:


9

3 개 언어-C, C ++ 및 Python

#ifdef _cplusplus
    #include <iostream>
    #define print() int main(){cout << "Hello world! -- from C++" << endl;}
#elif (defined __STDC__) || (defined __STDC_VERSION__)
    #include <stdio.h>
    #define print() int main(){printf("Hello world! -- from C\n");}
#else
import builtins
print = lambda : builtins.print("Hello world! -- from Python")
#endif

print()

언어마다 다른 내용이 인쇄되어 있습니다. C & C ++에서 '#'으로 시작하는 행은 사전 처리 지시문이지만 동일한 행은 Python의 주석입니다.


4

5 개 언어-Thue, Brainf ***, Boolf ***, Treehugger 및 Javascript

/*::=
alert::=~This is Thue!
::=
-><[[--->+<]>-.[---->+++++<]>-.+.++++++++++.+[---->+<]>+++.-[--->++<]>-.++++++++++.+[---->+<]>+++.+[->++<]>.---[----->+<]>-.+++[->+++<]>++.++++++++.+++++.--------.---[->+++<]>+...---------.[-]]
^^[[--->+^]>-.[---->+++++^]>-.+.++++++++++.+[---->+^]>+++.-[--->++^]>-.++++++++++.+[---->+^]>+++.>-[--->+^]>-.-[--->+^]>+.-------------..+++.[--->+^]>---.++[->+++^]>++..--.+++++++++++++.[--->+^]>-----.[-]]
-+[+;;+;+;+;+;+;+;;;;+;+;+;;+;+;+;;+;+;+;;+;+;;+;;+;;;+;;;;;;+;+;;+;+;;+;+;+;;+;+;;+;;+;;;+;;;;;;+;+;;;+;+;;;;+;+;+;;;;+;+;;+;+;;;;+;+;;+;;;+;;+;+;;+;;+;;+;;+;;+;;+;+;+;+;+;+;;;+;+;+;+;+;+;;;+;+;+;+;+;+;;+;+;;;;+;+;;]
*/alert("This is Javascript!")

불행히도 웹 기반 구현에서 Treehugger 부분이 시간 초과되므로 다른 Treehugger 인터프리터를 사용해야합니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.