Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
  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 + "'.");
  }