88
99# &whitespaceStack(&stateStack); #I think that this works?
1010
11- if ($line =~ / ^#!/ && $. == 1) { # translate #! line
11+ # translate #! line
12+ if ($line =~ / ^#!/ && $. == 1) {
1213 print " #!/usr/bin/python2.7 -u\n " ;
1314
14- } elsif ($line =~ / ^\s *#/ || $line =~ / ^\s *$ / ) { # Blank & comment lines (unchanged)
15+ # Blank & comment lines (unchanged)
16+ } elsif ($line =~ / ^\s *#/ || $line =~ / ^\s *$ / ) {
1517 print $line ;
1618
17- } elsif ($line =~ / ^\s *print\s *"(.*)\\ n"[\s ;]*$ / ) { # print statement with newline
18- print " print \" $1 \"\n " ;
19- # "
20-
21- } elsif ($line =~ / ^\s *print\s *"(.*)"[\s ;]*$ / ) { # print statment with no newline
22- print " sys.stdout.write(\" $1 \" )\n " ;
23- # "
24-
25- } elsif ($line =~ / ^\s *[^\s ]*\s *=(.*);$ / ) { # arithmetic operations
19+ # print statement with newline
20+ } elsif ($line =~ / ^\s *print\s *"(.*)\\ n"[\s ;]*$ / ) {
21+ my $printInput = $1 ;
22+ if ($printInput =~ / ^(.*)\s *\$ (.*)*$ / ) { # there is ONE variable
23+ $printInput =~ s /\$ // ; # removes variable signal
24+ print " print $printInput \n " ;
25+ } else { # there is no variable (or many, which currently kill everything)
26+ print " print \" $printInput \"\n " ;
27+ }
28+
29+ # print statment with no newline
30+ } elsif ($line =~ / ^\s *print\s *"(.*)"[\s ;]*$ / ) {
31+ my $printInput = $1 ;
32+ if ($printInput =~ / ^(.*)\s *\$ (.*)*$ / ) { # there is ONE variable
33+ $printInput =~ s /\$ // ; # removes variable signal
34+ print " sys.stdout.write($printInput )\n " ;
35+ } else { # there is no variable (or many, which currently kill everything)
36+ print " sys.stdout.write(\" $printInput \" )\n " ;
37+ }
38+
39+ # arithmetic operations
40+ } elsif ($line =~ / ^\s *[^\s ]*\s *=(.*);$ / ) {
2641# print $line;
2742 &arithmeticLines($line );
28-
29- } elsif ($line =~ / ^\s *[^\s ]*\s *(break)(.*);$ / || $line =~ / ^\s *[^\s ]*\s *(continue)(.*);$ / ) { # break/continue
43+ # print "$lineToPrint\n";
44+
45+ # break/continue
46+ } elsif ($line =~ / ^\s *[^\s ]*\s *(break)(.*);$ / || $line =~ / ^\s *[^\s ]*\s *(continue)(.*);$ / ) {
3047 print " $1 "
31- } else { # Lines we can't translate are turned into comments
32- print " #$line \n " ;
33- }
3448
49+ # for loops
50+
51+ # while loops
3552
53+ # if statements
54+ } elsif ($line =~ / ^\s *(.*)\s *if\s *\( (.*)\) (.*)\s *$ / ) {
55+ my $condition = $2 ;
56+ print " if " ;
57+ &arithmeticLines($condition );
58+ print " :\n " ;
3659
60+ # elsif
61+
62+ # else
63+ # } elsif ($line =~ /^$/
64+
65+ # end curly brace needs removal
66+ } elsif ($line =~ / ^\s *(.*)\s *\}\s *\( (.*)\) (.*);$ / ) {
67+ $line =~ s /\} // ;
68+
69+ # Lines we can't translate are turned into comments
70+ } else {
71+ print " #$line \n " ;
72+ }
3773
3874}
3975sub arithmeticLines {
@@ -49,7 +85,7 @@ sub arithmeticLines {
4985 $_ [0] =~ s / !\s / not/ g ;
5086
5187 $_ [0] =~ s /\; // ;
52- print " $_ [0]\n " ;
88+ print $_ [0];
5389}
5490
5591# WHERE IN THE PROCESS DO I DO THESE? Before every line needs an update, yeah?
0 commit comments