public override object?Visit(ForInExpression forInExpression)
 {
     StartGraphNode(forInExpression);
     VisitChildren(forInExpression);
     NodeStack.Pop( );
     return(null);
 }
Example #2
0
        private static void ProcessIndex(TokenList tokens, NodeStack nodes)
        {
            nodes.Add(new ArrayIndexNode());
            var childNode = BuildTree(tokens);

            nodes.Add(childNode);
        }
		protected static void AddCloseTag (CompletionDataList completionList, NodeStack stack)
		{
			//FIXME: search forward to see if tag's closed already
			var elements = new List<XElement> ();
			foreach (XObject ob in stack) {
				var el = ob as XElement;
				if (el == null)
					continue;
				if (!el.IsNamed || el.IsClosed)
					return;
				
				if (elements.Count == 0) {
					string name = el.Name.FullName;
					completionList.Add ("/" + name + ">", Gtk.Stock.GoBack,
					                    GettextCatalog.GetString ("Closing tag for '{0}'", name));
				} else {
					foreach (XElement listEl in elements) {
						if (listEl.Name == el.Name)
							return;
					}
					completionList.Add (new XmlMultipleClosingTagCompletionData (el, elements.ToArray ()));
				}
				elements.Add (el);
			}
		}
Example #4
0
        private static Node BuildTree(TokenList tokens)
        {
            var nodes = new NodeStack();

            while (tokens.Any() && !(tokens.Current.EndsExpressionOrParameters || tokens.Current.IsParameterSeparator || tokens.Current.EndsIndex))
            {
                if (tokens.Current.StartsExpressionOrParameters && nodes.LastAdded is MethodNode method)
                {
                    tokens.MoveNext();
                    ProcessParameters(tokens, method);
                }
                else if (tokens.Current.StartsExpressionOrParameters)
                {
                    tokens.MoveNext();
                    ProcessExpression(tokens, nodes);
                }
                else if (tokens.Current.StartsIndex)
                {
                    tokens.MoveNext();
                    ProcessIndex(tokens, nodes);
                }
                else
                {
                    nodes.Add(tokens.Current.CreateNode());
                }

                tokens.MoveNext();
            }
            return(nodes.Pop());
        }
Example #5
0
        private static void ProcessExpression(TokenList tokens, NodeStack nodes)
        {
            var childNode = BuildTree(tokens);

            childNode.KickPrecedenceUp();
            nodes.Add(childNode);
        }
Example #6
0
 /// <summary>
 /// 实现有误:因为遇到!_marked[w]并不能说明就有环
 /// </summary>
 /// <param name="g"></param>
 /// <param name="v"></param>
 private void DFSMy(Digraph g, int v)
 {
     if (HasCycle())
     {
         return;
     }
     _marked[v] = true;
     foreach (var w in g.Adj(v))
     {
         if (!_marked[w])
         {
             _pathTo[w] = v;
             DFS(g, w);
         }
         else
         {
             _cycle = new NodeStack <int>();
             for (int i = v; i != w; i = _pathTo[i])
             {
                 _cycle.Push(i);
                 //将_onStack的意义理解错了
                 _onStack[i] = true;
             }
             _cycle.Push(w);
             _onStack[w] = true;
             _cycle.Push(v);
         }
     }
 }
Example #7
0
        /**
         * Recursive function query function.
         */
        private void query(LimitedPriorityNodeList queue, NodeStack i_nodes, BinaryHierarchicalNode node, LongDescripter768 feature)
        {
            //近傍ノードをスタックに追加
            int sp         = i_nodes.getLength();
            int num_of_min = nearest(node, i_nodes, queue, feature);

            //先頭からnum_of_min個の最小ノードについて再帰探索
            for (int i = 0; i < num_of_min; i++)
            {
                BinaryHierarchicalNode n = i_nodes.getItem(sp + i).node;
                if (n.is_leaf)
                {
                    this.append(n);
                }
                else
                {
                    this.query(queue, i_nodes, n, feature);
                }
            }
            //好成績な近傍ノード1つを取り出して探索する。
            NodeStack.Item item = this.mlist.popSmallest();
            if (item != null)
            {
                BinaryHierarchicalNode n = item.node;
                if (n.is_leaf)
                {
                    this.append(n);
                }
                else
                {
                    this.query(queue, i_nodes, n, feature);
                }
            }
            return;
        }
