Ejemplo n.º 1
0
        public void testPushPopFromEOF()
        {
            // ^(101 ^(102 103) ^(104 105) ^(106 107) 108 109)
            // stream has 9 real + 8 nav nodes
            // Sequence of types: 101 DN 102 DN 103 UP 104 DN 105 UP 106 DN 107 UP 108 109 UP
            ITree r0 = new CommonTree(new CommonToken(101));
            ITree r1 = new CommonTree(new CommonToken(102));

            r1.AddChild(new CommonTree(new CommonToken(103)));
            r0.AddChild(r1);
            ITree r2 = new CommonTree(new CommonToken(104));

            r2.AddChild(new CommonTree(new CommonToken(105)));
            r0.AddChild(r2);
            ITree r3 = new CommonTree(new CommonToken(106));

            r3.AddChild(new CommonTree(new CommonToken(107)));
            r0.AddChild(r3);
            r0.AddChild(new CommonTree(new CommonToken(108)));
            r0.AddChild(new CommonTree(new CommonToken(109)));

            CommonTreeNodeStream stream = new CommonTreeNodeStream(r0);

            while (stream.LA(1) != Token.EOF)
            {
                stream.Consume();
            }
            int indexOf102 = 2;
            int indexOf104 = 6;

            Assert.AreEqual(Token.EOF, ((ITree)stream.LT(1)).Type);

            // CALL 102
            stream.Push(indexOf102);
            Assert.AreEqual(102, ((ITree)stream.LT(1)).Type);
            stream.Consume();             // consume 102
            Assert.AreEqual(Token.DOWN, ((ITree)stream.LT(1)).Type);
            stream.Consume();             // consume DN
            Assert.AreEqual(103, ((ITree)stream.LT(1)).Type);
            stream.Consume();             // consume 103
            Assert.AreEqual(Token.UP, ((ITree)stream.LT(1)).Type);
            // RETURN (to empty stack)
            stream.Pop();
            Assert.AreEqual(Token.EOF, ((ITree)stream.LT(1)).Type);

            // CALL 104
            stream.Push(indexOf104);
            Assert.AreEqual(104, ((ITree)stream.LT(1)).Type);
            stream.Consume();             // consume 102
            Assert.AreEqual(Token.DOWN, ((ITree)stream.LT(1)).Type);
            stream.Consume();             // consume DN
            Assert.AreEqual(105, ((ITree)stream.LT(1)).Type);
            stream.Consume();             // consume 103
            Assert.AreEqual(Token.UP, ((ITree)stream.LT(1)).Type);
            // RETURN (to empty stack)
            stream.Pop();
            Assert.AreEqual(Token.EOF, ((ITree)stream.LT(1)).Type);
        }
Ejemplo n.º 2
0
		public void testPushPopFromEOF()
		{
			// ^(101 ^(102 103) ^(104 105) ^(106 107) 108 109)
			// stream has 9 real + 8 nav nodes
			// Sequence of types: 101 DN 102 DN 103 UP 104 DN 105 UP 106 DN 107 UP 108 109 UP
			ITree r0 = new CommonTree(new CommonToken(101));
			ITree r1 = new CommonTree(new CommonToken(102));
			r1.AddChild(new CommonTree(new CommonToken(103)));
			r0.AddChild(r1);
			ITree r2 = new CommonTree(new CommonToken(104));
			r2.AddChild(new CommonTree(new CommonToken(105)));
			r0.AddChild(r2);
			ITree r3 = new CommonTree(new CommonToken(106));
			r3.AddChild(new CommonTree(new CommonToken(107)));
			r0.AddChild(r3);
			r0.AddChild(new CommonTree(new CommonToken(108)));
			r0.AddChild(new CommonTree(new CommonToken(109)));

			CommonTreeNodeStream stream = new CommonTreeNodeStream(r0);

			while (stream.LA(1) != Token.EOF)
			{
				stream.Consume();
			}
			int indexOf102 = 2;
			int indexOf104 = 6;
			Assert.AreEqual(Token.EOF, ((ITree)stream.LT(1)).Type);

			// CALL 102
			stream.Push(indexOf102);
			Assert.AreEqual(102, ((ITree)stream.LT(1)).Type);
			stream.Consume(); // consume 102
			Assert.AreEqual(Token.DOWN, ((ITree)stream.LT(1)).Type);
			stream.Consume(); // consume DN
			Assert.AreEqual(103, ((ITree)stream.LT(1)).Type);
			stream.Consume(); // consume 103
			Assert.AreEqual(Token.UP, ((ITree)stream.LT(1)).Type);
			// RETURN (to empty stack)
			stream.Pop();
			Assert.AreEqual(Token.EOF, ((ITree)stream.LT(1)).Type);

			// CALL 104
			stream.Push(indexOf104);
			Assert.AreEqual(104, ((ITree)stream.LT(1)).Type);
			stream.Consume(); // consume 102
			Assert.AreEqual(Token.DOWN, ((ITree)stream.LT(1)).Type);
			stream.Consume(); // consume DN
			Assert.AreEqual(105, ((ITree)stream.LT(1)).Type);
			stream.Consume(); // consume 103
			Assert.AreEqual(Token.UP, ((ITree)stream.LT(1)).Type);
			// RETURN (to empty stack)
			stream.Pop();
			Assert.AreEqual(Token.EOF, ((ITree)stream.LT(1)).Type);
		}