Example #1
0
        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);
        }
Example #2
0
 protected virtual void ValidateChildren(LispParser.MethodNode node)
 {
     //if (Children.Count == 0)
     //{
     //    throw new InvalidOperationException("{0} must have 1 or more arguments!");
     //}
 }
Example #3
0
 protected virtual void DecorateParseTree(LispParser.MethodNode node)
 {
     foreach (LispOperator <TBb> lispNode in Children)
     {
         node.Children.Add(lispNode.BuildParseTree());
     }
     ValidateChildren(node);
 }
Example #4
0
 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));
     }
 }
Example #5
0
 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));
         }
     }
 }
Example #6
0
 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())));
         }
     }
 }
Example #7
0
 protected abstract LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler);
Example #8
0
 public override LispParser.Node BuildParseTree()
 {
     LispParser.MethodNode node = new LispParser.MethodNode(Name);
     DecorateParseTree(node);
     return(node);
 }
Example #9
0
 protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler)
 {
     return(new Format <TBb>());
 }
Example #10
0
 protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler)
 {
     return(new LessThanOrEqualTo <TBb>());
 }