Exemplo n.º 1
0
    def visitExp(self, ctx: BKITParser.ExpContext):
        # a := b := 4
        # Binary(:=,Id(a),Binary(:=,Id(b),IntLiteral(4)))
        # [4,b,a]
        terms = list(reversed(list(map(lambda x: x.accept(self), ctx.term()))))

        # print(terms)

        def binaryGen(a, b):
            # 4 ,b
            return Binary(ctx.ASSIGN(0).getText(), b, a)

        #print(reduce(binaryGen, terms))
        return reduce(binaryGen, terms)
Exemplo n.º 2
0
 def visitExp(self, ctx: BKITParser.ExpContext):
     if ctx.ASSIGN():
         return Binary(ctx.ASSIGN().getText(), self.visitTerm(ctx.term()),
                       self.visitExp(ctx.exp()))
     else:
         return self.visitTerm(ctx.term())
Exemplo n.º 3
0
 def visitExp(self,ctx:BKITParser.ExpContext):
     if ctx.ASSIGN():
         return reduce(lambda rh,lh: Binary(ctx.ASSIGN(0).getText(), lh, rh), list(map(lambda term: self.visitTerm(term), ctx.term()))[::-1])
     return self.visitTerm(ctx.term(0))
Exemplo n.º 4
0
 def visitExp(self, ctx: BKITParser.ExpContext):
     # term
     if (ctx.getChildCount() == 1):
         return ctx.term().accept(self)
     # term ASSIGN exp
     return Binary(ctx.ASSIGN().getText(), ctx.term().accept(self), ctx.exp().accept(self))