def visitLiteral(self, ctx: BKITParser.LiteralContext): if ctx.INT(): a = ctx.INT().getText() inlit = 0 if len(a) > 1: if a[1] == 'x' or a[1] == 'X': inlit = int(a, 16) elif a[1] == 'o' or a[1] == 'O': inlit = int(a, 8) else: inlit = int(a) else: inlit = int(a) return IntLiteral(inlit) elif ctx.FLOAT(): return FloatLiteral(float(ctx.FLOAT().getText())) elif ctx.BOOLEAN(): if ctx.BOOLEAN().getText() == 'True': return BooleanLiteral(True) else: return BooleanLiteral(False) elif ctx.STRING(): return StringLiteral(ctx.STRING().getText()) else: return self.visit(ctx.arr())
def visitLiteral(self, ctx:BKITParser.LiteralContext): if ctx.INT(): return IntLiteral(int(ctx.INT().getText(), 0)) elif ctx.FLOAT(): return FloatLiteral(float(ctx.FLOAT().getText())) elif ctx.BOOLEAN(): return BooleanLiteral(ctx.BOOLEAN().getText() == 'True') elif ctx.STRING(): return StringLiteral(ctx.STRING().getText()) else: return ctx.arr().accept(self)