changeset 5:91e08ff0630d

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 28 Oct 2020 14:16:09 +0900
parents e66321b51bb5
children 1896f63eedc1
files tl1trans/tl1trans.pl
diffstat 1 files changed, 28 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }