Skip to content

Commit 72aa3fe

Browse files
committed
'Changes: print without newline, if statements, removal of closing curly braces as well as adding comments to demoes explaining what they are testing'
1 parent 3808cec commit 72aa3fe

File tree

5 files changed

+61
-19
lines changed

5 files changed

+61
-19
lines changed

demo00.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/usr/bin/perl -w
22

3+
#tests changing the first line and print lines with \n
4+
35
print "This is subset zero.\n";

demo01.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#!/usr/bin/perl -w
22

3+
#tests printing strings without a newline
4+
35
print "This is not subset zero.";

demo02.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/perl -w
22

3+
#tests arithmetic and printing a variable in print (please pretend that logic made sense)
4+
35
$a = 12;
46
$b = 2;
57

demo03.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
$c = $a + $b / $b;
77

88
if ($c != 0 && $a < 0) {
9-
print "Where is your logic?\n";
9+
print "Not right. No value for you.\n";
1010
} else {
11-
print "the value of c is $c.\n"
11+
print "$c"
1212
}

perlpythonLinesInProgress.pl

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,68 @@
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
}
3975
sub 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

Comments
 (0)