Skip to content

A file that behaves the same when executed as Ruby, C, PHP, and Javascript.

Notifications You must be signed in to change notification settings

duckinator/meep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

Meep

Polyglot program: Hello World in Ruby, C, PHP, and JavaScript.

Annotated source

//#<?php /*
  • Ruby sees an empty regular expression literal, followed by the comment <?php /*.
  • C sees a one-line comment.
  • PHP sees a literal //#, the beginning of PHP code, and the beginning of a multi-line comment.
  • JavaScript sees a one-line comment.
//;def main&b;b&&yield end;"\
  • Ruby sees an empty regular expression literal, followed by a definition of main, followed by the beginning of a string literal.
  • C sees a one-line comment, with a line continuation (the \).
  • PHP sees the continuation of the multi-line comment.
  • JavaScript sees a one-line comment.

The Ruby method just executes the code given to it in a block, if one was specified.

printf=require('util').print;/**/function//"
  • Ruby sees a continuation of the string literal.
  • C sees the ending of the continued one-line comment.
  • PHP sees a continuation of the multi-line comment, followed by the function keyword, and a one-line comment.
  • JavaScript sees an importing of the print function as printf(), followed by an empty multi-line comment, followed by the function keyword, followed by a one-line comment.
main(){printf("\x08\x08\x08Hello, world!\n");}
  • Ruby sees a call to main, executing everything in the block immediately.
  • C sees the definition of main(), with an implicit int type and implicit declaration of printf (hence the warnings).
  • PHP and JavaScript see the continuation of the main() function (starting with the function keyword).
main();
  • Ruby sees a call to main, which is an elaborate no-op because there is no block.
  • C sees this as a function prototype for main, with no arguments and an implicit return type of int.
  • PHP and JavaScript sees this as calling the main function defined above.

About

A file that behaves the same when executed as Ruby, C, PHP, and Javascript.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published