[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

115.0. "Multiple-Language Program" by BEING::POSTPISCHIL () Mon Apr 29 1985 22:16

Here's a challenge:

	Write a program which can be compiled by two different compilers (two
versions of the same language are not allowed) without warnings or error
messages.  The program does not have to do the same thing once compiled, but
it should be non-trivial.  That is, it should at least print out "Hello." or
something else.

	Once that is done, how about doing it for more than two languages?


				-- edp (WHOAREYOU note 329)
T.RTitleUserPersonal
Name
DateLines
115.1HARE::STANMon Apr 29 1985 23:269
I did this back in college.  It was a program that read in a number, n,
and then read in n numbers and printed out the numbers in sorted order.
It worked correctly whether you fed it to the FORTRAN or the PL/I compiler.

To make the problem harder, I also had the restriction that there
could not be comments in either language and you could not go
past column 72 (since fortran ignores everything past column 72).

I still have the card deck...
115.2GOLLY::GILBERTTue Apr 30 1985 10:408
You must be new here.

I recall that one note had a program that could be compiled in any of three
languages, and would print a copy of itself.  Perhaps some reader can supply
the note number of this arcane gem?

Anyway, welcome to HACKERS.  If you look back at other notes, you'll discover
many other interesting perversions.  Enjoy.
115.3BEING::POSTPISCHILTue Apr 30 1985 12:5814
Re .2:

	I saw the self-printing programs (I've seen them before, but I haven't
seen ones as short as were presented here -- that one-line C program is
great!), but I must have missed the three-language version.  I definitely want
to see that, if anyone knows where it is. 

	Well, if it's been done before, let's see how many languages it can
be done for.  Can anyone show a self-printing four-language program?  Or any
four-language program?  I like the restrictions about comments -- can anyone
else offer suggestions for good restrictions?


				-- edp
115.4BEING::POSTPISCHILTue Apr 30 1985 13:167
Re .2, .3:
	I found the note with the self-printing programs in it (#95), but I
didn't see anything that worked in more than one language.  If anyone knows
where this program is, please let me know.


				-- edp
115.5VIKING::WASSER_1Tue Apr 30 1985 17:066
	As a side note:  Microsoft wrote many of the "include" files
	used in a Microsoft Windows environment so that they work
	equally well when included in 'C' or MASM programs.

			-John Wasser
			PCSGSE
115.6VAXUUM::DYERWed May 01 1985 03:0626
	Note #43 in VAXUUM::SYS$NOTES:LANGUAGES.NOT has the attached gem
in it.
#6	<_Jym_>\

									(* main(
									))(){/*
C       Note that we are now in comment mode in Pascal, C, and FORTRAN
C	If we wish, we may insert any FORTRAN here ( e.g.
	DO 10 I=1,0
	    WRITE(6,6)
6	FORMAT (42HTHIS WAS COMPILED BY A FORTRAN 66 COMPILER    )
	STOP
10	CONTINUE
	WRITE(6,7)
7	FORMAT (42HTHIS WAS COMPILED BY A FORTRAN 77 COMPILER    )
	STOP
	END
C *)	(* Note that we may place Pascal source here *)
C *)	program main(output);						 (*
C *)	begin								 (*
C *)	writeln('A Pascal compiler compiled me')			 (*
C *)	end.								 (*
C */	/* Note that we may place C source here */			 /*
C */	printf("A C compiler compiled me\n");				 /*
C */	return (int ( * )()) 0;						 /*
C */	}
115.7TRON::WARWICKWed May 01 1985 07:135
Re:.6  Works in VAX C but not PASCAL or FORTRAN (even with /nof77/noextend).


Trevor

115.8MANANA::COLGATEThu May 02 1985 02:1433
Here is one that should do the trick; However, it does not conform to Stan's
restriction... It uses comments to make it work.

Wim

                                                                        (* main(
                                                                        ))(){/*
C       
C
C	Fortran comments.... Note above right...
C	
C	

100	FORMAT (30H THESE STATEMENTS SATISFY THE  )
110	FORMAT (30H FORTRAN COMPILER.......       )

	WRITE(5,100)
	WRITE(5,110)

	END

C *)									 (*
C *)	program main(output);						 (*
C *)	begin								 (*
C *)									 (*
C *)	writeln('This could be a complete pascal program!');		 (*
C *)	writeln('But why would you want it too be?');			 (*
C *)									 (*
C *)	end.								 (*
C */									 /*
C */	printf("This is infact a C program,\n");	 		 /*
C */	printf("But like the above two, it is rather boring.\n");    	 /*
C */	}
115.9HARE::STANThu May 02 1985 18:006
So far, these programs cheat: they really contain complete programs
in each language, embedded within comments of the other language.

The challenge is to do it without comments.

Does anyone have a card reader to read in my deck?
115.10BEING::POSTPISCHILThu May 02 1985 22:3913
A card reader -- what's that?  I just finished school and they didn't tell me
anything about card readers.  Is this some new invention?  (Just kidding.)

I like the program shown; I was starting to think everyone was kidding me about
having seen one.  But I agree, it would be nicer to do it without comments.
But in case this is too difficult, how about a program in which there are
tokens (words, symbols, et cetera) which are interpreted by the compilers as
non-comments.  That is, you could still use comments, but some of the tokens
would have to be used by more than one compiler.  Perhaps "begin" could be
a keyword in one language and a variable in another.


				-- edp
115.11LATOUR::SPIDERSat May 04 1985 03:143
Re: .9

I don't know if my card reader still works, but I have one.
115.12PARVAX::PFAUSat May 04 1985 15:483
I have a card reader and an interface.  Anyone have a cable?

tom_p
115.13LSMVAX::BLINNMon Jun 17 1985 00:457
BTW, the Fortran/PL/I program will probably run through a SNOBOL-4 
compiler/interpreter with no diagnostics, but may not run.  And of 
course, SNOBOL is the language in which a properly written program can 
have every statement except the first and last placed in a random order 
and have the program still run correctly.

#6Tom