Package org.antlr.misc

Examples of org.antlr.misc.IntSet


    if ( transition0.label.isAtom() ) {
      int atom = transition0.label.getAtom();
      return new LookaheadSet(atom);
    }
    if ( transition0.label.isSet() ) {
      IntSet sl = transition0.label.getSet();
      return new LookaheadSet(sl);
    }

    // compute FIRST of transition 0
    LookaheadSet tset = null;
View Full Code Here


   */
  public DFAState reach(DFAState d, Label label) {
    DFAState labelDFATarget = dfa.newState();
    // for each NFA state in d, add in target states for label
    int intLabel = label.getAtom();
    IntSet setLabel = label.getSet();
    Iterator iter = d.getNFAConfigurations().iterator();
    while ( iter.hasNext() ) {
      NFAConfiguration c = (NFAConfiguration)iter.next();
      if ( c.resolved || c.resolveWithPredicate ) {
        continue; // the conflict resolver indicates we must leave alone
View Full Code Here

        "reachableLabels="+reachableLabels.toString());
        */
    if ( reachableLabels.contains(label) ) { // exact label present
            return;
        }
        IntSet t = label.getSet();
        IntSet remainder = t; // remainder starts out as whole set to add
        int n = reachableLabels.size(); // only look at initial elements
        // walk the existing list looking for the collision
        for (int i=0; i<n; i++) {
            Label rl = (Label)reachableLabels.get(i);
            /*
            if ( label.equals(rl) ) {
                // OPTIMIZATION:
                // exact label already here, just return; previous addition
                // would have made everything unique/disjoint
                return;
            }
            */
            IntSet s_i = rl.getSet();
            IntSet intersection = s_i.and(t);
            /*
      System.out.println("comparing ["+i+"]: "+label.toString(dfa.nfa.grammar)+" & "+
                    rl.toString(dfa.nfa.grammar)+"="+
                    intersection.toString(dfa.nfa.grammar));
            */
      if ( intersection.isNil() ) {
                continue;
            }

            // For any (s_i, t) with s_i&t!=nil replace with (s_i-t, s_i&t)
            // (ignoring s_i-t if nil; don't put in list)

            // Replace existing s_i with intersection since we
            // know that will always be a non nil character class
            reachableLabels.set(i, new Label(intersection));

            // Compute s_i-t to see what is in current set and not in incoming
            IntSet existingMinusNewElements = s_i.subtract(t);
      //System.out.println(s_i+"-"+t+"="+existingMinusNewElements);
            if ( !existingMinusNewElements.isNil() ) {
                // found a new character class, add to the end (doesn't affect
                // outer loop duration due to n computation a priori.
                Label newLabel = new Label(existingMinusNewElements);
                reachableLabels.add(newLabel);
            }
View Full Code Here

  }

  protected static Integer getTokenType(Label label) {
    if ( label.isSet() ) {
      // pick random element of set
      IntSet typeSet = label.getSet();
      List typeList = typeSet.toList();
      int randomIndex = random.nextInt(typeList.size());
      return (Integer)typeList.get(randomIndex);
    }
    else {
      return Utils.integer(label.getAtom());
View Full Code Here

   */
  public IntSet getAllCharValues() {
    if ( charVocabulary!=null ) {
      return charVocabulary;
    }
    IntSet allChar = IntervalSet.of(Label.MIN_CHAR_VALUE, getMaxCharValue());
    return allChar;
  }
View Full Code Here

     *  from MIN_TOKEN_TYPE to last valid token type or char value.
     */
    public IntSet complement(IntSet set) {
        //System.out.println("complement "+set.toString(this));
        //System.out.println("vocabulary "+getTokenTypes().toString(this));
        IntSet c = set.complement(getTokenTypes());
        //System.out.println("result="+c.toString(this));
        return c;
    }
View Full Code Here

  {
    Rule r = getRule(ruleName);
    if ( r==null ) {
      return null;
    }
    IntSet elements = null;
    //System.out.println("parsed tree: "+r.tree.toStringTree());
      elements = nfabuilder.setRule(r.tree);
    //System.out.println("elements="+elements);
    return elements;
  }
View Full Code Here

        return LookaheadSet.EOF();
      }
      return new LookaheadSet(atom);
    }
    if ( transition0.label.isSet() ) {
      IntSet sl = transition0.label.getSet();
      LookaheadSet laSet = new LookaheadSet(sl);
      if ( laSet.member(Label.EOF) ) {
        laSet.remove(Label.EOF);
        laSet.hasEOF = true;
      }
View Full Code Here

    if ( transition0.label.isAtom() ) {
      int atom = transition0.label.getAtom();
      return new LookaheadSet(atom);
    }
    if ( transition0.label.isSet() ) {
      IntSet sl = transition0.label.getSet();
      return new LookaheadSet(sl);
    }

    // compute FIRST of transition 0
    LookaheadSet tset = null;
View Full Code Here

  public boolean member(int a) {
    return tokenTypeSet.member(a);
  }

  public LookaheadSet intersection(LookaheadSet s) {
    IntSet i = this.tokenTypeSet.and(s.tokenTypeSet);
    LookaheadSet intersection = new LookaheadSet(i);
    return intersection;
  }
View Full Code Here

TOP

Related Classes of org.antlr.misc.IntSet

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.