public override void Generate(ScriptLoader owner)
        {
            LookaheadStack <INodeEnumerator> nodes  = this.nodes;
            LookaheadStack <uint>            states = this.states;

            int    proc_state = 0;
            object proc_arg   = null;

            INodeEnumerator   ne   = m_enumerator;
            IExceptionHandler ehnd = m_handler;

loop:
            uint state = states.PopOrDefault();

            while (ne.MoveNext())
            {
                INode node = ne.Current;
                if (node.ChildCount == 0)
                {
                    bool goNext;
                    do
                    {
                        goNext = OnGenerate(node.GetToken(), state, ref proc_state, ref proc_arg);

                        if (ehnd.FailCount > 0)
                        {
                            ne.Dispose();
                            while (nodes.Count > 0)
                            {
                                nodes.Pop().Dispose();
                            }

                            return;
                        }
                        else if (proc_state != 0)
                        {
                            proc_arg = OnRequested(ref state, ref proc_state, proc_arg);
                        }

                        // 다음으로 넘어가지 않는다
                        // 반복
                    } while (!goNext);
                }
                else
                {
                    nodes.Push(ne);
                    ne = node.GetEnumerator();
                }
            }

            ne.Dispose();
            if (nodes.Count > 0)
            {
                ne = nodes.Pop();
                goto loop;
            }

            // 끝내기 전에 마무리지어야 한다
        }
Beispiel #2
0
 /// <summary>
 /// For nodes in the Collection, link the DirectedEdges at the node that are
 /// in the result.
 /// This allows clients to link only a subset of nodes in the graph, for
 /// efficiency (because they know that only a subset is of interest).
 /// </summary>
 public static void LinkResultDirectedEdges(NodeCollection nodes)
 {
     for (INodeEnumerator nodeit = nodes.GetEnumerator(); nodeit.MoveNext();)
     {
         Node node = nodeit.Current;
         ((DirectedEdgeStar)node.Edges).LinkResultDirectedEdges();
     }
 }
        public bool MoveNext()
        {
            if (e1 == null) // ok
            {
                if (ne.MoveNext())
                {
                    current = ((TokNode)ne.Current).GetToken();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

loop:
            if (ne.MoveNext())
            {
                if (ne.Current.ChildCount == 0)
                {
                    current = ((TokNode)ne.Current).GetToken();
                    return(true);
                }
                else
                {
                    stack.Push(ne);
                    ne = ne.Current.GetEnumerator();
                }
                goto loop;
            }

            if (stack.Count > 0)
            {
                ne.Dispose();
                ne = stack.Pop();
                goto loop;
            }

            if (save >= 0)
            {
                e1.index = save;
            }

            return(false);
        }
Beispiel #4
0
        public ForExpressionEnumerator(INodeEnumerator ne)
        {
#if DEBUG
            System.Diagnostics.Contracts.Contract.Requires(ne != null);
            System.Diagnostics.Debug.Assert(ne.Current?.GetToken()?.type == TokenType._for);
#endif
            ne.MoveNext();
            // for (. E ; E ; E ) eol E
            // for (. 0 ; 1 ; 2 ; ) eol 3 E

            INode[] nodes = new INode[4];
            INode   temp;
            for (int x = 0; x < 4 && ne.MoveNext();)
            {
                temp = ne.Current;
                TokenType tt = temp.GetToken().type;
                if (tt != TokenType.rparen ||
                    tt != TokenType.EOL)
                {
                    nodes[x++] = temp;
                }
                else if (tt == TokenType.semi_colon)
                {
                    nodes[x++] = EmptyNode.Instance;
                }
            }

            temp     = nodes[1];
            nodes[1] = nodes[3];
            nodes[3] = temp;
#if DEBUG
            while (ne.MoveNext())
            {
                System.Diagnostics.Debug.WriteLine("[ WARN ] !!!!!!!!!!!!!!!!!!! 아직 남아있는 노드 !!!!!!!!!!!!!!!");
            }
#endif

            m_index = -1;
            m_nodes = nodes;
        }
Beispiel #5
0
 private bool IsBoundaryPoint(LineIntersector li, NodeCollection bdyNodes)
 {
     for (INodeEnumerator i = bdyNodes.GetEnumerator(); i.MoveNext();)
     {
         Node       node = i.Current;
         Coordinate pt   = node.Coordinate;
         if (li.IsIntersection(pt))
         {
             return(true);
         }
     }
     return(false);
 }
        public override void Generate(ScriptLoader owner)
        {
            INodeEnumerator ne = m_enumerator;

            Stack <INodeEnumerator> nodes = new Stack <INodeEnumerator>();

            Queue <long> vs = new Queue <long>(2);

            while (ne.MoveNext())
            {
                INode node = ne.Current;
                if (node.ChildCount == 0)
                {
                    Token     t  = node.GetToken();
                    TokenType tt = t.type;
                    if (tt == TokenType.literal_int_4)
                    {
                        vs.Enqueue((int)t.state);
                    }
                    else
                    {
                        long a1 = vs.Dequeue(),
                             a2 = vs.Dequeue();
                        if (tt == TokenType.plus)
                        {
                            vs.Enqueue(a1 + a2);
                        }
                        else if (tt == TokenType.minus)
                        {
                            vs.Enqueue(a1 - a2);
                        }
                        else if (tt == TokenType.multiple)
                        {
                            vs.Enqueue(a1 * a2);
                        }
                        else
                        {
                            vs.Enqueue(a1 / a2);
                        }
                    }
                }
                else
                {
                    nodes.Push(ne);
                    ne = node.GetEnumerator();
                }
            }

            Console.WriteLine(vs.Dequeue());
        }
Beispiel #7
0
        public Coordinate[] GetBoundaryPoints()
        {
            NodeCollection coll = BoundaryNodes;

            Coordinate[] pts = new Coordinate[coll.Count];
            int          i   = 0;

            for (INodeEnumerator it = coll.GetEnumerator(); it.MoveNext();)
            {
                Node node = it.Current;
                pts[i++] = node.Coordinate.Clone();
            }

            return(pts);
        }