Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. ,[>--[<++>+++++++]<+[>+>+<<-]>[<+>-]+>[<->[-]]<[[,----------]]<>>--[>+
  2. <++++++]<<--------[>+>+<<-]>[<+>-]+>[<->[-]]<[->>.<<]>>+<<<-[>+>+<<-]>
  3. [<+>-]+>[<->[-]]<[->>.<<]>>+<<<-[>+>+<<-]>[<+>-]+>[<->[-]]<[->>.<<]>>+
  4. <<<-[>+>+<<-]>[<+>-]+>[<->[-]]<[->>.<<]>>++++++++++++++<<<------------
  5. --[>+>+<<-]>[<+>-]+>[<->[-]]<[->>.<<]>>++<<<--[>+>+<<-]>[<+>-]+>[<->[-
  6. ]]<[->>.<<]>++++[>+++++++<-]>+<<++++[<------->-]<-[>+>+<<-]>[<+>-]+>[<
  7. ->[-]]<[->>.<<]>>++<<<--[>+>+<<-]>[<+>-]+>[<->[-]]<[->>.<<]>>[-]<<<,]
  8.  
  9. ,[
  10.  
  11. #subtract #
  12. >--[<++>+++++++]<+
  13.  
  14. #strip comments
  15. [>+>+<<-]>[<+>-]+>[<->[-]]<[[,----------]]<
  16.  
  17. #put '+' in 4th cell
  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. $/="nn";
  46. chomp($prog = <>);
  47. for(1..length($prog)){
  48. $rev.=chop $prog;
  49. }
  50. #print$rev;
  51. for(1..length($rev)){
  52. $temp = chop$rev;
  53. if ($temp eq '"'){
  54. if($quote == 0){$quote = 1}
  55. else{$quote = 0}
  56. }
  57. if($temp eq '#' && $quote == 0){$comment = 1}
  58. if($temp eq "n"){
  59. $comment = 0;
  60. }
  61. if($comment != 1){
  62. $prog.=$temp;
  63. }
  64. }
  65. for(1..length($prog)){
  66. $rev.=chop $prog;
  67. }
  68. for(1..length($rev)){
  69. $temp = chop$rev;
  70. if ($temp eq ";" || $temp eq "}" || $temp eq ")" || $temp eq "=" || $temp eq "{"){
  71. $ws = 2;
  72. }
  73. if(($temp eq "n" || $temp eq " ") && $ws != 0){$ws = 1}elsif($ws==1){$ws=0}
  74. if($ws != 1){
  75. $prog.=$temp;
  76. }
  77. }
  78. print$prog;
  79.  
  80. for(1..10) {
  81. print "Hello, World!";#prints hello world
  82. print ($n = <>); #prints "#"
  83. }
  84.  
  85. for(1..10){print "Hello, World!";print ($n =<>);}
  86.  
  87. #!/usr/bin/env perl
  88. use strict;
  89. use warnings;
  90.  
  91. my $string_re = qr/"(?:\[btnfr"'\]|\(?:[0-3][0-7][0-7]|[0-7]{1,2})|\u+[0-9a-fA-F]{4}|[^rn\"])*"/;
  92. my @lines = <>;
  93. my @strings = ();
  94.  
  95. # First, replace strings with placeholders. Strings suck REALLY hard when replacing.
  96. map {
  97. while (m/$string_re/) {
  98. s//"32".@strings."32"/e;
  99. push @strings, $&;
  100. }
  101. } @lines;
  102.  
  103. # Remove comments
  104. my $in_comment = 0;
  105. my $partial_line;
  106.  
  107. sub remove_comments {
  108. my $line = $_[0];
  109. start:
  110. if ($in_comment) {
  111. if ((my $mulc_end_index = index $line, '*/') != -1) {
  112. $line = $partial_line . substr $line, $mulc_end_index + 2;
  113. $in_comment = 0;
  114. goto no_comment;
  115. }
  116. return 0;
  117. }
  118.  
  119. no_comment:
  120. my $eolc_idx = index $line, '//';
  121. my $mulc_idx = index $line, '/*';
  122.  
  123. if ($mulc_idx == -1 || ($eolc_idx != -1 && $eolc_idx < $mulc_idx)) {
  124. $line =~ s;//.*$;;;
  125. } elsif ($mulc_idx != -1) {
  126. $in_comment = 1;
  127. $partial_line = substr $line, 0, $mulc_idx;
  128. goto start;
  129. }
  130. $_ = $line;
  131. return 1
  132. }
  133.  
  134. @lines = grep {&remove_comments($_)} @lines;
  135.  
  136. # Remove empty lines, remove line ends
  137. @lines = grep(!/^s*$/, @lines);
  138. map {chomp;s/^s*//;s/s*$//} @lines;
  139.  
  140. # Remove unnecessary whitespace
  141. map {s/s*([][(){}><|&~,;=!+-])s*/$1/g} @lines;
  142.  
  143. # Remove unnecessary package declaration
  144. $lines[0] =~ s/^package [^;]+;//;
  145.  
  146. # Finally, put strings back.
  147. map {s/32(d+?)32/$strings[$1]/g} @lines;
  148.  
  149. print @lines;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement