# HG changeset patch # User Shinji KONO # Date 1603862169 -32400 # Node ID 91e08ff0630dafed7d820cb04b6194e5e4c09d36 # Parent e66321b51bb5dcec3d9e4d7d61045a36138f3553 ... diff -r e66321b51bb5 -r 91e08ff0630d tl1trans/tl1trans.pl --- a/tl1trans/tl1trans.pl Wed Oct 21 17:31:44 2020 +0900 +++ b/tl1trans/tl1trans.pl Wed Oct 28 14:16:09 2020 +0900 @@ -132,6 +132,7 @@ # space means a statement separation our $cnest = 0; +our $st = 0; sub statement { my ($skip) = @_; statement : while(1) { @@ -142,7 +143,10 @@ } while($_ ne "") { if (s/^\s+//) { - print $&; + print "$&"; + if ($st) { + print ";"; $st = 0; + } } if (s/^WRITE\((\d+)://) { my $d = $1; @@ -162,20 +166,20 @@ } if ($str ne "") { $str = "\"$str\""; - print "write($d,$str,strlen($str));" + &output("write($d,$str,strlen($str));") } } elsif (s/^CRLF//) { - print "write($d,\"\\n\",1);"; + &output("write($d,\"\\n\",1);"); } elsif (s/^\w+//) { - print "dprintf($d,\"%d\",$&);"; + &output("dprintf($d,\"%d\",$&);"); } elsif (s/.//) { } elsif ($& eq ")") { last; } } - } elsif (s/^[[({]//) { + } elsif (s/^[[{]//) { &output("{"); $nest++; next; - } elsif (s/^[])}]//) { + } elsif (s/^[]}]//) { &output("}"); $nest--; next; # FOR I:=1 TO 10 DO [ } elsif (s/^FOR\s+(\w+):=(\w+)\s+TO\s+(\w+)\s+DO\s*//) { @@ -197,31 +201,37 @@ } } $nest = $cnest ; - } elsif (s/^IF//) { + } elsif (s/^IF\s*//) { &output("if ("); - } elsif (s/^THEN//) { + } elsif (s/^THEN\s*//) { &output(") "); - } elsif (s/^ELSE//) { + } elsif (s/^ELSE\s*//) { &output(" else "); - } elsif (s/^REPEAT//) { + } elsif (s/^DO\s*//) { &output("do { "); - } elsif (s/^WHILE\s+(.*)\s+DO\s+//) { + } elsif (s/^REPEAT\s*//) { + &output("do { "); + } elsif (s/^WHILE\s+([^\s]*)\s+DO\s+//) { &output("while ($1) "); - } elsif (s/^UNTIL\s+(.*)//) { + } elsif (s/^WHILE\s*//) { + &output("while "); + } elsif (s/^UNTIL\s+([^\s]*)\s+//) { &output("} while ($1 == 0);"); - } elsif (s/^BEGIN//) { + } elsif (s/^BEGIN\s*//) { &output("{"); $nest++; - } elsif (s/^END//) { + } elsif (s/^END\s*//) { &output("}"); $nest--; last statement if ($nest==0) ; } elsif (s/^(\w+)//) { - &output(" $1();"); - } elsif (s/^RETURN\s*(\w*)//) { + &output(" $1"); + } elsif (s/^RETURN\s*(\w*)\s*//) { &output("return $1;"); - } elsif (s/^:=//) { + } elsif (s/^:=\s*//) { &output("="); + } elsif (s/^=\s*//) { + &output("=="); } elsif (s/^.//) { &output($&); } @@ -290,6 +300,7 @@ sub output { my ($o) = @_; + $st = 1; print $o; }