Beispiel #1
0
    def visitExpr(self, ctx: ExprParser.ExprContext):
        if ctx.getChildCount() == 1:
            n = next(ctx.getChildren())
            print("  " * self.nivell +
                  ExprParser.symbolicNames[n.getSymbol().type] + '(' +
                  n.getText() + ')')
            self.nivell -= 1
        elif ctx.getChildCount() == 3:
            op = 'NOT DEFINED IN TreeVisitor.py'
            if ctx.MES():
                op = 'MES(+)'
            elif ctx.DIV():
                op = 'DIV(/)'
            elif ctx.MUL():
                op = 'MUL(*)'
            elif ctx.MENYS():
                op = 'MENYS(-)'
            elif ctx.POW():
                op = 'POW(^)'

            print('  ' * self.nivell + op)
            self.nivell += 1
            self.visit(ctx.expr(0))
            self.nivell += 1
            self.visit(ctx.expr(1))
            self.nivell -= 1
Beispiel #2
0
 def visitExpr(self, ctx: ExprParser.ExprContext):
     if ctx.getChildCount() == 1:
         n = next(ctx.getChildren())
         print(" " * self.nivell + \
               ExprParser.symbolicNames[n.getSymbol().type] + \
               '(' +n.getText() + ')')
         self.nivell -= 1
     elif ctx.getChildCount() == 3:
         l = [i for i in ctx.getChildren()]
         print(' ' * self.nivell +
               ExprParser.symbolicNames[l[1].getSymbol().type] + "(" +
               l[1].getText() + ")")
         self.nivell += 1
         self.visit(ctx.expr(0))
         self.nivell += 1
         self.visit(ctx.expr(1))
         self.nivell -= 1