Example #8
0
        static void Main(string[] args)
        {
            var stack = new NodeStack <string>();

            stack.Push("Tom");
            stack.Push("Alice");
            stack.Push("Bob");
            stack.Push("Kate");

            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();
            string header = stack.Peek();

            Console.WriteLine($"Верхушка стека: {header}");
            Console.WriteLine();

            header = stack.Pop();
            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
        }
        private void StartGraphNode(IAstNode node)
        {
            var graphNode = new Node( )
            {
                Id       = CreateNodeId(node),
                Label    = node.GetType( ).Name,
                Category = "TreeNode"
            };

            graphNode.Properties.Add("SourceInteval", node.Location.ToString( ));

            if (NodeStack.Count > 0)
            {
                var link = new Link( )
                {
                    Source = NodeStack.Peek( ).Id,
                    Target = graphNode.Id
                };

                Graph.Links.Add(link);
            }

            Graph.Nodes.Add(graphNode);
            NodeStack.Push(graphNode);
        }
Example #10
0
        private void UpdateOpenNodes(Context context)
        {
            NodeStack openNodes    = context._openNodes[guid];
            NodeStack tmpNodes     = context._tempNodes[guid];
            NodeStack oldOpenNodes = context._oldOpenNodes[guid];

            while (openNodes.Count > 0 /*&& oldOpenNodes.Count > 0*/)
            {
                if (openNodes.Count > oldOpenNodes.Count)
                {
                    tmpNodes.Push(openNodes.Pop());
                }
                else if (openNodes.Count < oldOpenNodes.Count)
                {
                    oldOpenNodes.Pop()._close(context);
                }
                else if (openNodes.Peek().guid != oldOpenNodes.Peek().guid)
                {
                    tmpNodes.Push(openNodes.Pop());
                    oldOpenNodes.Pop()._close(context);
                }
                else
                {
                    break;
                }
            }
            while (tmpNodes.Count > 0)
            {
                oldOpenNodes.Push(tmpNodes.Pop());
            }
        }
 public override object?Visit(RootNode root)
 {
     StartGraphNode(root);
     VisitChildren(root);
     NodeStack.Pop( );
     return(null);
 }
 public override object?Visit(ConditionalExpression conditionalExpression)
 {
     StartGraphNode(conditionalExpression);
     VisitChildren(conditionalExpression);
     NodeStack.Pop( );
     return(null);
 }
 public override object?Visit(Prototype prototype)
 {
     StartGraphNode(prototype);
     VisitChildren(prototype);
     NodeStack.Pop( );
     return(null);
 }
Example #14
0
 public override int Visit(Prototype prototype)
 {
     StartGraphNode(prototype);
     VisitChildren(prototype);
     NodeStack.Pop( );
     return(0);
 }
Example #15
0
 public override int Visit(RootNode root)
 {
     StartGraphNode(root);
     VisitChildren(root);
     NodeStack.Pop( );
     return(0);
 }
Example #16
0
 public override int Visit(ForInExpression forInExpression)
 {
     StartGraphNode(forInExpression);
     VisitChildren(forInExpression);
     NodeStack.Pop( );
     return(0);
 }
Example #17
0
        public void TestPopException()
        {
            NodeStack <string> stack    = new NodeStack <string>();
            string             actual   = stack.Pop();
            string             excerted = "Стек пуст";

            Assert.AreEqual(excerted, actual);
        }
 public override object?Visit(FunctionDefinition definition)
 {
     StartGraphNode(definition);
     ActiveNode.Label = $"{ActiveNode.Label}: {definition.Name}";
     VisitChildren(definition);
     NodeStack.Pop( );
     return(null);
 }
