Multiple languages in the same file

I've written a program that prints "The best programming language ever is X"
replacing X with an appropriate string depending on the language used to compile/interpret it
see comments for the supported languages

I'm sharing it here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#//<?php echo "\r    \r";

#// Polyglot script
#// Copyright Mattia Basaglia 2011
#// Distributed under the Boost Software License, Version 1.0.
#// ( See http://www.boost.org/LICENSE_1_0.txt )

#// This file can be used as source/script for 
#// C
#// C++
#// Objective-C
#// Objective-C++
#// Perl
#// PHP
#// Python
#// Ruby
#// POSIX Shell

#define function int 
#ifdef __cplusplus
    #include <iostream>
    #define print std::cout <<
    #ifdef __OBJC__
        #include<stdio.h>
    #endif
#else
    #define print const char* c=
    #include <stdio.h>
#endif
#/*?><?php /*
q="""
#{
# =+'
=begin
}'+'
#*/
function main()
{
/*
#{
# ";q=0;print() { echo $1 Shell; exit; # ?><?php /*
# =+'+'
=end 
} # "
# """
#';
# */
#// The following line is executed by all languages
print "The best programming language ever is ";
#//?><?php echo "PHP\n"; return; ?>
#/*
q="""
#{
print "Ruby\n";
exit;
}
";q=+0;
print "Perl\n";
__END__=0;
'
"""
print "Python ( if only it didn\'t add trailing newlines :^/ )";
exit();
# ?>
q="""" 
# */ 
#ifndef __cplusplus
printf("%s",c);
#endif
#ifdef __OBJC__
printf("Objective-");
#endif
#ifdef __cplusplus 
std::cout << "C++" << std::endl ;
#else
printf("C\n");
#endif // <?php
}
#//?><?php main(); #'" """ 

It has been tested with the following:
GCC 4.5.2
PHP 5.3.5
perl v5.10.1
Python 2.7.1
GNU bash, version 4.2.8(1)
dash 0.5.5.1
ruby 1.8.7
On Trisquel 5.0 x86_64

If your favorite language is not listed feel free to try to include it :^P

PS: Does anyone know how to fix Python output without breaking other languages?
You can do this in Python:
1
2
3
4
5
from sys import stdout

stdout.write("line 1 ")
stdout.write("still line 1\n")
stdout.write("line 2")
At first I thougt this was a question from some new kid that was posted to the wrong section(I rarely check the names until after I've read the headline). Then I read the post and thought "So what? Big deal." (Still not having read the name yet). Then I read the code... not a single jump statement of any kind or any dynamic links... Well done sir.

One question though, you have a preprocessor instructions that define "print" as "std::cout", why don't you use them? This is a really cool concept Bazzy I am truely impressed.
@chrisname
Making line 49 a function call will break shell and languages that will not have a way to rename print
@Computergeek01
What do you mean? I use print for C++ on line 49. I have preprocessed enough to make C-family compatible with all the others.

I've never liked the CPP much but it makes C-family very easy to be integrated with completely different languages
Topic archived. No new replies allowed.