*** Welcome to piglix ***

Polyglot (computing)


In computing, a polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independent of the programming language used to compile or interpret it.

Generally polyglots are written in a combination of C (which allows redefinition of tokens with a preprocessor) and a scripting language such as Lisp, Perl or sh.

Polyglot markup is similar, but about markup language context.

Polyglot persistence is similar, but about databases.

The two most commonly used techniques for constructing a polyglot program are to make liberal use of languages that use different characters for comments and to redefine various tokens as others in different languages. Often good use is made of syntax quirks. These are demonstrated in this public domain polyglot written in ANSI C, PHP and bash:

Note the following:

Some less-common languages also offer possibilities to create Polyglot code. Here is a small sample, written simultaneously in SNOBOL4, Win32Forth, PureBasicv4.x, and REBOL:

The term is sometimes applied to programs that are valid in more than one language, but do not strictly perform the same function in each. One use for this form is a file that runs as a DOS batch file, then re-runs itself in Perl:


...
Wikipedia

...