Rev | Author | # | Line |
---|---|---|---|
12 | StuartYeates | 1 | !!! PolyGlot |
2 | |||
3 | Originally an adjective meaning an individual spoke many languages. More recent an adjective meaning that a file of SourceCode was valid in many [ProgrammingLanguage]s | ||
4 | |||
5 | ---- | ||
9 | JohnMcPherson | 6 | !!! PolyGlot #1 |
1 | JohnMcPherson | 7 | |
10 | AristotlePagaltzis | 8 | The [original polyglot | http://ideology.com.au/polyglot/] is valid code in 8 languages. |
3 | CraigBox | 9 | |
9 | JohnMcPherson | 10 | <verbatim> |
11 | (*O/*_/ | ||
12 | Cu #%* )pop mark/CuG 4 def/# 2 def%%%%@@P[TX---P\P_SXPY!Ex(mx2ex("SX!Ex4P)Ex= | ||
13 | CuG #%* *+Ex= | ||
14 | CuG #%*------------------------------------------------------------------*+Ex= | ||
10 | AristotlePagaltzis | 15 | CuG #%* POLYGLOT - a program in eight languages 15 February 1991 *+Ex= |
16 | CuG #%* 10th Anniversary Edition 1 December 2001 *+Ex= | ||
9 | JohnMcPherson | 17 | CuG #%* *+Ex= |
18 | CuG #%* Written by Kevin Bungard, Peter Lisle, and Chris Tham *+Ex= | ||
19 | CuG #%* *+Ex= | ||
10 | AristotlePagaltzis | 20 | CuG #%* Polyglot suports the following languages: *+Ex= |
21 | CuG #%* 1. COBOL (ANSI) *+Ex= | ||
22 | CuG #%* 2. Pascal (ISO) *+Ex= | ||
23 | CuG #%* 3. Fortran (ANSI, f77) *+Ex= | ||
24 | CuG #%* 4. C (ANSI-ish) *+Ex= | ||
25 | CuG #%* 5. PostScript *+Ex= | ||
26 | CuG #%* 6. Linux/Unix shell script (bash, sh, csh) *+Ex= | ||
27 | CuG #%* 7. x86 machine language (MS-DOS, Win32, Linux) *+Ex= | ||
28 | CuG #%* 8. Perl (version 5) *+Ex= | ||
9 | JohnMcPherson | 29 | CuG #%* *+Ex= |
30 | CuG #%* Usage: *+Ex= | ||
10 | AristotlePagaltzis | 31 | CuG #%* 1. Rename this file to polyglot.[cob|pas|f77|c|ps|sh|com|pl] *+Ex= |
32 | CuG #%* *+Ex= | ||
33 | CuG #%* 2. Compile and run with your favorite compiler and operating *+Ex= | ||
34 | CuG #%* system. *+Ex= | ||
9 | JohnMcPherson | 35 | CuG #%* *+Ex= |
36 | CuG #%* Notes: *+Ex= | ||
37 | CuG #%* 1. We have attempted to use only standard language features. *+Ex= | ||
38 | CuG #%* *+Ex= | ||
10 | AristotlePagaltzis | 39 | CuG #%* 2. Without the -traditional flag gcc will issue a warning. *+Ex= |
9 | JohnMcPherson | 40 | CuG #%* *+Ex= |
10 | AristotlePagaltzis | 41 | CuG #%* 3. When transferring from Unix to DOS make sure that a LF *+Ex= |
9 | JohnMcPherson | 42 | CuG #%* is correctly translated into a CR/LF. *+Ex= |
10 | AristotlePagaltzis | 43 | CuG #%* *+Ex= |
44 | CuG #%* 4. Keep the black lines at the start of the program. They *+Ex= | ||
45 | CuG #%* are important. *+Ex= | ||
46 | CuG #%* *+Ex= | ||
47 | CuG #%* 5. This text is a comment block in all eight languages. *+Ex= | ||
9 | JohnMcPherson | 48 | CuG #%* *+Ex= |
49 | CuG #%* Please mail any comments, corrections or additions to *+Ex= | ||
10 | AristotlePagaltzis | 50 | CuG #%* polyglot@ideology.com.au *+Ex= |
9 | JohnMcPherson | 51 | CuG #%* *+Ex= |
52 | CuG #%*------------------------------------------------------------------*QuZ= | ||
53 | CuG #%* *+Ex= | ||
10 | AristotlePagaltzis | 54 | CuG #%*!Mx)ExQX5ZZ5SSP5n*5X!)Ex+ExPQXH,B+ExP[-9A-9B(g?(gA'UTTER_XYZZXX!X *+ |
9 | JohnMcPherson | 55 | CuG #(* *( |
56 | C # */); /*( | ||
57 | C # *) program polyglot (output); (*+ | ||
58 | C # identification division. | ||
59 | C # program-id. polyglot. | ||
60 | C # | ||
61 | C # data division. | ||
62 | C # procedure division. | ||
63 | C # | ||
64 | C # * ))cleartomark /Bookman-Demi findfont 36 scalefont setfont ( | ||
65 | C # * ( | ||
66 | C # | ||
67 | C # * hello polyglots$ | ||
68 | C # main. | ||
69 | C # perform | ||
10 | AristotlePagaltzis | 70 | C /# * ) 2>_$$; echo "hello polyglots"; rm _$$; exit; |
71 | C # * ( | ||
72 | C # | ||
73 | C *0 ) unless print "hello polyglots\n"; __END__ | ||
9 | JohnMcPherson | 74 | |
75 | C stop run. | ||
76 | -*, 'hello polyglots' | ||
77 | C | ||
78 | C print. | ||
79 | C display "hello polyglots". ( | ||
80 | C */ int i; /* | ||
81 | C */ main () { /* | ||
82 | C */ i=printf ("hello polyglots\n"); O= &i; return *O; /* | ||
83 | C *) (* | ||
84 | C *) begin (* | ||
85 | C *) writeln ('hello polyglots'); (* | ||
86 | C *) (* ) | ||
87 | C * ) pop 60 360 ( | ||
88 | C * ) pop moveto (hello polyglots) show ( | ||
89 | C * ) pop showpage (( | ||
90 | C *) | ||
91 | end .(* ) | ||
92 | C)pop% program polyglot. *){*/} | ||
93 | </verbatim> | ||
94 | |||
10 | AristotlePagaltzis | 95 | Compile as [C] and run on [Linux]:: |
8 | JohnMcPherson | 96 | |
11 | AristotlePagaltzis | 97 | <verbatim> |
98 | gcc -xc polyglot.src -o polyglot && ./polyglot | ||
99 | </verbatim> | ||
100 | The <tt>-xc</tt> switch forces the language to be [C]. | ||
8 | JohnMcPherson | 101 | |
10 | AristotlePagaltzis | 102 | View as PostScript:: |
8 | JohnMcPherson | 103 | |
11 | AristotlePagaltzis | 104 | <verbatim> |
105 | gv polyglot.src | ||
106 | </verbatim> | ||
10 | AristotlePagaltzis | 107 | |
11 | AristotlePagaltzis | 108 | Run as a [Shell] script:: |
10 | AristotlePagaltzis | 109 | |
11 | AristotlePagaltzis | 110 | <verbatim> |
111 | sh polyglot.src | ||
112 | # or | ||
113 | chmod +x polyglot.src && ./polyglot.src | ||
114 | </verbatim> | ||
10 | AristotlePagaltzis | 115 | |
11 | AristotlePagaltzis | 116 | Etc... |
9 | JohnMcPherson | 117 | |
118 | ---- | ||
11 | AristotlePagaltzis | 119 | |
9 | JohnMcPherson | 120 | !!! PolyGlot #2 |
121 | |||
10 | AristotlePagaltzis | 122 | The following is a polyglotic quine. (A quine is a program that prints its own source code out when run, without cheating by using open(2) on itself.) |
123 | |||
124 | [polyglotC++PerlPythonC.c | http://www.phong.org/bf/polyglotC++PerlPythonC.c]: | ||
9 | JohnMcPherson | 125 | |
126 | <verbatim> | ||
127 | #include <stdio.h> | ||
128 | #define q(a,...) a | ||
129 | #define substr q | ||
130 | #define eval(a) main(){char c[]=a,n=10;c[419]=0;printf(c+4,n,n,n,n,34,34,n,34,39,c+4,39,34,n);}/* Copyright (C) Thomas Schumm <phong@phong.org> | ||
131 | exec("from sys import*;substr=q=lambda y:exit(stdout.write(y[4:-46]%((10,)*4+(34,34,10,34,39,y[4:-46],39,34,10))))",None);#*/ | ||
132 | eval(substr(q("$p='#include <stdio.h>%c#define q(a,...) a%c#define substr q%c#define eval(a) main(){char c[]=a,n=10;c[419]=0;printf(c+4,n,n,n,n,34,34,n,34,39,c+4,39,34,n);}/* Copyright (C) Thomas Schumm <phong@phong.org>%cexec(%cfrom sys import*;substr=q=lambda y:exit(stdout.write(y[4:-46]%%((10,)*4+(34,34,10,34,39,y[4:-46],39,34,10))))%c,None);#*/%ceval(substr(q(%c$p=%c%s%c;printf($p,(10)x4,34,34,10,34,39,$p,39,34,10)%c),1,-1))%c';printf($p,(10)x4,34,34,10,34,39,$p,39,34,10)"),1,-1)) | ||
133 | </verbatim> |
lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 4 times)