def visitUnit_infinity(self, ctx: parse.Unit_infinityContext): """unit_infinity inf=(INFINITY | NEG_INFINITY)""" if ctx.inf.type == parse.INFINITY: return RealNumber(float("inf")) else: return RealNumber(float("-inf"))
def visitTex_symb_single(self, ctx: parse.Tex_symb_singleContext): """tex_symb_single (NON_EI_LETTER | E | I | DIGIT) """ if ctx.E(): return RealNumber(np.e) if ctx.I(): return ComplexNumber.create(RealNumber(0), RealNumber(1)) text = ctx.getText() if ctx.DIGIT(): return RealNumber(int(text)) else: return Variable(self.state, text)
def visitMult_sign(self, ctx: parse.Mult_signContext): """mult_sign sign=(PLUS | MINUS) mult_expr """ if ctx.sign.type == parse.MINUS: return Expression(op.mul, RealNumber(-1), self.visit(ctx.mult_expr())) else: return self.visit(ctx.mult_expr())
def visitNnint(self, ctx: parse.NnintContext): """nnint DIGIT+ """ return RealNumber(int(ctx.getText()))
def visitNumber(self, ctx: parse.NumberContext): """number MINUS? DIGIT+ (POINT DIGIT*)? """ return RealNumber(float(ctx.getText()))
def visitUnit_i(self, ctx: parse.Unit_iContext): # i = 0 + 1i return ComplexNumber.create(RealNumber(0), RealNumber(1))
def visitUnit_e(self, ctx: parse.Unit_eContext): return RealNumber(math.e)
def visitUnit_pi(self, ctx: parse.Unit_piContext): return RealNumber(math.pi)