public Boolean ownsBlock(String name) { for (Block child : children) { if (child.getName().equals(name)) return true; } return false; }
@Override public String toString() { String str = ""; for (Statement statement : statements) str += statement.toString(); for (Block child : children) str += child.getName() + "[" + child.toString() + "]"; return str; }
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 + "'."); }
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 Block getBlock(String name) { for (Block child : children) { if (child.getName().equals(name)) return child; } Block block; for (Block child : children) { if ((block = child.getBlock(name)) != null) return block; } return null; }
public Boolean isFather(Block block) { for (Block b : children) if (b.equals(block)) return true; return false; }