using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ShintenScript { public abstract class ASTNodeBinaryNumericOperator : IASTNode { public IASTNode lhs, rhs; protected ASTNodeBinaryNumericOperator(IASTNode lhs, IASTNode rhs) { this.lhs = lhs; this.rhs = rhs; } public bool Const() { return lhs.Const() && rhs.Const(); } public object CreateFunction() { SSType lhst = lhs.Type(); SSType rhst = rhs.Type(); if (lhst == SSType.real && rhst == SSType.real) { Func left = (Func)lhs.CreateFunction(); Func right = (Func)rhs.CreateFunction(); return CreateFunction11(left, right); } throw new Exception("This should be unreachable"); } public SSType Type() { SSType lhst = lhs.Type(); SSType rhst = rhs.Type(); if (lhst == SSType.real && rhst == SSType.real) return SSType.real; throw new TypeException($"Unsupported types for operator '{Op()}': {lhst} and {rhst}"); } public abstract string Op(); public abstract object CreateFunction11(Func left, Func right); } }