|
In the context of 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 independently of which of the chosen programming language in which it is compiled or interpreted. Intuition suggests that polyglot programs should be impossible or very difficult to write. Intuition, in this case, is wrong. Originally, the word computing was synonymous with counting and calculating, and a science that deals with the original sense of computing mathematical calculations. ...
A computer program or software program (usually abbreviated to a program) is a step-by-step list of instructions written for a particular computer architecture in a particular computer programming language. ...
This article or section should be merged with script programming language In computer applications, a script, roughly speaking, is a computer program that automates the sort of task that a user might otherwise do interactively at the keyboard. ...
A programming language or computer language is a standardized communication technique for expressing instructions to a computer. ...
Generally polyglots are written in a combination of C (which allows redefinition of tokens and even operators with a preprocessor) and a scripting programming language such as Lisp, Perl or sh. The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a standardized imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ...
In mathematics, an operator is some kind of function; if it comes with a specified type of operand as function domain, it is no more than another way of talking of functions of a given type. ...
In computer science, a preprocessor is a program that takes a source code and performs transformations on it, before the step of compilation or interpretation. ...
Scripting programming languages (commonly called scripting languages or script languages) are computer programming languages designed for scripting the operation of a computer. ...
Lisp is a reflective, multi-paradigm programming language with a long history. ...
Perl, also Practical Extraction and Report Language (a backronym, see below) is an interpreted procedural programming language designed by Larry Wall. ...
A Unix shell, also called the command line, provides the traditional user interface for the Unix operating system. ...
The two most commonly used techniques for constructing a polyglot program are to make liberal use of languages which use different characters for comments and to redefine various tokens as others in different languages. Often good use is made of quirks of syntax. These are demonstrated in this public domain polyglot written in ANSI C, PHP and GNU bash shell: Syntax, originating from the Greek words ÏÏ
ν (syn, meaning co- or together) and ÏÎ¬Î¾Î¹Ï (táxis, meaning sequence, order, arrangement), can be described as the study of the rules, or patterned relations that govern the way the words in a sentence come together. ...
The public domain comprises the body of all creative works and other knowledge—writing, artwork, music, science, inventions, and others—in which no person or organization has any proprietary interest. ...
The C Programming Language, Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a standardized imperative computer programming language developed in the early 1970s by Dennis Ritchie for use on the Unix operating system. ...
PHP, short for PHP: Hypertext Preprocessor, is an open-source, reflective programming language used mainly for developing server-side applications and dynamic web content, and more recently, other software. ...
GNU is a free software operating system. ...
UNIX Bash is the shell, or command language interpreter, that will appear in the GNU operating system. ...
A Unix shell, also called the command line, provides the traditional user interface for the Unix operating system. ...
#define a /* #<?php echo "010Hello, world!n"// 2> /dev/null > /dev/null ; // 2> /dev/null; x=a; $x=5 // 2> /dev/null ; if (($x)) // 2> /dev/null; then return 0; // 2> /dev/null; fi #define e ?> #define b */ #include <stdio.h> #define main() int main() #define printf printf( #define true ) #define function function main() { printf "Hello, world!n"true/* 2> /dev/null | grep -v true*/; return 0; } #define c /* main #*/ Note the following: - A hash sign marks a preprocessor statement in C, but is a comment in both bash and PHP.
- "//" is a comment in PHP and the root directory in bash.
- Shell redirection is used to eliminate undesirable outputs.
- Even on commented out lines, the "<?php" and "?>" PHP indicators still have effect.
- The statement "function main()" is valid in both PHP and bash; C #defines are used to convert it into "int main()" at compile time.
- Comment indicators can be combined to perform various operations.
- "if (($x))" is a valid statement in both bash and PHP.
- printf is a bash shell builtin which is identical to the C printf except for its omission of brackets (which the C preprocessor adds if this is compiled with a C compiler).
- The final three lines are only used by bash, to call the main function. In PHP the main function is defined but not called and in C there is no need to explicitly call the main function.
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 Microsoft batch file, then re-runs itself in Perl: In computer science, a preprocessor is a program that takes a source code and performs transformations on it, before the step of compilation or interpretation. ...
In computer file systems, the root directory is the first or top-most directory in a hierarchy. ...
In Unix, a shell builtin is a command or a function, called from a shell, that is executed directly in the shell itself, instead of an external executable program which the shell would load and execute. ...
Microsoft Corporation (NASDAQ: MSFT, HKEx: 4338) is the worlds largest software company, with 2005 global annual sales of 40 billion US dollars and nearly 60,000 employees in 85 countries and regions. ...
Perl, also Practical Extraction and Report Language (a backronym, see below) is an interpreted procedural programming language designed by Larry Wall. ...
@rem = '--*-Perl-*-- @echo off perl "%~dpnx0" %* goto endofperl @rem '; #!perl print "Hello, world!n"; :endofperl This allows the creation of Perl scripts that can be run on Microsoft systems with minimal effort.
External links
|