コード例 #1
0
ファイル: CST.py プロジェクト: juqian/tiny-py-interpreter
 def walk(self, tree:ParseTree, ast):
     if tree.getChildCount() > 1:
         for child in tree.getChildren():
             # Don't add useless token to tree
             if isinstance(child.getPayload(), antlr4.Token) and child.symbol.type in useless_tokens:
                 continue
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)
     else:
         super().walk(tree, ast)
コード例 #2
0
ファイル: CST.py プロジェクト: huynhtttg11/HuynhTrung
 def walk(self, tree: ParseTree, ast):
     if tree.getChildCount() > 1:
         for child in tree.getChildren():
             # Don't add useless token to tree
             if isinstance(
                     child.getPayload(),
                     antlr4.Token) and child.symbol.type in useless_tokens:
                 continue
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)
     else:
         super().walk(tree, ast)
コード例 #3
0
ファイル: CST.py プロジェクト: huynhtttg11/HuynhTrung
 def walk(self, tree: ParseTree, ast):
     if tree.getChildCount() == 0:
         # We've reached a leaf. We must create a new instance of an AST because
         # the constructor will make sure this new instance is added to its parent's
         # child nodes.
         CstFlattened(ast, tree)
     elif tree.getChildCount() == 1:
         # We've reached an inner node with a single child: we don't include this in
         # our AST.
         self.walk(tree.getChild(0), ast)
     elif tree.getChildCount() > 1:
         for child in tree.getChildren():
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)
コード例 #4
0
ファイル: CST.py プロジェクト: juqian/tiny-py-interpreter
 def walk(self, tree:ParseTree, ast):
     if tree.getChildCount() == 0:
         # We've reached a leaf. We must create a new instance of an AST because
         # the constructor will make sure this new instance is added to its parent's
         # child nodes.
         CstFlattened(ast, tree)
     elif tree.getChildCount() == 1:
         # We've reached an inner node with a single child: we don't include this in
         # our AST.
         self.walk(tree.getChild(0), ast)
     elif tree.getChildCount() > 1:
         for child in tree.getChildren():
             temp = CstFlattened(ast, child)
             if not isinstance(temp.payload, antlr4.Token):
                 # Only traverse down if the payload is not a Token.
                 self.walk(child, temp)