Inheritance: Expression, ISubDeclarator
Exemple #1
0
        /// <summary>
        /// Evaluates a function declaration expression
        /// </summary>
        /// <returns></returns>
        private FunctionExpression EvaluateFunction()
        {
            FunctionExpression retVal = null;
            int current = Index;

            if (LookAhead("FUNCTION"))
            {
                List <Parameter> parameters = new List <Parameter>();
                bool             cont       = true;
                Match("FUNCTION");
                while (cont)
                {
                    string id = Identifier();
                    if (id != null)
                    {
                        skipWhiteSpaces();
                        Match(":");
                        skipWhiteSpaces();
                        string typeName = Identifier(true);
                        if (typeName != null)
                        {
                            Parameter parameter = (Parameter)Generated.acceptor.getFactory().createParameter();
                            parameter.Name     = id;
                            parameter.TypeName = typeName;
                            parameters.Add(parameter);
                        }
                        else
                        {
                            throw new ParseErrorException("Parameter type expected");
                        }
                    }
                    else
                    {
                        throw new ParseErrorException("Parameter identifier expected");
                    }

                    cont = LookAhead(",");
                    if (cont)
                    {
                        Match(",");
                    }
                }

                skipWhiteSpaces();
                Match("=>");
                Expression expression = Expression(0);
                if (expression != null)
                {
                    retVal = new FunctionExpression(Root, parameters, expression);
                }
                else
                {
                    throw new ParseErrorException("Function expression expected");
                }
            }

            return(retVal);
        }
 /// <summary>
 ///     Visits a Function expression
 /// </summary>
 /// <param name="functionExpression"></param>
 protected virtual void VisitFunctionExpression(FunctionExpression functionExpression)
 {
     if (functionExpression.Expression != null)
     {
         VisitExpression(functionExpression.Expression);
     }
 }
        /// <summary>
        ///     Evaluates a function declaration expression
        /// </summary>
        /// <returns></returns>
        private FunctionExpression EvaluateFunction()
        {
            FunctionExpression retVal = null;

            SkipWhiteSpaces();
            int start = Index;
            if (LookAhead("FUNCTION"))
            {
                List<Parameter> parameters = new List<Parameter>();
                bool cont = true;
                Match("FUNCTION");
                while (cont)
                {
                    string id = Identifier();
                    if (id != null)
                    {
                        SkipWhiteSpaces();
                        Match(":");
                        SkipWhiteSpaces();
                        string typeName = Identifier(true);
                        if (typeName != null)
                        {
                            Parameter parameter = (Parameter) acceptor.getFactory().createParameter();
                            parameter.Name = id;
                            parameter.TypeName = typeName;
                            parameters.Add(parameter);
                        }
                        else
                        {
                            throw new ParseErrorException("Parameter type expected", Index, Buffer);
                        }
                    }
                    else
                    {
                        throw new ParseErrorException("Parameter identifier expected", Index, Buffer);
                    }

                    cont = LookAhead(",");
                    if (cont)
                    {
                        Match(",");
                    }
                }

                SkipWhiteSpaces();
                string assignOp = LookAhead(AssignOps);
                if (assignOp != null)
                {
                    Match(assignOp);
                    Expression expression = Expression(0);
                    if (expression != null)
                    {
                        retVal = new FunctionExpression(Root, RootLog, parameters, expression, start, Index);
                    }
                    else
                    {
                        throw new ParseErrorException("Function expression expected", Index, Buffer);
                    }
                }
                else
                {
                    throw new ParseErrorException("=> or <- expected", Index, Buffer);
                }
            }

            return retVal;
        }
        /// <summary>
        /// Evaluates a function declaration expression
        /// </summary>
        /// <returns></returns>
        private FunctionExpression EvaluateFunction()
        {
            FunctionExpression retVal = null;
            int current = Index;

            if (LookAhead("FUNCTION"))
            {
                List<Parameter> parameters = new List<Parameter>();
                bool cont = true;
                Match("FUNCTION");
                while (cont)
                {
                    string id = Identifier();
                    if (id != null)
                    {
                        skipWhiteSpaces();
                        Match(":");
                        skipWhiteSpaces();
                        string typeName = Identifier(true);
                        if (typeName != null)
                        {
                            Parameter parameter = (Parameter)Generated.acceptor.getFactory().createParameter();
                            parameter.Name = id;
                            parameter.TypeName = typeName;
                            parameters.Add(parameter);
                        }
                        else
                        {
                            throw new ParseErrorException("Parameter type expected");
                        }
                    }
                    else
                    {
                        throw new ParseErrorException("Parameter identifier expected");
                    }

                    cont = LookAhead(",");
                    if (cont)
                    {
                        Match(",");
                    }
                }

                skipWhiteSpaces();
                Match("=>");
                Expression expression = Expression(0);
                if (expression != null)
                {
                    retVal = new FunctionExpression(Root, parameters, expression);
                }
                else
                {
                    throw new ParseErrorException("Function expression expected");
                }
            }

            return retVal;
        }
 /// <summary>
 ///     Visits a Function expression
 /// </summary>
 /// <param name="functionExpression"></param>
 protected virtual void VisitFunctionExpression(FunctionExpression functionExpression)
 {
     if (functionExpression.Expression != null)
     {
         VisitInterpreterTreeNode(functionExpression.Expression);
     }
 }
        /// <summary>
        /// Provides the speed parameter of the function
        /// </summary>
        /// <param name="functionExpression"></param>
        /// <returns></returns>
        public Parameter GetSpeedParameter(FunctionExpression functionExpression)
        {
            Parameter retVal = null;

            Parameter distance = GetDistanceParameter(functionExpression);
            foreach (Parameter p in functionExpression.Parameters)
            {
                if (IsDouble(p) && p != distance)
                {
                    retVal = p;
                    break;
                }
            }

            return retVal;
        }
        /// <summary>
        /// Provides the distance parameter of the function expression
        /// </summary>
        /// <param name="functionExpression"></param>
        /// <returns></returns>
        public Parameter GetDistanceParameter(FunctionExpression functionExpression)
        {
            Parameter retVal = null;

            foreach (Parameter p in functionExpression.Parameters)
            {
                if (IsDouble(p))
                {
                    retVal = p;
                    break;
                }
            }

            return retVal;
        }