/** Generic Queue Class
 *
 * As created by POHL, Java by Disection
 *
 * With a few changes:
 * ADDED: display method
 * for our Language Translator
 * to make it work with Word objects
 * NOTE: we haven't broken it for other objects
 * K.Becker, October 2002
 **/
import java.util.*;

public class MyQueue {
  public Object front() {
    if (head != null)
      return head.data;
    else
      return null;
  }
  public void add(Object value) {
    if (head == null) {
      head = tail = new ListElement(value);
    }
    else {
      tail.next = new ListElement(value);
      tail = tail.next;
    }
    if (Debug.isSet()){   System.out.print("MyQueue::add: " 
			     + value + "\n");
    }

  }
  public Object pop() {  
    Object result = front();
    if (head != null)
      head = head.next;
    return result;
  }
  public boolean empty() { return head == null; }
  
  public void display(){
      ListElement l = head;
      while (l != null) {
          if (l.data instanceof Word) {
              Word w = (Word)l.data;
              w.display();
          }
          else if (l.data instanceof Token) {
              Token t = (Token)l.data;
              if (t.Val() != null)
		  t.Val().display();
	      else
		  System.out.print(t.Symbol());
          }
           else {
              System.out.print(l.data + "\n");
          }
          l = l.next;
      }
  }
  
  private ListElement head = null;
  private ListElement tail = null;
}
