Examples of SymbolList


Examples of instantbach.data.SymbolList

     */
    public ProgressionPanel(MainFrame parent, SymbolList availableSymbols) {
        this.parent = parent;
        this.buttonList = new ArrayList<SymbolButton>();

        this.progression = new SymbolList();

        this.musicPanel = new MusicPanel(this);

        this.setLayout(new BorderLayout());

View Full Code Here

Examples of instantbach.data.SymbolList

        //create a graph of rules for chord progressions
        LoadProgressionGraph loader = new LoadProgressionGraph(this);
        graph = loader.createProgressionGraph(graphLocation);

        //create a list of available chords
        availableSymbols = new SymbolList();

        availableSymbols.add("ii","ii");
        availableSymbols.add("iii","iii");
        availableSymbols.add("IV","IV");
        availableSymbols.add("V","V");
View Full Code Here

Examples of instantbach.data.SymbolList

    /**
     * Generates a random progression and attempts to voice it
     */
    public synchronized void generateAndVoiceProgression() {

        SymbolList progression = new SymbolList();

        ArrayList<String> identifiers = new ArrayList<String>();

        //add the root as the last chord
        identifiers.add("I");

        //add the dominant as the second to last
        identifiers.add("7V");

        //get the current vertex (for the cadence)
        Vertex currentVertex = graph.getVertex("7V");

        for (int i = 0; i < 9; i++) {

            //get the adjacent edges to the current vertex
            LinkedList<Edge> currentEdges = currentVertex.getAdjacent();
            int numToChoose = currentEdges.size();

            int randomNumber = (int) (Math.random() * numToChoose + 0);

            //get a random edge
            Edge randomEdge = currentEdges.get(randomNumber);

            //get the destination of the random edge
            currentVertex = randomEdge.getDestination();

            String identifier = currentVertex.getName();
            identifiers.add(identifier);
            //returnVector.add(current.name);
        }

        //create a progression using the given identifiers
        for (int i = identifiers.size() - 1; i >= 0; i--) {
            //get the symbol for the current identifier
            String id = identifiers.get(i);
            Symbol symbol = availableSymbols.getSymbolByIdentifier(id);

            //add this symbol to the current progression
            progression.add(symbol);
        }

        //pass this progression to be voiced
        this.voiceProgression(progression);

View Full Code Here

Examples of net.sourceforge.chaperon.grammar.symbol.SymbolList

   *
   * @return Symbol of the next position
   */
  private Symbol getItemNext(int index)
  {
    SymbolList productiondefinition;

    if (_positions[index] < ((productiondefinition =
        _grammar.getProductionList().getProduction(_productions[index]).getDefinition()).getSymbolCount()))
      return productiondefinition.getSymbol(_positions[index]);
    return EmptySymbol.EMPTY;
  }
View Full Code Here

Examples of net.sourceforge.chaperon.grammar.symbol.SymbolList

  public ItemSet closure()
  {
    ItemSet J = new ItemSet(_grammar, _firstsets, this); // J=I

    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);
View Full Code Here

Examples of net.sourceforge.chaperon.grammar.symbol.SymbolList

   *
   * @return List of symbols
   */
  public SymbolList getReduceSymbols()
  {
    SymbolList reducesymbols = new SymbolList(true);

    for (int i = 0; i < _elementCount; i++)
    {
      if (getItemNext(i).isEmpty()) // for all A=u^ and all symbols in FOLLOW(A)
        reducesymbols.addSymbol(_lookaheads[i]);
    }
    return reducesymbols;
  }
View Full Code Here

Examples of net.sourceforge.chaperon.grammar.symbol.SymbolList

   * @return Content of the itemset
   */
  public String toString()
  {
    StringBuffer buffer = new StringBuffer();
    SymbolList list;

    for (int i = 0; i < _elementCount; i++)
    {
      buffer.append(_grammar.getProductionList().getProduction(_productions[i]).getSymbol());
      buffer.append("->");
      list = (SymbolList) _grammar.getProductionList().getProduction(_productions[i]).getDefinition();

      for (int j = 0; j < list.getSymbolCount(); j++)
      {
        if (j == _positions[i])
          buffer.append(".");

        buffer.append(list.getSymbol(j) + " ");
      }

      if (_positions[i] == list.getSymbolCount())
        buffer.append(".");

      if (_lookaheads[i] != null)
        buffer.append("," + _lookaheads[i]);

View Full Code Here

Examples of net.sourceforge.chaperon.grammar.symbol.SymbolList

          }
        }
      }


    SymbolList symbols;
    do
    {
      mustrepeat = false;

      for (int i = 0; i < C.getSize(); i++)
        if (changedState.get(i) != 0)
        {
          changedState.set(i, 0);
          I = C.get(i);

          if (_logger!=null)
          {
            _logger.debug("Inspecting state "+i+"\n"+I);
          }

          symbols = I.getShiftSymbols();
         
          for (int j = 0; j < symbols.getSymbolCount(); j++)
          {
            J = I.gotoX(symbols.getSymbol(j));
            index = I.getTransition(symbols.getSymbol(j));
            changed = C.get(index).add(J); // if the found state change

            if (changed)
            {
              if (index < changedState.getSize())
                changedState.set(index, 1);
              else
                changedState.add(1);

              if (index <= i) // if J before I, and J
                // was changed then must the loop repeat
                mustrepeat = true;
            }

            if (_logger!=null)
              _logger.debug("State "+i+" + "+symbols.getSymbol(j)+" -> State "+index);
          }
        }

    }
    while (mustrepeat);                        // Repeat till no state changed
View Full Code Here

Examples of net.sourceforge.chaperon.grammar.symbol.SymbolList

    // for all itemsets I in collection C
    ItemSet I;
    Token token;
    IntegerList reduceproductions;
    int highestproduction, priority;
    SymbolList shiftsymbols, reducesymbols;

    for (i = 0; i < _C.getSize(); i++)
    {
      I = _C.get(i);

      shiftsymbols = I.getShiftSymbols(); // Transition symbols for shift actions
      reducesymbols = I.getReduceSymbols(); // Lookahead symbols for reduce actions

      for (j = 0; j < _tsymbols.getSymbolCount(); j++)
      {
        reduceproductions = I.getReduceProductions(_tsymbols.getSymbol(j));
        priority = -1;
        highestproduction = -1;
        for (k = 0; k < reduceproductions.getSize(); k++)
        {
          /*if ((_grammar.getProductionList().getProduction(reduceproductions.get(k)).getSymbol().equals(
                      _grammar.getStartSymbol())) && (_tsymbols.getSymbol(j).equals(endsymbol)))
            _table.setAcceptAction(i, j, reduceproductions.get(k));*/

          if (_grammar.getProductionList().getProduction(reduceproductions.get(k)).getPriority()
                  > priority)
          {
            highestproduction = reduceproductions.get(k);
            priority = _grammar.getProductionList().getProduction(highestproduction).getPriority();
          }
        }

        //if (!_table.isAcceptAction(i, j))

        if (shiftsymbols.contains(_tsymbols.getSymbol(j)))
        {
          if (reducesymbols.contains(_tsymbols.getSymbol(j)))
          {
            token = _grammar.getTokenList().getToken(_tsymbols.getSymbol(j));

            if (token.getPriority() > priority)
            {
              _table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));

              if (_logger!=null)
                _logger.warn("Shift/Reduce Conflict State "+i+" between"+
                             System.getProperty(("line.separator"))+
                             token+System.getProperty(("line.separator"))+
                             _grammar.getProductionList().getProduction(highestproduction)+
                             System.getProperty(("line.separator"))+
                             "The parser will shift");
            }
            else if (token.getPriority() < priority)
            {
              /*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
                      _grammar.getStartSymbol()))
                   && (_tsymbols.getSymbol(j).equals(endsymbol)))
                _table.setAcceptAction(i, j, highestproduction);
              else*/
                _table.setReduceAction(i, j, highestproduction);

              if (_logger!=null)   
                _logger.warn("Shift/Reduce Conflict State "+i+" between"+
                             System.getProperty(("line.separator"))+
                             token+System.getProperty(("line.separator"))+
                             _grammar.getProductionList().getProduction(highestproduction)+
                             System.getProperty(("line.separator"))+
                             "The parser will reduce");
            }
            else
            {
              if (token.getAssociativity()==Associativity.RIGHT)
              {
                _table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));

                if (_logger!=null)   
                  _logger.warn("Shift/Reduce Conflict State "+i+" between"+
                               System.getProperty(("line.separator"))+
                               token+System.getProperty(("line.separator"))+
                               _grammar.getProductionList().getProduction(highestproduction)+
                               System.getProperty(("line.separator"))+
                               "The parser will shift");
              }
              else if (token.getAssociativity()==Associativity.LEFT)
              {
                /*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
                        _grammar.getStartSymbol()))
                    && (_tsymbols.getSymbol(j).equals(endsymbol)))
                  _table.setAcceptAction(i, j, highestproduction);
                else*/
                  _table.setReduceAction(i, j, highestproduction);

                if (_logger!=null)   
                  _logger.warn("Shift/Reduce Conflict State "+i+" between"+
                               System.getProperty(("line.separator"))+
                               token+System.getProperty(("line.separator"))+
                               _grammar.getProductionList().getProduction(highestproduction)+
                               System.getProperty(("line.separator"))+
                               "The parser will reduce");
              }
              else
              {
                _table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));

                if (_logger!=null)   
                  _logger.info("Shift/Reduce Conflict State "+i+" between"+
                               System.getProperty(("line.separator"))+
                               token+System.getProperty(("line.separator"))+
                               _grammar.getProductionList().getProduction(highestproduction)+
                               System.getProperty(("line.separator"))+
                               "The parser will shift");
                _conflicts.add(new ShiftReduceConflict(I, _tsymbols.getSymbol(j)));
              }
            }
          }
          else
            _table.setShiftAction(i, j, I.getTransition(_tsymbols.getSymbol(j)));
        }
        else if (reducesymbols.contains(_tsymbols.getSymbol(j)))
        {
          /*if ((_grammar.getProductionList().getProduction(highestproduction).getSymbol().equals(
                  _grammar.getStartSymbol()))
               && (_tsymbols.getSymbol(j).equals(endsymbol)))
            _table.setAcceptAction(i, j, highestproduction);
          else*/
            _table.setReduceAction(i, j, highestproduction);
        }

        for (k = 0; k < reduceproductions.getSize(); k++)
          if ((_grammar.getProductionList().getProduction(reduceproductions.get(k)).getSymbol().equals(
                      _grammar.getStartSymbol())) && (_tsymbols.getSymbol(j).equals(endsymbol)))
            _table.setAcceptAction(i, j, reduceproductions.get(k));
      }

      for (j = 0; j < _ntsymbols.getSymbolCount(); j++)
        if (shiftsymbols.contains(_ntsymbols.getSymbol(j)))
          _table.setTransition(i, j, I.getTransition(_ntsymbols.getSymbol(j)));
    }

    /*_table.setAcceptAction(_C.get(0).getTransition(_grammar.getStartSymbol()),
                           _ntsymbols.indexOf(_grammar.getStartSymbol()), 0);*/
 
View Full Code Here

Examples of net.sourceforge.chaperon.grammar.symbol.SymbolList

  public FirstSets(Grammar grammar, Logger logger)
  {
    _grammar = grammar;
    enableLogging(logger);

    SymbolList usedsymbols = grammar.getSymbols();

    _symbols = new Symbol[usedsymbols.getSymbolCount()];
    _firstsets = new SymbolList[usedsymbols.getSymbolCount()];
    for (int i = 0; i < usedsymbols.getSymbolCount(); i++)
    {
      if (_logger!=null)
        _logger.debug("Generating first set for "+usedsymbols.getSymbol(i).getName());
      _symbols[i] = usedsymbols.getSymbol(i);
      _firstsets[i] = first(_symbols[i]);
    }
  }
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.