Package org.antlr.misc

Examples of org.antlr.misc.IntervalSet


  public Object clone() {
    Label l;
    try {
      l = (Label)super.clone();
      l.label = this.label;
            l.labelSet = new IntervalSet();
      l.labelSet.addAll(this.labelSet);
    }
    catch (CloneNotSupportedException e) {
      throw new InternalError();
    }
View Full Code Here


*/
public class LookaheadSet {
  public IntervalSet tokenTypeSet;

  public LookaheadSet() {
    tokenTypeSet = new IntervalSet();
  }
View Full Code Here

            smax = label.getAtom();
          }
        }
      }
      else if ( label.isSet() ) {
        IntervalSet labels = (IntervalSet)label.getSet();
        int lmin = labels.getMinElement();
        // if valid char (don't do EOF) and less than current min
        if ( lmin<smin && lmin>=Label.MIN_CHAR_VALUE ) {
          smin = labels.getMinElement();
        }
        if ( labels.getMaxElement()>smax ) {
          smax = labels.getMaxElement();
        }
      }
    }

    if ( smax<0 ) {
View Full Code Here

        int labelIndex = label.getAtom()-smin; // offset from 0
        stateTransitions.set(labelIndex,
                   Utils.integer(edge.target.stateNumber));
      }
      else if ( label.isSet() ) {
        IntervalSet labels = (IntervalSet)label.getSet();
        int[] atoms = labels.toArray();
        for (int a = 0; a < atoms.length; a++) {
          // set the transition if the label is valid (don't do EOF)
          if ( atoms[a]>=Label.MIN_CHAR_VALUE ) {
            int labelIndex = atoms[a]-smin; // offset from 0
            stateTransitions.set(labelIndex,
View Full Code Here

          // eof[s] points to accept state
          eof.set(s.stateNumber, Utils.integer(edge.target.stateNumber));
        }
      }
      else if ( label.isSet() ) {
        IntervalSet labels = (IntervalSet)label.getSet();
        int[] atoms = labels.toArray();
        for (int a = 0; a < atoms.length; a++) {
          if ( atoms[a]==Label.EOT ) {
            // eot[s] points to accept state
            eot.set(s.stateNumber, Utils.integer(edge.target.stateNumber));
          }
View Full Code Here

    this.decisionNumber = decisionNumber;
    this.decisionNFAStartState = decisionStartState;
    initAltRelatedInfo();
    unreachableAlts = null;
    for (Map.Entry<IntervalSet, List<Integer>> entry : edgeMap.entrySet()) {
      IntervalSet edge = entry.getKey();
      List<Integer> alts = entry.getValue();
      Collections.sort(alts); // make sure alts are attempted in order
      //System.out.println(edge+" -> "+alts);
      DFAState s = newState();
      s.k = 1;
View Full Code Here

  }

  protected static Integer getTokenType(Label label) {
    if ( label.isSet() ) {
      // pick random element of set
      IntervalSet typeSet = (IntervalSet)label.getSet();
      int randomIndex = random.nextInt(typeSet.size());
      return typeSet.get(randomIndex);
    }
    else {
      return Utils.integer(label.getAtom());
    }
    //System.out.println(t0.label.toString(g));
View Full Code Here

    List<IntervalSet> disjoint = makeEdgeSetsDisjoint(edges);
    //System.out.println("disjoint="+disjoint);

    MultiMap<IntervalSet, Integer> edgeMap = new MultiMap<IntervalSet, Integer>();
    for (int i = 0; i < disjoint.size(); i++) {
      IntervalSet ds = disjoint.get(i);
      for (int alt = 1; alt < altLook.length; alt++) {
        LookaheadSet look = altLook[alt];
        if ( !ds.and(look.tokenTypeSet).isNil() ) {
          edgeMap.map(ds, alt);
        }
      }
    }
    //System.out.println("edge map: "+edgeMap);
View Full Code Here

  protected List<IntervalSet> makeEdgeSetsDisjoint(List<IntervalSet> edges) {
    OrderedHashSet<IntervalSet> disjointSets = new OrderedHashSet<IntervalSet>();
    // walk each incoming edge label/set and add to disjoint set
    int numEdges = edges.size();
    for (int e = 0; e < numEdges; e++) {
      IntervalSet t = edges.get(e);
      if ( disjointSets.contains(t) ) { // exact set present
        continue;
      }

      // compare t with set i for disjointness
      IntervalSet remainder = t; // remainder starts out as whole set to add
      int numDisjointElements = disjointSets.size();
      for (int i = 0; i < numDisjointElements; i++) {
        IntervalSet s_i = disjointSets.get(i);

        if ( t.and(s_i).isNil() ) { // nothing in common
          continue;
        }
        //System.out.println(label+" collides with "+rl);

        // 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
        IntervalSet intersection = s_i.and(t);
        disjointSets.set(i, intersection);

        // Compute s_i-t to see what is in current set and not in incoming
        IntervalSet 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.
          disjointSets.add(existingMinusNewElements);
        }
View Full Code Here

    /** Public default constructor used by TestRig */
    public TestIntervalSet() {
    }

    @Test public void testSingleElement() throws Exception {
        IntervalSet s = IntervalSet.of(99);
        String expecting = "99";
        assertEquals(s.toString(), expecting);
    }
View Full Code Here

TOP

Related Classes of org.antlr.misc.IntervalSet

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.