public object DoForNum(NumAST num, object options = null) { ObjType ot = new ObjType(); switch (num.token.tokenType) { case TokenType.IntNum: ot = GetTypeFromName("int64"); break; case TokenType.FloatNum: ot = GetTypeFromName("float64"); break; } ObjExpr oe = new ObjExpr() { val = num.value, isSimplifiedToNum = true, isInt = (num.token.tokenType == TokenType.IntNum), objType = ot }; return(oe); }
ObjExpr BinOpTwoLiterals(ObjExpr lhs, ObjExpr rhs, string op) { ObjExpr objExpr = new ObjExpr(); if (lhs.isInt) { Int64 lhsVal = Int64.Parse(lhs.val); if (rhs.isInt) { Int64 rhsVal = Int64.Parse(rhs.val); Int64 tot; switch (op) { case "+": tot = lhsVal + rhsVal; break; case "-": tot = lhsVal - rhsVal; break; case "*": tot = lhsVal * rhsVal; break; case "/": tot = lhsVal / rhsVal; break; default: tot = 42; break; } objExpr.val = tot.ToString(); objExpr.isInt = true; objExpr.objType = GetTypeFromName("int64"); } else { double rhsVal = double.Parse(rhs.val); double tot; switch (op) { case "+": tot = lhsVal + rhsVal; break; case "-": tot = lhsVal - rhsVal; break; case "*": tot = lhsVal * rhsVal; break; case "/": tot = lhsVal / rhsVal; break; default: tot = 42.0; break; } objExpr.val = tot.ToString(); objExpr.isInt = false; objExpr.objType = GetTypeFromName("float"); } } else { double lhsVal = double.Parse(lhs.val); if (rhs.isInt) { Int64 rhsVal = Int64.Parse(rhs.val); double tot; switch (op) { case "+": tot = lhsVal + rhsVal; break; case "-": tot = lhsVal - rhsVal; break; case "*": tot = lhsVal * rhsVal; break; case "/": tot = lhsVal / rhsVal; break; default: tot = 42.0; break; } objExpr.val = tot.ToString(); objExpr.isInt = false; objExpr.objType = GetTypeFromName("float"); } else { double rhsVal = double.Parse(rhs.val); double tot; switch (op) { case "+": tot = lhsVal + rhsVal; break; case "-": tot = lhsVal - rhsVal; break; case "*": tot = lhsVal * rhsVal; break; case "/": tot = lhsVal / rhsVal; break; default: tot = 42.0; break; } objExpr.val = tot.ToString(); objExpr.isInt = false; objExpr.objType = GetTypeFromName("float"); } } objExpr.isSimplifiedToNum = true; return(objExpr); }