Exemple #1
0
 public static DelEvaluate <T> Inverted <T>(this DelEvaluate <T> d)
 {
     if (d == Helper <T> .False)
     {
         return(Helper <T> .True);
     }
     if (d == Helper <T> .True)
     {
         return(Helper <T> .False);
     }
     return((x) => !d(x));
 }
Exemple #2
0
 /// <summary>
 ///     Construct a function based on the provided signature.
 /// </summary>
 /// <param name="theSignature">The signature.</param>
 /// <param name="theEvaluate">The evaluate delegate.</param>
 public BasicTemplate(String theSignature, DelEvaluate theEvaluate)
     : this(0, theSignature, NodeType.Function, false, 0, theEvaluate, null, null)
 {
 }
 /// <summary>
 ///     Construct a function based on the provided signature.
 /// </summary>
 /// <param name="theSignature">The signature.</param>
 /// <param name="theEvaluate">The evaluate delegate.</param>
 public BasicTemplate(String theSignature, DelEvaluate theEvaluate)
     : this(0, theSignature, NodeType.Function, false, 0, theEvaluate, null, null)
 {
 }
Exemple #4
0
        /// <summary>
        ///     Construct a basic template object.
        /// </summary>
        /// <param name="thePrecedence">The precedence.</param>
        /// <param name="theSignature">The opcode signature.</param>
        /// <param name="theType">The opcode type.</param>
        /// <param name="isVariable">True, if this opcode is a variable.</param>
        /// <param name="theDataSize">The data size kept for this opcode.</param>
        /// <param name="theEvaluate">The evaluator delegate.</param>
        /// <param name="theIsPossibleReturnType">The return type delegate.</param>
        /// <param name="theRandomize">The randomizer delegate.</param>
        public BasicTemplate(int thePrecedence, String theSignature,
                             NodeType theType, bool isVariable,
                             int theDataSize,
                             DelEvaluate theEvaluate,
                             DelIsPossibleReturnType theIsPossibleReturnType,
                             DelRandomize theRandomize)
        {
            _precedence = thePrecedence;
            _signature  = theSignature;
            _varValue   = isVariable;
            _dataSize   = theDataSize;
            _nodeType   = theType;

            _delEvaluate             = theEvaluate;
            _delIsPossibleReturnType = theIsPossibleReturnType;
            _delRandomize            = theRandomize;

            if (theSignature.Trim().Equals("("))
            {
                // special case, we add a left-paren for the shunting yard alg.
                _name        = theSignature;
                _returnValue = null;
            }
            else
            {
                // non-special case, find the name of the function/operator
                var  parser = new SimpleParser(theSignature);
                bool pass   = false;

                parser.EatWhiteSpace();
                _name = parser.ReadToChars("(").Trim();
                parser.Advance();

                bool done = false;
                while (!done)
                {
                    if (parser.Peek() == ')')
                    {
                        parser.Advance();
                        done = true;
                    }
                    else if (parser.Peek() == ':')
                    {
                        parser.Advance();
                        pass = true;
                    }
                    else if (parser.Peek() == '{')
                    {
                        ParamTemplate temp = ReadParam(parser);
                        temp.PassThrough = pass;
                        pass             = false;
                        _param.Add(temp);
                    }
                    else
                    {
                        parser.Advance();
                        if (parser.EOL())
                        {
                            throw new EncogError("Invalid opcode template.");
                        }
                    }
                }

                // get the return type
                parser.EatWhiteSpace();
                if (!parser.LookAhead(":", true))
                {
                    throw new EACompileError("Return type not specified.");
                }
                parser.Advance();
                parser.EatWhiteSpace();
                _returnValue = ReadParam(parser);
            }
        }
        /// <summary>
        ///     Construct a basic template object.
        /// </summary>
        /// <param name="thePrecedence">The precedence.</param>
        /// <param name="theSignature">The opcode signature.</param>
        /// <param name="theType">The opcode type.</param>
        /// <param name="isVariable">True, if this opcode is a variable.</param>
        /// <param name="theDataSize">The data size kept for this opcode.</param>
        /// <param name="theEvaluate">The evaluator delegate.</param>
        /// <param name="theIsPossibleReturnType">The return type delegate.</param>
        /// <param name="theRandomize">The randomizer delegate.</param>
        public BasicTemplate(int thePrecedence, String theSignature,
                             NodeType theType, bool isVariable,
                             int theDataSize,
                             DelEvaluate theEvaluate,
                             DelIsPossibleReturnType theIsPossibleReturnType,
                             DelRandomize theRandomize)
        {
            _precedence = thePrecedence;
            _signature = theSignature;
            _varValue = isVariable;
            _dataSize = theDataSize;
            _nodeType = theType;

            _delEvaluate = theEvaluate;
            _delIsPossibleReturnType = theIsPossibleReturnType;
            _delRandomize = theRandomize;

            if (theSignature.Trim().Equals("("))
            {
                // special case, we add a left-paren for the shunting yard alg.
                _name = theSignature;
                _returnValue = null;
            }
            else
            {
                // non-special case, find the name of the function/operator
                var parser = new SimpleParser(theSignature);
                bool pass = false;

                parser.EatWhiteSpace();
                _name = parser.ReadToChars("(").Trim();
                parser.Advance();

                bool done = false;
                while (!done)
                {
                    if (parser.Peek() == ')')
                    {
                        parser.Advance();
                        done = true;
                    }
                    else if (parser.Peek() == ':')
                    {
                        parser.Advance();
                        pass = true;
                    }
                    else if (parser.Peek() == '{')
                    {
                        ParamTemplate temp = ReadParam(parser);
                        temp.PassThrough = pass;
                        pass = false;
                        _param.Add(temp);
                    }
                    else
                    {
                        parser.Advance();
                        if (parser.EOL())
                        {
                            throw new EncogError("Invalid opcode template.");
                        }
                    }
                }

                // get the return type
                parser.EatWhiteSpace();
                if (!parser.LookAhead(":", true))
                {
                    throw new EACompileError("Return type not specified.");
                }
                parser.Advance();
                parser.EatWhiteSpace();
                _returnValue = ReadParam(parser);
            }
        }