public Boolean variableExists(String name) { Block block = this; while (block.getParent() != null) { for (Variable var : block.getVariables()) { if (var.getName().equals(name)) return true; } block = block.getParent(); } return false; }
public Variable getVariable(String name) throws SyntaxException { Block block = this; while (block != null) { for (Variable var : block.getVariables()) { if (var.getName().equals(name)) return var; } block = block.getParent(); } throw new SyntaxException("No variable named '" + name + "'."); }