Ejemplo n.º 1
0
        private static IEnumerable <PostParseMethod> getMethodItem(PostParseItem parseExpression)
        {
            switch (parseExpression.ItemType)
            {
            case PPItemType.Variable:

                break;

            case PPItemType.String:
                break;

            case PPItemType.Operation:
                foreach (var d in getMethodItem(((PostParseOperation)parseExpression).Left))
                {
                    yield return(d);
                }
                foreach (var d in getMethodItem(((PostParseOperation)parseExpression).Right))
                {
                    yield return(d);
                }
                break;

            case PPItemType.Statement:
                foreach (var d in ((PostParseStatement)parseExpression).Items)
                {
                    foreach (var postParseItem in getMethodItem(d))
                    {
                        yield return(postParseItem);
                    }
                }
                break;

            case PPItemType.Method:
                foreach (var p in ((PostParseMethod)parseExpression).Params)
                {
                    foreach (var postParseMethod in getMethodItem(p))
                    {
                        yield return(postParseMethod);
                    }
                }


                yield return((PostParseMethod)parseExpression);

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        private void tryToNeeds(PostParseItem item, bool isLeft, AssureSplitStacks assurer)
        {
            switch (item.ItemType)
            {
                case PPItemType.Variable:
                    if (((PostParseVariable)item).Type == VariableType.Stack)
                    {
                        if (isLeft)
                            assurer.Resolve(((PostParseVariable)item).Index, ((PostParseVariable)item));
                        else
                            assurer.Need(((PostParseVariable)item).Index, ((PostParseVariable)item));

                    }
                    break;
                case PPItemType.String:
                    return;

                case PPItemType.Operation:

                    var op = ((PostParseOperation)item);
                    tryToNeeds(op.Left, false, assurer);
                    tryToNeeds(op.Right, false, assurer);

                    break;
                case PPItemType.Statement:
                    var st = ((PostParseStatement)item);
                    foreach (var postParseItem in st.Items)
                    {
                        tryToNeeds(postParseItem, false, assurer);
                    }
                    break;
                case PPItemType.Method:
                    var wst = ((PostParseMethod)item);
                    foreach (var a in wst.Params)
                        tryToNeeds(a, false, assurer);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            return;

            ;
        }
Ejemplo n.º 3
0
        private PostParseItem tryToFix(PostParseItem right, Dictionary<int, PostParseItem> stacks)
        {
            switch (right.ItemType)
            {
                case PPItemType.Variable:
                    if (((PostParseVariable)right).Type == VariableType.Stack)
                    {
                        return stacks[((PostParseVariable)right).Index];
                    }
                    return right;
                    break;
                case PPItemType.String:
                    return right;
                    break;
                case PPItemType.Operation:

                    var op = ((PostParseOperation)right);
                    return new PostParseString(string.Format(op.Wrap, tryToFix(op.Left, stacks), tryToFix(op.Right, stacks)));
                    break;
                case PPItemType.Statement:
                    var st = ((PostParseStatement)right);
                    return new PostParseString(string.Format(st.Wrap, st.Items.Select(a => tryToFix(a, stacks)).ToArray()));
                    break;
                case PPItemType.Method:
                    var wst = ((PostParseMethod)right);
                    PostParseItem[] itm = new PostParseItem[wst.Params.Length];
                    for (int index = 0; index < wst.Params.Length; index++)
                    {
                        itm[index] = tryToFix(wst.Params[index], stacks);
                    }
                    wst.Params = itm;
                    return wst;
                    // return new PostParseString(right.ToString());
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 4
0
        private void doThings(List<PostParseExpression> item2)
        {
            Dictionary<int, PostParseItem> stacks = new Dictionary<int, PostParseItem>();
            for (int index = 0; index < item2.Count; index++)
            {
                PostParseExpression postParseExpression = item2[index];
                switch (postParseExpression.ExpressionType)
                {
                    case PPExpressionType.Statement:
                        var st = ((PostParseStatement)postParseExpression);
                        item2[index] = new PostParseString(string.Format(st.Wrap, st.Items.Select(a => tryToFix(a, stacks)).ToArray()));
                        break;
                    case PPExpressionType.Set:
                        if (((PostParseSet)postParseExpression).Left is PostParseVariable)
                        {
                            var pps = (PostParseVariable)((PostParseSet)postParseExpression).Left;
                            switch (pps.Type)
                            {
                                case VariableType.Stack:

                                    if (!((PostParseSet)postParseExpression).OkayToRemove)
                                    {
                                        ((PostParseSet)postParseExpression).Right =
                                            tryToFix(((PostParseSet)postParseExpression).Right, stacks);
                                        ((PostParseSet)postParseExpression).MarkForRemoval = false;
                                        if (stacks.ContainsKey(pps.Index))
                                            stacks.Remove(pps.Index);
                                        string gc;
                                        stacks.Add(pps.Index, new PostParseString(gc = GetNext()));
                                        ((PostParseSet)postParseExpression).Left = new PostParseString("var " + gc);
                                    }
                                    else
                                    {

                                        var fm = tryToFix(((PostParseSet)postParseExpression).Right, stacks);

                                        if (stacks.ContainsKey(pps.Index))
                                            stacks.Remove(pps.Index);
                                        stacks.Add(pps.Index, fm);
                                        ((PostParseSet)postParseExpression).Right = fm;
                                        postParseExpression.MarkForRemoval = true;

                                        if (((PostParseSet)postParseExpression).RemoveLeft)
                                        {
                                            ((PostParseExpression)fm).endOfLine = true;
                                            item2[index] = (PostParseExpression)fm;
                                        }

                                    }

                                    break;
                                case VariableType.Special:
                                    ((PostParseSet)postParseExpression).Right = tryToFix(((PostParseSet)postParseExpression).Right, stacks);
                                    break;
                                case VariableType.Variable: ((PostParseSet)postParseExpression).Right = tryToFix(((PostParseSet)postParseExpression).Right, stacks);
                                    break;

                                default:
                                    throw new ArgumentOutOfRangeException();
                            }

                        }
                        break;
                    case PPExpressionType.String:
                        break;
                    case PPExpressionType.Method:
                        var wst = ((PostParseMethod)postParseExpression);
                        PostParseItem[] itm = new PostParseItem[wst.Params.Length];
                        for (int i = 0; i < wst.Params.Length; i++)
                        {
                            itm[i] = tryToFix(wst.Params[i], stacks);
                        }
                        wst.Params = itm;

                        //  item2[index] = new PostParseString(wst.ToString());

                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
        }
Ejemplo n.º 5
0
 public PostParseMethod(string cleanMethodName, PostParseItem[] @params, int numofv)
 {
     TotalMethodName = cleanMethodName;
     Params = @params;
     NumOfVariables = numofv;
 }
Ejemplo n.º 6
0
 public PostParseSet(PostParseItem left, PostParseItem right, bool okayToRemove)
 {
     Left = left;
     Right = right;
     OkayToRemove = okayToRemove;
 }
Ejemplo n.º 7
0
 public PostParseOperation(PostParseItem left, PostParseItem right, string wrap)
 {
     Left = left;
     Right = right;
     Wrap = wrap;
 }
Ejemplo n.º 8
0
        private static IEnumerable<PostParseMethod> getMethodItem(PostParseItem parseExpression)
        {
            switch (parseExpression.ItemType)
            {
                case PPItemType.Variable:

                    break;
                case PPItemType.String:
                    break;
                case PPItemType.Operation:
                    foreach (var d in getMethodItem(((PostParseOperation)parseExpression).Left)) yield return d;
                    foreach (var d in getMethodItem(((PostParseOperation)parseExpression).Right)) yield return d;
                    break;
                case PPItemType.Statement:
                    foreach (var d in ((PostParseStatement)parseExpression).Items) foreach (var postParseItem in getMethodItem(d)) yield return postParseItem;
                    break;
                case PPItemType.Method:
                    foreach (var p in ((PostParseMethod)parseExpression).Params)
                    {
                        foreach (var postParseMethod in getMethodItem(p))
                        {
                            yield return postParseMethod;
                        }
                    }

                    yield return ((PostParseMethod)parseExpression);

                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 9
0
 public PostParseSet(PostParseItem left, PostParseItem right, bool okayToRemove)
 {
     Left         = left;
     Right        = right;
     OkayToRemove = okayToRemove;
 }
Ejemplo n.º 10
0
 public PostParseOperation(PostParseItem left, PostParseItem right, string wrap)
 {
     Left  = left;
     Right = right;
     Wrap  = wrap;
 }