コード例 #1
0
        public LispOperator <TBb> Compile(TBb blackboard, string code)
        {
            LispParser lispParser = new LispParser();

            LispParser.Node parseTree = lispParser.Parse(code);
            return(Compile(blackboard, parseTree));
        }
コード例 #2
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);
        }
コード例 #3
0
        public LispOperator <TBb> Compile(TBb blackboard, LispParser.Node parseTree)
        {
            foreach (LispOperator <TBb> lispOperator in Operators)
            {
                LispOperator <TBb> result = lispOperator.CreateOperator(blackboard, parseTree, this);
                if (result != null)
                {
                    return(result);
                }
            }

            throw new InvalidOperationException(
                      string.Format("Unrecognized token: {0}.", parseTree));
        }
コード例 #4
0
        public override LispOperator <TBb> CreateOperator(
            TBb blackboard,
            LispParser.Node node,
            LispParser.ICompiler <TBb> compiler)
        {
            LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode;
            if (identifierNode == null)
            {
                return(null);
            }

            Func <bool> func = blackboard.GetBoolFunction(identifierNode.Value);

            if (func == null)
            {
                return(null);
            }

            return(new BlackboardBoolFunction <TBb>(identifierNode.Value, func));
        }
コード例 #5
0
 LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICompiler <TBb> .Compile(TBb blackboard, LispParser.Node parseTree)
 {
     return(Compile(blackboard, parseTree));
 }
コード例 #6
0
 LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICanCreateFromLispParseTree <TBb> .CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
 {
     return(CreateOperator(blackboard, node, compiler));
 }
コード例 #7
0
 public abstract LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler);
コード例 #8
0
 public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
 {
     LispParser.StringNode stringNode = node as LispParser.StringNode;
     return(stringNode != null ? new StringConstant <TBb>(stringNode.Value) : null);
 }
コード例 #9
0
        public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
        {
            LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode;

            return(identifierNode != null && identifierNode.Value == "False" ? new FalseConstant <TBb>() : null);
        }
コード例 #10
0
 public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
 {
     LispParser.IntegerNode integerNode = node as LispParser.IntegerNode;
     return(integerNode != null ? new IntConstant <TBb>(integerNode.Value) : null);
 }