Examples of IntegerList


Examples of net.sourceforge.chaperon.common.IntegerList

   * @return Start point for the calculation.
   */
  private ItemSet getStartItemSet()
  {
    ItemSet I = new ItemSet(grammar, firstsets);
    IntegerList startlist = grammar.getProductionList(grammar.getStartSymbol());

    for (int i = 0; i<startlist.getCount(); i++)
      I.addItem(startlist.get(i), 0, EOF);

    return I.closure();
  }
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

              // otherwise is b FIRST(a)
              b.addSymbol(J.lookaheads[i]);

            // list of all productions B
            IntegerList productionlist = grammar.getProductionList(symbol);

            // for alle productions B
            for (int j = 0; j<productionlist.getCount(); j++)
            {
              // if J doesn't contain [B=^w,b] , should it added
              for (int k = 0; k<b.getSymbolCount(); k++)
                changed |= J.addItem(productionlist.get(j), 0, b.getSymbol(k));
            }
          }
        }
      }
    }
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

    tsymbols = symbols.getTerminals();
    ntsymbols = symbols.getNonterminals();

    // C = closure( [S'=^S,EOF] )
    IntegerList changedState = new IntegerList()// 0=not changed 1=changed

    addItemSet(getStartItemSet());
    changedState.add(CHANGED);

    boolean mustrepeat = false;
    for (int i = 0; i<getItemSetCount(); i++)
    {
      changedState.set(i, NOTCHANGED);

      ItemSet I = getItemSet(i);

      // J = goto(I,X) add to C, for all nonterminal and terminal symbols X
      // for the non terminal symbols
      SymbolSet nextnonterminals = I.getNextNonterminals();
      for (int j = 0; j<nextnonterminals.getSymbolCount(); j++)
      {
        ItemSet J = I.jump(nextnonterminals.getSymbol(j));

        if (!J.isEmpty())
        {
          int index = indexOfCore(J);
          if (index<0// if C doesn't contain J
          {
            index = addItemSet(J);

            changedState.add(CHANGED);
          }
          else  // otherwise the found state extends through J
          {
            if (getItemSet(index).addItemSet(J))  // if the found state change
            {
              if (index<changedState.getCount())
                changedState.set(index, CHANGED);
              else
                changedState.add(CHANGED);

              if (index<=i// if J before I, and J


                // was changed then must the loop repeat
                mustrepeat = true;
            }
          }

          I.setTransition(nextnonterminals.getSymbol(j), index)// stores the transition for this symbol
        }
      }

      // and for the terminal symbols
      SymbolSet nextterminals = I.getNextTerminals();
      for (int j = 0; j<nextterminals.getSymbolCount(); j++)
      {
        ItemSet J = I.jump(nextterminals.getSymbol(j));

        if (!J.isEmpty())
        {
          int index = indexOfCore(J);
          if (index<0// if C doesn't contain J
          {
            index = addItemSet(J);

            changedState.add(CHANGED);
          }
          else  // otherwise the found state extends through J
          {
            if (getItemSet(index).addItemSet(J))  // if the found state change
            {
              if (index<changedState.getCount())
                changedState.set(index, CHANGED);
              else
                changedState.add(CHANGED);

              if (index<=i// if J before I, and J


                // was changed then must the loop repeat
                mustrepeat = true;
            }
          }

          I.setTransition(nextterminals.getSymbol(j), index)// stores the transition for this symbol
        }
      }
    }

    do
    {
      mustrepeat = false;

      for (int i = 0; i<getItemSetCount(); i++)
        if (changedState.get(i)==CHANGED)
        {
          changedState.set(i, NOTCHANGED);

          ItemSet I = getItemSet(i);

          symbols = I.getShiftSymbols();

          for (int j = 0; j<symbols.getSymbolCount(); j++)
          {
            ItemSet J = I.jump(symbols.getSymbol(j));
            int index = I.getTransition(symbols.getSymbol(j));

            if (getItemSet(index).addItemSet(J))  // if the found state change
            {
              if (index<changedState.getCount())
                changedState.set(index, CHANGED);
              else
                changedState.add(CHANGED);

              if (index<=i// if J before I, and J


                // was changed then must the loop repeat
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

      return firstset;
    else
      visited.addSymbol(symbol);

    // if is a non terminal symbol
    IntegerList productions = grammar.getProductionList(symbol);
    SymbolSet examined = new SymbolSet()// List of all examined symbols

    for (int i = 0; i<productions.getCount(); i++)
    {
      SymbolList productiondefinition = grammar.getProduction(productions.get(i)).getDefinition();
      if (productiondefinition.getSymbolCount()==0)

        // Symbol for a empty firstset added
        firstset.addSymbol(EMPTYLIST);
      else
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

   *
   * @return List of indices from found productions
   */
  public IntegerList getProductionList(Symbol ntsymbol)
  {
    IntegerList list = new IntegerList();
    int i;
   
    for (i = 0; i < getProductionCount(); i++)
    {
      if (getProduction(i).getSymbol().equals(ntsymbol))
        list.add(i);
    }
    return list;
  }
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

   *
   * @return List of indices from the productions
   */
  public IntegerList getProductionList(Symbol ntsymbol)
  {
    IntegerList list = new IntegerList();
    int i;

    for (i = 0; i<getProductionCount(); i++)
    {
      if (getProduction(i).getSymbol().equals(ntsymbol))
        list.add(i);
    }

    return list;
  }
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

        }
      }

      if (states.isEmpty())
      {
        IntegerList temp = newstates;
        newstates = states;
        states = temp;

        temp = newstatekeys;
        newstatekeys = statekeys;
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

        }
      }

      if (states.isEmpty())
      {
        IntegerList temp = newstates;

        newstates = states;
        states = temp;

        temp = newstatekeys;
View Full Code Here

Examples of net.sourceforge.chaperon.common.IntegerList

   *
   * @return List of indices from the productions
   */
  public IntegerList getProductionList(Symbol ntsymbol)
  {
    IntegerList list = new IntegerList();
    int i;

    for (i = 0; i<getProductionCount(); i++)
    {
      if (getProduction(i).getSymbol().equals(ntsymbol))
        list.add(i);
    }
    return list;
  }
View Full Code Here

Examples of net.sourceforge.chaperon.helpers.IntegerList

    int i, j, k;                                       // Index variables
    SymbolList productiondefinition;
    SymbolList b = new SymbolList();
    SymbolList b2 = new SymbolList(true);
    IntegerList productionlist;
    Symbol symbol;

    // for every item in itemset I
    for (i = 0; i < J._elementCount; i++)
    {
      productiondefinition = _grammar.getProductionList().getProduction(J._productions[i]).getDefinition();

      // and not A=XYZ^
      if (J._positions[i] < productiondefinition.getSymbolCount())
      {
        symbol = productiondefinition.getSymbol(J._positions[i]); // A=X ^symbol Z

        // for every item [A=u^Bv,a] in J and production B=w in G
        if (!symbol.isTerminal())
        {
          int pos = J._positions[i] + 1;              // for the FIRST set from (va)

          b.clear();

          // if [A=u^Bv,a]
          if (pos < productiondefinition.getSymbolCount())
          {
            // then is b the list of alle terminal symbols from FIRST(va)
            do
            {
              if (productiondefinition.getSymbol(pos).isTerminal())
              {
                b2.clear();
                b2.addSymbol(productiondefinition.getSymbol(pos));
              }
              else
                b2 = _firstsets.getFirstSet(productiondefinition.getSymbol(pos));
              b.addSymbolList(b2);
              pos++;
            }
            while ((b2.contains(EmptySymbol.EMPTY)) && (pos < productiondefinition.getSymbolCount()));

            if (b.contains(EmptySymbol.EMPTY))
              b.addSymbol(J._lookaheads[i]);

            b.removeSymbol(EmptySymbol.EMPTY);
          }
          else if (pos >= productiondefinition.getSymbolCount())
            // otherwise is b FIRST(a)
            b.addSymbol(J._lookaheads[i]);

          // list of all productions B
          productionlist = _grammar.getProductionList().getProductionList(symbol);

          // for alle productions B
          for (j = 0; j < productionlist.getSize(); j++)
          {
            // if J doesn't contain [B=^w,b] , should it added
            for (k = 0; k < b.getSymbolCount(); k++)
            {
              if (!J.containsItem(productionlist.get(j), 0, b.getSymbol(k)))
                J.addItem(productionlist.get(j), 0, b.getSymbol(k));
            }
          }
        }
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.