package ga050426;

class Symbol{
	String name, type;
	int value, seg;
	Symbol prec, next;
	
	Symbol(String name, int value, int seg, String type, Symbol prec, Symbol next){
		this.name=name;
		this.value=value;
		this.seg=seg;
		this.type=type;
		this.prec=prec;
		this.next=next;
	}
}

public class Symbols {
	Symbol head, tail;
	
	public void enter(String name, int value, int seg, String type){
		if (tail != null)
			tail = tail.next = new Symbol(name, value, seg, type, tail, null);
		else
			tail = head = new Symbol(name, value, seg, type, tail, null);
	}
	Symbols(){}
	public static Symbols instance = new Symbols();
	public int getStartValue(){
		for (Symbol cur = head; cur != null; cur = cur.next) {
			if(cur.name.toLowerCase().equals("start"))return cur.value;
			}
		return -1;
	}
	
	public String toString() {
		StringBuffer buf = new StringBuffer(String
				.format("#Symbols (dec)%n"));
		for (Symbol cur = head; cur != null; cur = cur.next) {
			buf.append(String.format(" %s  %d  %d  %s %n", cur.name, cur.value, cur.seg, cur.type));
		}
		return new String(buf);
	}
}
