当前位置: 首页>>代码示例>>C#>>正文


C# Group.RemoveAt方法代码示例

本文整理汇总了C#中Group.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# Group.RemoveAt方法的具体用法?C# Group.RemoveAt怎么用?C# Group.RemoveAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Group的用法示例。


在下文中一共展示了Group.RemoveAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseUnaryArtitmetic

        TException ParseUnaryArtitmetic(Group group, int index, char operatorChar)
        {
            if (index + 1 >= group.Count)
                return new TException(this, "Invalid expression term '" + group[index] + "'");

            // Try and get a TNumber value out of the operand
            TType operand = TType.Parse(this, group[index + 1]);
            if (operand is TException) return operand as TException;

            TNumber number = operand as TNumber;
            if (number == null)
            {
                TVariable variable = operand as TVariable;
                if (variable == null)
                    return new TException(this, "Failed to perform unary arithmetic operation",
                        "only numbers can be used");

                number = variable.Value as TNumber;
                if (number == null)
                    return new TException(this, "Failed to perform unary arithmetic operation",
                        "only numbers can be used");
            }

            if (operatorChar == '-') group[index] = number.ToNegative();
            else group[index] = number;
            group.RemoveAt(index + 1);

            return null;
        }
开发者ID:supermaximo93,项目名称:Toast-Prototype-Interpreter,代码行数:29,代码来源:Interpreter.cs

示例2: ParseGroup

        /// <summary>
        /// Interprets Toast code that has been split into symbols, contained in a Interpreter.Group
        /// </summary>
        /// <param name="group">The group to Parse.</param>
        /// <returns>The result of the statement or expression contained in the group.</returns>
        public TType ParseGroup(Group group)
        {
            if (group.Count == 0) return new TArgumentList();

            // Parse any keywords first
            string firstSymbolStr = group[0] as string;
            if (firstSymbolStr != null)
            {
                if (firstSymbolStr == TType.DIRECTIVE_CHARACTER.ToString()) return ParseDirectiveGroup(group);

                switch (firstSymbolStr)
                {
                    case "let": return ParseAssignmentGroup(group);
                    case "if": return ParseIfGroup(group);
                    case "while": return ParseWhileGroup(group);
                    case "begin": return ParseBegin();
                    case "end": return new TException(this, "Unexpected keyword 'end'");
                    case "else": return new TException(this, "Unexpected keyword 'else'");
                    case "for": break;
                }
            }

            // Recursively iterate through the groups
            for (int i = 0; i < group.Count; ++i)
            {
                Group nextGroup = group[i] as Group;
                if (nextGroup != null)
                {
                    TType value = ParseGroup(nextGroup);
                    if (value is TException) return value;
                    group[i] = value;
                }

                // Attempt a function call
                TType argument = group[i] as TType;
                if ((argument != null) && (i - 1 >= 0))
                {
                    bool functionCalled = false;
                    TType functionReturnValue = null;

                    // If the symbol before the argument is a TFunction call it
                    TType value = TType.Parse(this, group[i - 1]);
                    TFunction function = value as TFunction;
                    if (function != null)
                    {
                        functionReturnValue = function.Call(this, argument);
                        functionCalled = true;
                    }
                    else
                    {
                        // If it's a TBlock, execute it
                        TBlock block = value as TBlock;
                        if (block != null)
                        {
                            bool exitFromFunction, breakUsed;
                            functionReturnValue = block.Execute(this, out exitFromFunction, out breakUsed);
                            if (exitFromFunction) return functionReturnValue;
                            functionCalled = true;
                        }
                        else
                        {
                            // If it's a TVariable, and it's value is a TFunction or TBlock, execute it
                            TVariable variable = value as TVariable;
                            if (variable != null)
                            {
                                function = variable.Value as TFunction;
                                if (function != null)
                                {
                                    functionReturnValue = function.Call(this, argument);
                                    functionCalled = true;
                                }
                                else
                                {
                                    block = variable.Value as TBlock;
                                    if (block != null)
                                    {
                                        bool exitFromFunction, breakUsed;
                                        functionReturnValue = block.Execute(this, out exitFromFunction, out breakUsed);
                                        if (exitFromFunction) return functionReturnValue;
                                        functionCalled = true;
                                    }
                                }
                            }
                        }
                    }

                    if (functionCalled)
                    {
                        // Replace the function and argument in the group with the returned value
                        if (functionReturnValue is TException) return functionReturnValue;
                        group[i - 1] = functionReturnValue;
                        group.RemoveAt(i);
                        --i;
                    }
                }
//.........这里部分代码省略.........
开发者ID:supermaximo93,项目名称:Toast-Prototype-Interpreter,代码行数:101,代码来源:Interpreter.cs

示例3: ParseReferencesOfGroup

        /// <summary>
        /// Parses a group, searching for any reference and dereference operators. Operators and operands are
        /// replaced with the reference/dereferenced value.
        /// </summary>
        /// <param name="group">The group to parse.</param>
        /// <param name="limit">The index of the group to parse up to. Used by the ParseAssignmentGroup method.</param>
        /// <returns>A TException on failure, otherwise null.</returns>
        TException ParseReferencesOfGroup(Group group, int limit = -1)
        {
            int limitToUse = limit < 0 ? group.Count - 1 : limit;
            int index;

            while (true)
            {
                // Search from right to left for the first reference or dereference character
                int refIndex = group.LastIndexOf(TType.REFERENCE_CHARACTER.ToString(), limitToUse),
                    derefIndex = group.LastIndexOf(TType.DEREFERENCE_CHARACTER.ToString(), limitToUse);

                char character; // Used so we know what operation we're carrying out later
                if (refIndex < 0)
                {
                    index = derefIndex;
                    character = TType.DEREFERENCE_CHARACTER;
                }
                else if (derefIndex < 0)
                {
                    index = refIndex;
                    character = TType.REFERENCE_CHARACTER;
                }
                else
                {
                    if (refIndex > derefIndex)
                    {
                        index = refIndex;
                        character = TType.REFERENCE_CHARACTER;
                    }
                    else
                    {
                        index = derefIndex;
                        character = TType.DEREFERENCE_CHARACTER;
                    }
                }
                if (index < 0) break;

                if (index + 1 > group.Count)
                    return new TException(this, "Invalid expression term '" + character + "' at end of statement");

                // If the operand is not a variable, return a TException (can't dereference values)
                TType variable = TType.Parse(this, group[index + 1]);
                if (variable is TException) return variable as TException;
                if (!(variable is TVariable))
                {
                    if (character == TType.REFERENCE_CHARACTER)
                        return new TException(this,
                            "Attempted creation of reference to value", "expected variable identifier");
                    else
                        return new TException(this, "Attempted dereference of value", "expected variable identifier");
                }

                if (character == TType.REFERENCE_CHARACTER) group[index] = new TVariable("reference", variable);
                else
                {
                    group[index] = ((TVariable)variable).Value;
                    if (!(group[index] is TVariable) && !(group[index] is TFunction))
                        return new TException(this,
                            "Dereference of value type variable", "expected reference");
                }
                group.RemoveAt(index + 1);
                limitToUse = limit < 0 ? group.Count - 1 : limit;
            }

            return null;
        }
开发者ID:supermaximo93,项目名称:Toast-Prototype-Interpreter,代码行数:73,代码来源:Interpreter.cs


注:本文中的Group.RemoveAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。