# What code compiles in the most number of languages?

Excluding trivial programs, what code compiles in the most number of languages?

(By "trivial" I mean to exclude answers such as the empty program or text that will be echoed directly.)

The following code apparently compiles in all of the following programming languages (and prints something different in each one): C, C++, Perl, TeX, LaTeX, PostScript, sh, bash, zsh and 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%*/


That's 10 different languages. I found it via pts oldalai (who also has a magnificent Christmas poem written in C, C++, Perl and TeX). Can anyone do better?

-
The technical term being Polyglot – st0le Jan 2 '12 at 11:55
Here's 16 language polyglot – st0le Jan 2 '12 at 11:56
If sh, bash, and zsh count as different languages even when it's essentially only using sh then I think you need to specify precisely what you count as different languages. E.g. Perl 4 vs Perl 5.10 have some significant differences. – Peter Taylor Jan 2 '12 at 13:14
@PeterTaylor: Point taken, and many languages are likely to be similar, e.g., C/C++, Tex/LaTeX. Perhaps that's the nature of the game - to win you have to target the language that has the most number of near-variants. – shamp00 Jan 2 '12 at 15:15
@st0le: Thanks for that, I failed to find the name for this type of program (and I am surprised to find that this is the first use of the polyglot tag on this site). – shamp00 Jan 2 '12 at 15:15