Ejemplo n.º 1
0
  /**
   * @param line - linha com a definicao
   * @param level - nivel do symbolo
   */
  public SymbolArray(String line, Memory mem, int level) throws LanguageException {
    super(Symbol.ARRAY, true);
    this.level = level;
    IteratorArray it = new IteratorArray(line);
    String mod = Symbol.getDefAlter(line);
    String type = Symbol.getDefType(line);
    String nameVar = Symbol.getDefName(it.getNext());

    // nome da variavel
    name = nameVar + getOriginalDims(line);

    int dimension = Integer.valueOf(it.getNext()); // numero de dimensoes

    data = new Vector<SymbolData>(dimension);

    nameVar = nameVar + it.getUnprocessed();

    nameVar = mod + " " + type + " " + nameVar;
    for (int i = 0; i < dimension; i++) {
      SymbolData var =
          Memory.makeNewSymbol(nameVar + Symbol.iniArray + i + Symbol.finArray, mem, level);
      var.normalizeName();
      data.add(var);
    }

    //        objectValue = data;

    // constructor
  }
Ejemplo n.º 2
0
  @Override
  public String toString() {
    StringBuffer txt = new StringBuffer();
    txt.append("\n NAME: " + name);
    txt.append("\n TYPE: " + this.type);
    for (SymbolData s : getData()) {
      txt.append("\n|" + s.toString() + "|\t");
    }

    return txt.toString();
  }
Ejemplo n.º 3
0
  // O nome da variavel
  public SymbolArray(SymbolArray model, String varName, int level) throws LanguageException {
    super(Symbol.ARRAY, true);
    this.level = level;
    IteratorArray it = new IteratorArray(varName);
    name = varName;
    int dimension = model.getSize();
    data = new Vector<SymbolData>(dimension); // construir um vector

    for (int i = 0; i < dimension; i++) {
      SymbolData var =
          Memory.cloneDataSymbol(
              model.data.get(i), name + Symbol.iniArray + i + Symbol.finArray, level);
      var.normalizeName();
      data.add(var);
    }
    // objectValue = data;
  }
Ejemplo n.º 4
0
  public SymbolArray(LineTokens line, Memory mem, int level) throws Exception {
    super(Symbol.ARRAY, true);
    IteratorElemTokens it = new IteratorElemTokens(line);
    // tipo de dados
    Token dataType;
    Token dataAlter = it.next().getElement(0);
    // tipo de varivel array
    if (dataAlter.kw == Keyword.VARIAVEL || dataAlter.kw == Keyword.CONSTANTE) {
      dataType = it.next().getElement(0);
    } else {
      dataType = dataAlter;
      dataAlter = new Token(Keyword.VARIAVEL);
    }
    // nome do array
    Token dataName = it.next().getElement(0);
    // elimiar o [
    LineTokens firstDim = it.next();
    firstDim.removeFirst();
    firstDim.removeLast();
    // alterar isto para suportar o calculo
    int dimension = (int) firstDim.getElement(0).nval;
    // eliminar os ]
    // --------------------outras Dimensões---------------------------------
    LineTokens dims = new LineTokens();
    while (it.hasNext()
        && it.peek().getElement(0).ttype != Keyword.ASSIGN
        && it.peek().getElement(0).ttype != Keyword.COMMA) {
      dims.addLine(it.next());
      // --------------valores--------------------------------------
    }
    LineTokens values = new LineTokens();
    if (it.hasNext() && it.peek().getElement(0).ttype == Keyword.ASSIGN) {
      // eliminar o assign
      it.next();
      values.addLine(it.next());
    }
    // --------outras variaveis---------------------------------
    LineTokens newVars = new LineTokens();
    if (it.hasNext() && it.peek().getElement(0).ttype == Keyword.COMMA) {
      // eliminar a virgula
      it.next();
      newVars.addLine(it.getUnprocessed());
    }

    data = new Vector<SymbolData>(dimension);
    // copia da memoria
    //        Memory tmpMem = new Memory(mem);
    for (int i = 0; i < dimension; i++) {
      LineTokens varArray = new LineTokens();
      varArray.addTokens(dataAlter);
      varArray.addTokens(dataType);
      Token nameVar = new Token(dataName.sval + Symbol.iniArray + i + Symbol.finArray);
      varArray.addTokens(nameVar);
      varArray.addLine(dims);
      SymbolData var = MakeSymbol.NewSymbol(varArray, mem, level);
      var.normalizeName();
      data.add(var);
    }
    this.name = dataName.sval;
    this.level = level;
    this.setValue(values);
  }