public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.MethodNode methodNode = node as LispParser.MethodNode; if (methodNode == null || methodNode.Identifier.Value != Name) { return(null); } LispMethod <TBb> method = CreateMethod(blackboard, methodNode, compiler); if (method != null) { if (method.GetType() != GetType()) { throw new InvalidOperationException( string.Format( "Expected {0} but compiled to {1}!", TypeHelper.GetFriendlyTypeName(GetType()), TypeHelper.GetFriendlyTypeName(method.GetType()))); } foreach (LispParser.Node child in methodNode.Children) { method.Children.Add((LispOperator <TBb>)compiler.Compile(blackboard, child)); } } return(method); }
protected virtual void ValidateChildren(LispParser.MethodNode node) { //if (Children.Count == 0) //{ // throw new InvalidOperationException("{0} must have 1 or more arguments!"); //} }
protected virtual void DecorateParseTree(LispParser.MethodNode node) { foreach (LispOperator <TBb> lispNode in Children) { node.Children.Add(lispNode.BuildParseTree()); } ValidateChildren(node); }
protected override void ValidateChildren(LispParser.MethodNode node) { base.ValidateChildren(node); if (Children.Count < 0) { throw new InvalidOperationException( string.Format( "{0} must have 2 or more arguments!", Name)); } }
protected override void ValidateChildren(LispParser.MethodNode node) { base.ValidateChildren(node); foreach (LispOperator <TBb> child in Children) { ICanEvaluateToString floater = child as ICanEvaluateToString; if (floater == null) { throw new InvalidOperationException( string.Format( "Arguments for {0} must be evaluatable to string. {1} isn't!", Name, child.GetType().Name)); } } }
protected override void ValidateChildren(LispParser.MethodNode node) { base.ValidateChildren(node); if (Children.Count != 2) { throw new InvalidOperationException( string.Format( "{0} must have 2 arguments!", Name)); } foreach (LispOperator <TBb> child in Children) { ICanEvaluateToFloat floater = child as ICanEvaluateToFloat; if (floater == null) { throw new InvalidOperationException( string.Format( "Arguments for {0} must be evaluatable to float. {1} isn't!", Name, TypeHelper.GetFriendlyTypeName(child.GetType()))); } } }
protected abstract LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler);
public override LispParser.Node BuildParseTree() { LispParser.MethodNode node = new LispParser.MethodNode(Name); DecorateParseTree(node); return(node); }
protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler) { return(new Format <TBb>()); }
protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler) { return(new LessThanOrEqualTo <TBb>()); }