Package net.sourceforge.chaperon.common

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


              // 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

    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

      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

   *
   * @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

   *
   * @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

        }
      }

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

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

        }
      }

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

        newstates = states;
        states = temp;

        temp = newstatekeys;
View Full Code Here

   *
   * @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

TOP

Related Classes of net.sourceforge.chaperon.common.IntegerList

Copyright © 2018 www.massapicom. 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.