def visitOperand(self,ctx:MCParser.OperandContext):
     if ctx.literals():
         return self.visit(ctx.literals())
     elif ctx.ID():
         return Id(ctx.ID().getText())
     else:
         return self.visit(ctx.funcall())
Beispiel #2
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.exp():
         return self.visit(ctx.exp())
     elif ctx.INTLIT():
         return IntLit(int(ctx.INTLIT().getText()))
     else:
         return BoolLit(True if (
             ctx.BOOLIT().getText() == "true") else False)
Beispiel #3
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     # if ctx.getChildCount() == 3:
     #     return ctx.exp().accept(self) # generate code for the third right hand side
     # elif ctx.INTLIT():
     #     return IntLit(int(ctx.INTLIT().getText())) # return a IntLit object
     # print(ctx.BOOLIT().getText(), type(ctx.BOOLIT().getText()))
     # if ctx.BOOLIT().getText() == 'true': return True
     # else: return False # return a BoolLit object
     # return BoolLit(ctx.BOOLIT().getText())
     return self.visit(ctx.exp()) if ctx.getChildCount() == 3 else IntLit(
         int(ctx.INTLIT().getText())) if ctx.INTLIT(
         ) else True if ctx.BOOLIT().getText() == 'true' else False
Beispiel #4
0
 def visitOperand(self, ctx:MCParser.OperandContext):
     if (ctx.literals()):
         return self.visit(ctx.literals())
     if (ctx.ID()):
         return Id(ctx.ID().getText())
     if (ctx.func_call()):
         return self.visit(ctx.func_call())
     if (ctx.sub_exp()):
         return self.visit(ctx.sub_exp())
     return self.visit(ctx.index_exp())
 def visitOperand(self, ctx:MCParser.OperandContext):
     value = ctx.getChild(0).getText()
     if ctx.INTLIT():
         return IntLiteral(int(value))
     elif ctx.FLOATLIT():
         return FloatLiteral(float(value))
     elif ctx.STRINGLIT():
         return StringLiteral(value)
     elif ctx.BOOLLIT():
         if value == "true":
             return BooleanLiteral(True)
         else:
             return BooleanLiteral(False)
     else:
         return Id(ctx.ID().getText())
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.INTLIT():
         return IntLiteral(int(ctx.INTLIT().getText()))
     elif ctx.Booleanlit():
         return BooleanLiteral(True if ctx.Booleanlit().getText()[0] ==
                               "t" else False)
     elif ctx.Realit():
         return FloatLiteral(float(ctx.Realit().getText()))
     elif ctx.ID():
         return Id(ctx.ID().getText())
     elif ctx.Stringlit():
         return StringLiteral(ctx.Stringlit().getText())
     return self.visit(ctx.funcall())
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.INTLIT():
         return IntLiteral(int(ctx.INTLIT().getText()))
     elif ctx.BOOLLIT():
         return BooleanLiteral(True if ctx.BOOLLIT().getText() ==
                               "true" else False)
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     elif ctx.ID():
         return Id(ctx.ID().getText())
     elif ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     return self.visit(ctx.funcall())
 def visitOperand(self, ctx: MCParser.OperandContext):
     #operand: INTLIT | FLOATLIT | BOOLEANLIT | STRINGLIT | funcall | ID ;
     if ctx.INTLIT():
         return IntLiteral(int(ctx.INTLIT().getText()))
     if ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     if ctx.BOOLEANLIT():
         return BooleanLiteral(ctx.BOOLEANLIT().getText())
     if ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     if ctx.funcall():
         return self.visit(ctx.funcall())
     if ctx.ID():
         return Id(ctx.ID().getText())
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.getChildCount() == 3:
         return None  # generate code for the third right hand side
     elif ctx.INTLIT():
         return None  # return a IntLit object
     return None  # return a BoolLit object
Beispiel #10
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.funcall(): return self.visit(ctx.funcall())
     elif ctx.variable(): return self.visit(ctx.variable())
     elif ctx.INTLIT(): return IntLiteral(int(ctx.INTLIT().getText()))
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     elif ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     elif ctx.TRUE():
         return BooleanLiteral(True)
     else:
         return BooleanLiteral(False)
Beispiel #11
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     return self.visit(ctx.funccall()) if ctx.funccall() else self.visit(
         ctx.literal())
Beispiel #12
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.BOOLLIT():
         return BooleanLiteral(ctx.BOOLLIT())
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     elif ctx.INTLIT():
         return IntLiteral(int(ctx.INTLIT().getText()))
     elif ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     elif ctx.ID():
         return Id(ctx.ID().getText())
     else:
         return self.visit(ctx.invocation())
Beispiel #13
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     # operand: literal | ID | funcall;
     return self.visit(ctx.literal()) if ctx.literal() else Id(
         ctx.ID().getText()) if ctx.ID() else self.visit(ctx.funcall())
Beispiel #14
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.INTLIT(): return IntLiteral(int(ctx.INTLIT().getText()))
     elif ctx.FLOATLIT():
         return FloatLiteral(float(ctx.FLOATLIT().getText()))
     elif ctx.STRINGLIT():
         return StringLiteral(ctx.STRINGLIT().getText())
     elif ctx.BOOLIT():
         return BooleanLiteral(ctx.BOOLIT().getText() == "true")
     elif not ctx.LB():
         return Id(ctx.ID().getText())
     elif ctx.LB():
         return CallExpr(Id(ctx.ID().getText()),
                         [self.visit(x)
                          for x in ctx.exp()] if ctx.exp() else [])
Beispiel #15
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     return self.visit(ctx.getChild(0))
Beispiel #16
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     if ctx.INTLIT():
         return IntLiteral(ctx.INTLIT())
     elif ctx.BOOLLIT():
         return BooleanLiteral(ctx.BOOLLIT())
     elif ctx.FLOATLIT():
         return FloatLiteral(ctx.FLOATLIT())
     elif ctx.STRLIT():
         return StringLiteral(ctx.STRLIT().getText())
     elif ctx.ID():
         return Id(ctx.ID().getText())
     elif ctx.index_exp():
         return self.visit(ctx.index_exp())
     elif ctx.funcall():
         return self.visit(ctx.funcall())
Beispiel #17
0
 def visitOperand(self, ctx: MCParser.OperandContext):
     '''operand: literal | operand1 ;'''
     return self.visit(ctx.literal()) if ctx.literal() else self.visit(
         ctx.operand1())