1. Gigih Aji Ibrahim
  2. pytegal

Commits

Gigih Aji Ibrahim  committed f1a5d8a

fix bugs

  • Participants
  • Parent commits 2d5ce9b
  • Branches default

Comments (0)

Files changed (3)

File src/parser4.py

View file
  • Ignore whitespace
 
 
     def pUnaryExpr(self, token):
-        expr = self.pExpr()
+        expr = self.pExpr(self.CondPred)
         return UnaryExpr(self.getLoc(token), token.type, expr)
 
 
             caseExpr  = CaseExpr(self.getLoc(condExpr.loc), condExpr, thenBlock)
             cases.append(caseExpr)
 
-        if self.accept('else'):
-            elseBlock = self.groupBlockStmt()
+        elseBlock = self.groupBlockStmt() if self.accept('else') else []
         
         self.expect('#DEDENT')
         return MatchExpr(self.getLoc(token), left, cases, elseBlock)

File src/pygen/generator.py

View file
  • Ignore whitespace
                 self.visit(condExpr)
         
         def _rewrite(block):
-            with self.wrap(PyAssignStmt()):
-                self.var(name)
+            if name:
+                with self.wrap(PyAssignStmt()):
+                    self.var(name)
+                    self.visit(block)
+            else:
                 self.visit(block)
         
         with self.wrap(PyIfStmt()):
         self.var(self.toPyName(node.symbol))
 
     def vMatchExpr(self, node):
-        ## NYI
-        pass
+        ## tranform to multi if stmt
+        self._createMultiIfStmt(None, node)
     
     def vCaseExpr(self, node):
         ## NYI

File src/step/typechecker.py

View file
  • Ignore whitespace
                 self.visit(node)
 
                 ## rewrite or wrap the statement as ReturnStmt
-                if len(node) == 1 and not isinstance(node[0], ReturnStmt):
+                if len(node) == 1 and not isinstance(node[0], ReturnStmt) and not isinstance(node[0].parent.returnType, VoidType):
                     node[0].parent.stmts[0] = self.wrapReturnStmt(node[0])
 
             except SemanticError as ex: