Package net.sourceforge.chaperon.model.extended

Examples of net.sourceforge.chaperon.model.extended.PatternSet


    return false;
  }

  public PatternSet getNextPattern()
  {
    PatternSet pattern = new PatternSet();

    for (Item item = first; item!=null; item = item.next)
      if (item.position==Item.SHIFT)
        pattern.addPattern(item.pattern);

    return pattern;
  }
View Full Code Here


    return pattern;
  }

  public PatternSet getPreviousPattern()
  {
    PatternSet pattern = new PatternSet();

    for (Item item = first; item!=null; item = item.next)
      if ((item.position==Item.GOTO) && (item.pattern!=null))
        pattern.addPattern(item.pattern);

    return pattern;
  }
View Full Code Here

    {
      //State state = getState(i);
      //System.out.println("\nState "+i+"\n"+state);
      SortedCharSet limits = new SortedCharSet();
      StringSet nonterminals = new StringSet();
      PatternSet gotoPattern = new PatternSet();

      for (Item item = state.first; item!=null; item = item.next)
      {
        if (item.position==Item.SHIFT)
        {
          if (item.pattern.getSymbol()!=null)
            nonterminals.addString(item.pattern.getSymbol());

          limits.addChar(item.pattern.getLimits());
        }
        else if (item.position==Item.GOTO)
          gotoPattern.addPattern(item.pattern);

        limits.addChar(item.lookahead.getLimits());
      }

//      System.out.println("limits="+limits);
//      System.out.println("nonterminals="+nonterminals);
//      System.out.println("gotoPattern="+gotoPattern);
      // for all other characters from the begin
      if ((limits.getCharCount()>=1) && (limits.getChar(0)>'\u0000'))
      {
        addShiftAction(state, '\u0000', (char)(limits.getChar(0)-1));
        addReduceAction(state, '\u0000', (char)(limits.getChar(0)-1));
      }

      // for each character
      for (int j = 0; j<limits.getCharCount(); j++)
      {
        if ((j>0) && ((limits.getChar(j)-limits.getChar(j-1))>1))
        {
          addShiftAction(state, (char)(limits.getChar(j-1)+1), (char)(limits.getChar(j)-1));
          addReduceAction(state, (char)(limits.getChar(j-1)+1), (char)(limits.getChar(j)-1));
        }

        addShiftAction(state, limits.getChar(j), limits.getChar(j));
        addReduceAction(state, limits.getChar(j), limits.getChar(j));
      }

      // for all other characters to the end
      if (limits.getCharCount()>=1)
      {
        addShiftAction(state, (char)(limits.getChar(limits.getCharCount()-1)+1), '\u4000');
        addReduceAction(state, (char)(limits.getChar(limits.getCharCount()-1)+1), '\u4000');
      }

      // for universal characters
      if (limits.getCharCount()==0)
      {
        addShiftAction(state, '\u0000', '\u4000');
        addReduceAction(state, '\u0000', '\u4000');
      }

      // for each nonterminal
      for (int j = 0; j<nonterminals.getStringCount(); j++)
        addGotoAction(state, nonterminals.getString(j));

      for (PatternIterator pattern = gotoPattern.getPattern(); pattern.hasNext();)
        addGotoAction(state, pattern.next());

      addReduceAction(state);
    }
  }
View Full Code Here

  private State getStartState()
  {
    if (grammar.getStartSymbol()==null)
      throw new IllegalArgumentException("Start symbol is not defined");

    PatternSet firstSet = grammar.getFirstSet();

    System.out.println("firstset = "+firstSet);

    State state = new State(grammar);

    for (PatternIterator pattern = firstSet.getPattern(); pattern.hasNext();)
    {
      Pattern firstPattern = pattern.next();
      Item item =
        new Item(((Definition)definitions.get(firstPattern)).getSymbol(), firstPattern, Item.SHIFT,
                 null);
View Full Code Here

        String symbol = ((Element)item.pattern).getSymbol();
        System.out.println("pattern="+item.pattern);

        Definition definition = ((Definition)definitions.get(item.pattern));
        PatternSet firstSet = grammar.getFirstSet(symbol);
        for (PatternIterator pattern = firstSet.getPattern(); pattern.hasNext();)
        {
          Pattern firstPattern = pattern.next();

          //Definition definition = ((Definition)definitions.get(firstSet.getPattern(l)));
          if (definition.getLastSet().contains(item.pattern))
View Full Code Here

TOP

Related Classes of net.sourceforge.chaperon.model.extended.PatternSet

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.