def visitExp6(self, ctx: BKITParser.Exp6Context):
        if ctx.getChildCount() == 1:
            return ctx.exp7().accept(self)

        if ctx.LP():
            method = Id(ctx.ID().getText())
            idx = []
            num_function_call_exp = len(ctx.expression()) - len(ctx.LSB())
            funcall_exp = []
            for x in ctx.expression()[:num_function_call_exp]:
                funcall_exp.append(x.accept(self))

            arr = CallExpr(method, funcall_exp)

            for x in ctx.expression()[num_function_call_exp:]:
                idx.append(x.accept(self))

            return ArrayCell(arr, idx)
        else:
            arr = Id(ctx.ID().getText())
            idx = []
            for x in ctx.expression():
                idx.append(x.accept(self))

            return ArrayCell(arr, idx)
Example #2
0
 def visitExp6(self, ctx: BKITParser.Exp6Context):
     if ctx.getChildCount() == 3:
         return self.visit(ctx.getChild(1))
     elif ctx.ID():
         return Id(ctx.ID().getText())
     else:
         return self.visit(ctx.getChild(0))
Example #3
0
 def visitExp6(self,ctx:BKITParser.Exp6Context):
     if ctx.getChildCount()>1:
         expr=self.visit(ctx.exp7())
         listexp=[]
         for i in ctx.exp():
             listexp=listexp+[self.visit(i)]
         return ArrayCell(expr,listexp)
Example #4
0
 def visitExp5(self,ctx:BKITParser.Exp6Context):
     if ctx.SUB():
         return UnaryOp(ctx.SIGN().getText(),self.visit(ctx.exp5))
     elif ctx.SUBFLOAT():
         return UnaryOp(ctx.SIGNFLOAT().getText(),self.visit(ctx.exp5))
     else: 
         return self.visit(ctx.exp6())
Example #5
0
 def visitExp6(self,ctx:BKITParser.Exp6Context):
     if ctx.op_index():
         getID = self.visitExp6(ctx.exp6())
         getOpIdx = self.visitOp_index(ctx.op_index())
         if isinstance(getID, list):
             value = []
             value.extend(getID[1])
             value.append(getOpIdx)
             return [getID[0], value]
         else:
             return [getID, [getOpIdx]]
     else:
         temp = self.visitOperands(ctx.operands())
         return temp
 def visitExp6(self, ctx: BKITParser.Exp6Context):
     if ctx.getChildCount() > 1:
         body = self.visit(ctx.exp6())
         if ctx.SUB():
             op = str(ctx.SUB().getText())
         if ctx.SUBF():
             op = str(ctx.SUBF().getText())
         return UnaryOp(op, body)
     else:
         return self.visit(ctx.exp7())
Example #7
0
 def visitExp6(self, ctx: BKITParser.Exp6Context):
     if ctx.getChildCount() == 1: return self.visit(ctx.exp7())
     else:
         return ArrayCell(self.visit(ctx.exp6()),
                          self.visit(ctx.index_operators()))  ####
 def visitExp6(self, ctx: BKITParser.Exp6Context):
     if ctx.array_literal():
         return self.visit(ctx.array_literal())
     if ctx.literal():
         return self.visit(ctx.literal())
     if ctx.ID():
         return Id(ctx.ID().getText())
     if ctx.call_exp():
         return self.visit(ctx.call_exp())
     if ctx.array_cell():
         return self.visit(ctx.array_cell())
     if ctx.exp():
         return self.visit(ctx.exp())
Example #9
0
 def visitExp6(self, ctx: BKITParser.Exp6Context):
     if ctx.INTLIT():
         if ctx.INTLIT().getText()[:2] in ['0x', '0X']:
             return IntLiteral(int(ctx.INTLIT().getText(), 16))
         elif ctx.INTLIT().getText()[:2] in ['0o', '0O']:
             return IntLiteral(int(ctx.INTLIT().getText(), 8))
         else:
             return IntLiteral(int(ctx.INTLIT().getText()))
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     elif ctx.BOOLLIT():
         return BooleanLiteral('True' == ctx.BOOLLIT().getText())
     elif ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     elif ctx.value():
         return self.visit(ctx.value())
     elif ctx.exp():
         return self.visit(ctx.exp())
     elif ctx.funccall():
         return self.visit(ctx.funccall())
 def visitExp6(self, ctx: BKITParser.Exp6Context):
     return ctx.exp7().accept(
         self) if ctx.getChildCount() == 1 else ArrayCell(
             ctx.exp7().accept(self),
             list(map(lambda exp: exp.accept(self), ctx.expression())))
Example #11
0
 def visitExp6(self, ctx: BKITParser.Exp6Context):
     if ctx.getChildCount() == 1:
         return self.visit(ctx.exp7())
     op = ctx.SubInt().getText() if ctx.SubInt() else ctx.SubFloat(
     ).getText()
     return UnaryOp(op, self.visit(ctx.exp6()))