fork download
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. my %funcs=qw(writeln Console.WriteLine readln Console.ReadLine write
  6. Console.Write read Console.Read start Diagnostics.Process.Start exit
  7. Environment.Exit);
  8. $funcs{$_} = "global::System.$funcs{$_}" for keys %funcs;
  9.  
  10. print <<TOP;
  11. using System;
  12.  
  13. /* AUTOGENERATED BY HACK COMPILER V 0.1 */
  14. namespace Program
  15. {
  16.   public class MainApp
  17.   {
  18.   public static void Main(string[] args)
  19.   {
  20. TOP
  21.  
  22. while (<>)
  23. {
  24. s/[\r\n]+$//o; # allow silly windows CrLf
  25. s/^\s*function\b/public static dynamic /o;
  26. s/^\s*end\b/}/o;
  27. s/^\s*#__csc__\b/\/* INLINE C-SHARP CODE *\//o;
  28. s/^\s*#__end__\b/\/* END *\//o;
  29.  
  30. $_ .= '{' if m/^\s*(if|else|while|for)\s*([(]|$)/o;
  31.  
  32. if (m/^\s*\bvar\b/o)
  33. {
  34. for my $func (keys %funcs) { s/\b$func\b/$funcs{$func}() /g; }
  35. s/\s*$/;/o;
  36. }
  37. for my $func (keys %funcs) { s/^(\s*)\b$func\b(.*)$/$1$funcs{$func}($2);/g; }
  38.  
  39. print "\t\t\t$_\n"
  40. }
  41.  
  42. print <<BOTTOM;
  43.  
  44.   }
  45.   }
  46. }
  47.  
  48. BOTTOM
  49.  
Success #stdin #stdout 0s 4728KB
stdin
var x = "Hello!"
var y = "World!"

var hello = x+y

writeln hello

var test_num = 5
writeln "test number: {0}", test_num

// THIS IS A COMMENT
/* another damn comment 
   of multiple 
   lines */

while (true)
	write "Enter Name:"
	
	var name = readln
	if (name == "me")
		writeln "THIS IS SO AWESOME!!!"
		writeln "I am me!"
	end
	
	else if(name == "exit")
		writeln "Exiting..."
		exit 0
	end
	
	else
		writeln "NOO!!! :("
		write "I am not 'me'..."
	end
end
stdout
using System;

/* AUTOGENERATED BY HACK COMPILER V 0.1 */
namespace Program
{
    public class MainApp
    {          
        public static void Main(string[] args)
        {   
			var x = "Hello!";
			var y = "World!";
			
			var hello = x+y;
			
			global::System.Console.WriteLine( hello);
			
			var test_num = 5;
			global::System.Console.WriteLine( "test number: {0}", test_num);
			
			// THIS IS A COMMENT
			/* another damn comment 
			   of multiple 
			   lines */
			
			while (true){
				global::System.Console.Write( "Enter Name:");
				
				var name = global::System.Console.ReadLine();
				if (name == "me"){
					global::System.Console.WriteLine( "THIS IS SO AWESOME!!!");
					global::System.Console.WriteLine( "I am me!");
			}
				
				else if(name == "exit")
					global::System.Console.WriteLine( "Exiting...");
					global::System.Environment.Exit( 0);
			}
				
				else{
					global::System.Console.WriteLine( "NOO!!! :(");
					global::System.Console.Write( "I am not 'me'...");
			}
			}

        }
    }
}