All Downloads are FREE. Search and download functionalities are using the official Maven repository.

astra.ast.visitor.VariableStack Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
package astra.ast.visitor;

import java.util.HashMap;
import java.util.Map;
import java.util.Stack;

public class VariableStack {
	Stack> tables = new Stack>();
	
	public VariableStack() {
		addScope();
	}
	
	public void addVariable(String variable, String type) {
		tables.peek().put(variable, type);
	}
	
	public boolean exists(String variable) {
//		System.out.println("looking for: " + variable);
		int i = tables.size()-1;
		while (i >= 0) {
			Map table = tables.get(i--);
			if (table.containsKey(variable)) {
//				System.out.println("found: " + variable);
				return true;
			}
		}
//		System.out.println("not found: " + variable);
		return false;
	}
	
	public void addScope() {
		tables.push(new HashMap());
	}

	public void removeScope() {
		tables.pop();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy