Exemplo n.º 1
0
        public LispOperator <TBb> Compile(TBb blackboard, string code)
        {
            LispParser lispParser = new LispParser();

            LispParser.Node parseTree = lispParser.Parse(code);
            return(Compile(blackboard, parseTree));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
 LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICompiler <TBb> .Compile(TBb blackboard, LispParser.Node parseTree)
 {
     return(Compile(blackboard, parseTree));
 }
Exemplo n.º 6
0
 LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICanCreateFromLispParseTree <TBb> .CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler)
 {
     return(CreateOperator(blackboard, node, compiler));
 }
Exemplo n.º 7
0
 public abstract LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler);
Exemplo n.º 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }