Beispiel #1
0
	static object ComputationValue(Racr.AstNode n) {
		var op = n.GetOperator();
		var operands = n.GetOperands().Children();
		var args = operands.Select(p => ((Racr.AstNode) p).Value()).ToArray();
		var func = opTable[op];
		try { return func(args); }
		catch { return null; }
	}
Beispiel #2
0
	static string ComputationSExpr(Racr.AstNode n) {
		return "(~~ " + n.GetOperator() + " " + String.Join(" ", n.GetOperands().Children().Select(x => ((Racr.AstNode)x).SExpr())) + ")";
	}
Beispiel #3
0
	static ValueTypes ComputationType(Racr.AstNode n) {
		var op = n.GetOperator();
		var inType = ValueTypes.ErrorType;
		var outType = ValueTypes.ErrorType;
		var operands = n.GetOperands().Children();
		if (op == "&&" || op == "//" || op == "not") inType = outType = ValueTypes.Boolean;
		else if (op == "=" || op == "<" || op ==  ">" || op == "<=" || op == ">=" || op == "!=") {
			inType = ValueTypes.Number;
			outType = ValueTypes.Boolean;
		}
		else if (op == "string=?" || op == "string<?" || op ==  "string>?" || op == "string<=?" || op == "string>=?") {
			inType = ValueTypes.String;
			outType = ValueTypes.Boolean;
		}
		else if (op == "+" || op == "-" || op == "*" || op == "/") inType = outType = ValueTypes.Number;
		else if (op == "string-append") inType = outType = ValueTypes.String;
		if (operands.Any(x => ((Racr.AstNode) x).Type() != inType)) return ValueTypes.ErrorType;
		return outType;
	}