Example #19
0
        public void Max_Test_Exception()
        {
            NodeStack <int> stack    = new NodeStack <int>();
            int             actual   = stack.Max();
            int             excerted = 0;

            Assert.AreEqual(excerted, actual);
        }
        public override object?Visit(LocalVariableDeclaration localVariableDeclaration)
        {
            StartGraphNode(localVariableDeclaration);
            ActiveNode.Label = $"{ActiveNode.Label}: {localVariableDeclaration.Name}";

            VisitChildren(localVariableDeclaration);
            NodeStack.Pop( );
            return(null);
        }
        public override object?Visit(ParameterDeclaration parameterDeclaration)
        {
            StartGraphNode(parameterDeclaration);
            ActiveNode.Label = $"{ActiveNode.Label}: {parameterDeclaration.Name}";

            VisitChildren(parameterDeclaration);
            NodeStack.Pop( );
            return(null);
        }
		static int GetAttributeIndentDepth (NodeStack nodes)
		{
			var node = nodes.Peek ();
			if (node is XElement && !node.IsEnded)
				return 1;
			if (node is XAttribute)
				return node.IsEnded? 1 : 2;
			return 0;
		}
        public override object?Visit(FunctionCallExpression functionCall)
        {
            StartGraphNode(functionCall);
            ActiveNode.Label = $"{ActiveNode.Label}: {functionCall.FunctionPrototype.Name}";

            VisitChildren(functionCall);
            NodeStack.Pop( );
            return(null);
        }
        public override object?Visit(BinaryOperatorExpression binaryOperator)
        {
            StartGraphNode(binaryOperator);
            ActiveNode.Label = $"{ActiveNode.Label}: {binaryOperator.Name}";

            VisitChildren(binaryOperator);
            NodeStack.Pop( );
            return(null);
        }
        public override object?Visit(VariableReferenceExpression reference)
        {
            StartGraphNode(reference);
            ActiveNode.Label = $"{ActiveNode.Label}: {reference.Name}";

            VisitChildren(reference);
            NodeStack.Pop( );
            return(null);
        }
        public override object?Visit(ConstantExpression constant)
        {
            StartGraphNode(constant);
            ActiveNode.Label = $"{ActiveNode.Label}: {constant.Value}";

            VisitChildren(constant);
            NodeStack.Pop( );
            return(null);
        }
Example #27
0
        public void TestPushOneElement()
        {
            NodeStack <string> stack = new NodeStack <string>();

            stack.Push("Name");
            string actual   = stack.Pop();
            string excerted = "Name";

            Assert.AreEqual(excerted, actual);
        }
Example #28
0
        protected virtual void Visit(ReturnStatement returnStatement)
        {
            // First, dispatch to resolve type of node at deeper level
            Visit((Node)returnStatement);

            if (returnStatement.Value != null)
            {
                var function = NodeStack.OfType <MethodDefinition>().Last();
                returnStatement.Value.TypeInference.ExpectedType = function.ReturnType.ResolveType();
            }
        }
Example #29
0
        private Node GetDeclarationContainer()
        {
            // By default use the method definition as the main declarator container
            var methodDefinition = (Node)NodeStack.OfType <MethodDefinition>().LastOrDefault();

            if (methodDefinition != null)
            {
                return(methodDefinition);
            }

            // Else use the IDeclaration
            return((Node)NodeStack.OfType <IDeclaration>().LastOrDefault());
        }
Example #30
0
        public override Node Visit(ReturnStatement returnStatement)
        {
            // First, dispatch to resolve type of node at deeper level
            base.Visit(returnStatement);

            if (returnStatement.Value != null)
            {
                var function = NodeStack.OfType <MethodDefinition>().Last();
                returnStatement.Value.TypeInference.ExpectedType = function.ReturnType.ResolveType();
            }

            return(returnStatement);
        }
		protected static void AddCloseTag (CompletionDataList completionList, NodeStack stack)
		{
			//FIXME: search forward to see if tag's closed already
			var elements = new List<XElement> ();
			foreach (XObject ob in stack) {
				var el = ob as XElement;
				if (el == null)
					continue;
				if (!el.IsNamed || el.IsClosed)
					return;
				
				if (elements.Count == 0) {
					string name = el.Name.FullName;
					completionList.Add ("/" + name + ">", Gtk.Stock.GoBack,
					                    GettextCatalog.GetString ("Closing tag for '{0}'", name));
				} else {
					foreach (XElement listEl in elements) {
						if (listEl.Name == el.Name)
							return;
					}
					completionList.Add (new XmlMultipleClosingTagCompletionData (el, elements.ToArray ()));
				}
				elements.Add (el);
			}
		}
		static int GetAttributeIndentDepth (NodeStack nodes)
		{
			var node = nodes.Peek ();
			if (node is XElement && !node.IsEnded)
				return 1;
			if (node is XAttribute)
				return node.IsEnded? 1 : 2;
			return 0;
		}
		static int GetElementIndentDepth (NodeStack nodes)
		{
			return nodes.OfType<XElement> ().Count (el => !el.IsClosed);
		}
Example #34
0
 /// <summary>
 /// Constructor for the <c>DocumentReader</c> object. This
 /// makes use of a DOM document to extract events and provide them
 /// to the core framework. All nodes will be extracted from the
 /// document and queued for extraction as they are requested. This
 /// will ignore any comment nodes as they should not be considered.
 /// </summary>
 /// <param name="document">
 /// this is the document that is to be read
 /// </param>
 public DocumentReader(Document document) {
    this.queue = new NodeExtractor(document);
    this.stack = new NodeStack();
    this.stack.push(document);
 }