Examples of SymbolList


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

  public SymbolList getFirstSet(Symbol symbol)
  {
    for (int i = 0; i < _symbols.length; i++)
      if (_symbols[i].equals(symbol))
        return _firstsets[i];
    return new SymbolList();
  }
View Full Code Here

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

   *
   * @return List of symbol
   */
  private SymbolList first(Symbol symbol)
  {
    return first(symbol, new SymbolList(true));
  }
View Full Code Here

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

   *
   * @return List of symbol
   */
  private SymbolList first(Symbol symbol, SymbolList visited)
  {
    SymbolList firstset = new SymbolList(true);

    // if the symbol is a terminal symbol
    if (symbol.isTerminal())
    {
      firstset.addSymbol(symbol);
      return firstset;
    }

    if (visited.contains(symbol))
      return firstset;
    else
      visited.addSymbol(symbol);

    //System.out.println("Symbol="+symbol.toString());

    // if is a non terminal symbol
    IntegerList productions = _grammar.getProductionList().getProductionList(symbol);
    SymbolList examined = new SymbolList(true); // List of all examined symbols
    SymbolList productiondefinition, newfirstset;
    boolean foundEMPTY;
    int i, j, k; // index variables
    Symbol newsymbol;

    for (i = 0; i < productions.getSize(); i++)
    {
      productiondefinition = _grammar.getProductionList().getProduction(
        productions.get(i)).getDefinition();
      if (productiondefinition.getSymbolCount() == 0)
      {
        // Symbol for a empty firstset added
        firstset.addSymbol(EmptySymbol.EMPTY);
      }
      else
      {
        // for every symbol in the production
        j = 0;
        do
        {
          foundEMPTY = true;
          newsymbol = productiondefinition.getSymbol(j);
          if (newsymbol.isTerminal())
          {
            // if a terminal symbol
            firstset.addSymbol(newsymbol);
          }
          else if (!newsymbol.equals(symbol))
          {
            // and if a non terminal symbol
            if (!examined.contains(newsymbol))
            {
              newfirstset = first(newsymbol, visited);
              foundEMPTY = newfirstset.contains(EmptySymbol.EMPTY);
              for (k = 0; k < newfirstset.getSymbolCount(); k++)
                if (!newfirstset.getSymbol(k).isEmpty())
                  firstset.addSymbol(newfirstset.getSymbol(k));
              examined.addSymbol(newsymbol);
            }
          }

          j++;
        }
        while ((!newsymbol.isTerminal()) && (foundEMPTY) &&
               (j < productiondefinition.getSymbolCount()) &&
               (!productiondefinition.getSymbol(j - 1).equals(symbol)));
      }
    }
    //System.out.println("Symbol="+symbol.toString()+" beendet");
    return firstset;
  }
View Full Code Here

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

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

    for (int i = 0; i < getProductionCount(); i++)
      list.addSymbolList(getProduction(i).getSymbols());
    return list;
  }
View Full Code Here

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

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

    list.addSymbolList(_tokenlist.getSymbols());
    list.addSymbolList(_productionlist.getSymbols());
    return list;
  }
View Full Code Here

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

      return new SyntaxErrorException("No productions are defined");

    if (_productionlist.getProductionList(_ssymbol).getSize() <= 0)
      return new SyntaxErrorException("Start symbol is not set");

    SymbolList symbols = getSymbols();
    SymbolList tsymbols = symbols.getTerminalSymbols();
    SymbolList ntsymbols = symbols.getNonTerminalSymbols();

    int i;

    // Test, if all terminal symbol are well defined
    for (i = 0; i < tsymbols.getSymbolCount(); i++)
      if (!_tokenlist.contains(tsymbols.getSymbol(i)))
        return new SyntaxErrorException(_tokenlist + "\n" + _productionlist
                                        + "Terminal symbol \""
                                        + tsymbols.getSymbol(i)
                                        + "\" is not defined through a token");

    // Test, if all non terminal symbol are well defined
    for (i = 0; i < ntsymbols.getSymbolCount(); i++)
      if (!_productionlist.contains(ntsymbols.getSymbol(i)))
        return new SyntaxErrorException(_productionlist
                                        + "Nonterminal symbol \""
                                        + ntsymbols.getSymbol(i)
                                        + "\" is not defined through a production");

    return null;
  }
View Full Code Here

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

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

    list.addSymbol(_ntsymbol);
    list.addSymbolList(_definition);
    if (_precedence!=null)
      list.addSymbol(_precedence);
    return list;
  }
View Full Code Here

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

   *
   * @return List of Symbols
   */
  public SymbolList getSymbols()
  {
    SymbolList list = new SymbolList(true);

    for (int i = 0; i < getTokenCount(); i++)
      list.addSymbol(getToken(i).getSymbol());
    return list;
  }
View Full Code Here

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

   *
   * @return Symbol of the next position, otherwise the symbol for an empty list.
   */
  private Symbol getItemNext(int index)
  {
    SymbolList productiondefinition;

    if (positions[index]<((productiondefinition =
                          grammar.getProduction(productions[index]).getDefinition()).getSymbolCount()))
      return productiondefinition.getSymbol(positions[index]);

    return EMPTYLIST;
  }
View Full Code Here

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

  public SymbolSet getNextTerminals()
  {
    SymbolSet set = new SymbolSet();

    SymbolList productiondefinition;
    for (int item = 0; item<elementCount; item++)
      if ((positions[item]<((productiondefinition =
                            grammar.getProduction(productions[item]).getDefinition()).getSymbolCount())) &&
          (productiondefinition.getSymbol(positions[item]) instanceof Terminal))
        set.addSymbol(productiondefinition.getSymbol(positions[item]));

    return set;
  }
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.