1	package antlr.collections;
2	
3	import antlr.collections.Stack;
4	import antlr.collections.impl.LList;
5	import java.util.Enumeration;
6	
7	public class LLStackTest {
8	
9	
10		public static void main(String[] args) {
11			// create linked list, but treat it like a Stack
12			LList list = new LList();
13			Stack s = list;
14			s.push(new Integer(3));
15			s.push(new Integer(4));
16			s.push(new Integer(5));
17	
18			// Test height()
19			if ( s.height()!=3 )
20				System.out.println("incorrect height");
21			else
22				System.out.println("correct: height is 3");
23			
24			// Test the enumeration (pretend it's a list again)
25			// Note how different perspectives on the same object are useful.
26			Enumeration e = list.elements();
27			for (; e.hasMoreElements();) {
28				System.out.println(e.nextElement());
29			}
30	
31			// Test pop(): compute 3*(4+5) via "3 4 5 + *" in RPN notation
32			int a = ((Integer)s.pop()).intValue();
33			int b = ((Integer)s.pop()).intValue();
34			s.push( new Integer(a+b) );
35			a = ((Integer)s.pop()).intValue();
36			b = ((Integer)s.pop()).intValue();
37			int result = a * b;
38			System.out.println("result, " + result + ", should be 27");
39			
40			if ( s.height()!=0 ) System.out.println("incorrect stack height");
41			
42			/* Code that is commented here out won't compile since a Stack
43			 * is a limited perspective on a LLStack implementation.
44			 *      Stack s2 = s;
45			 *      s2.includes("Frank");
46			 */
47		}
48	}
49