A Polyglot program or script is one which will compile and run in multiple languages. Polyglots are written using a combination of programming languages and scripting languages like C,C++ and LISP , PERL , python.

It is hard to believe at first as one can ask how does a native C Cross Compiler understand the syntax of python or LISP.The trick is in tricking the compiler of programming language to think that we are writing code in say C.Awesome right.

A simple example of a polyglot program is

# define y >
# include
# define x z /*
print(“Crash\n”);__END__
++++++++++[>++++++++++>++++++++++<<-]
+++[>>+++++<-<-]>>.<+++++++.——-..>.+.–.<.*/
main()
{ printf (“Crash\n”); }

Let me tell you what is so special about this program well it will run in compilers of 3 different languages namely C , PERL and BRAINFUCK(or brainf**k).

This is simply wonderful.

Below is a link of a Polyglot program that runs in 8 different languages .. OMG

http://ideology.com.au/polyglot/

Share 

Add a Comment

You need to be a member of Open Source University Meetup to add comments!

Join this social network


Webinars

OSUM members get exclusive access to a series of webinars on the most innovative open source technologies via the OSUM Webinar Series.

If you missed any of the previous OSUM Webinars, click here to listen to the replays of the previous sessions.

News

Download Free OpenOffice.org Guide For Creating Large Documents One of the advantages of OpenOffice.org is its ability to handle large word processing documents such as theses and research papers. Download this free guide now and read expert advice on writing with OpenOffice.org.

Get On Board with JavaFX & the Tech Train Game

Get a hands-on introduction to JavaFX when you play the Tech Test Train - Ride the train, test your knowledge of JavaFX technology, and earn points. Click HERE to play.

Working With ZFS Snapshots Download the free ZFS Snapshots How-To Guide to learn how to create and use the backup and restore capabilities of ZFS snapshots.

© 2009   Created by Gary Serda

Badge  |  Report an Issue  |  Privacy  |  Terms of Service