Package org.antlr.analysis

Examples of org.antlr.analysis.LookaheadSet


        /*
        System.out.println("compare "+i+", "+j+": "+
                   altLook[i].toString(this)+" with "+
                   altLook[j].toString(this));
        */
        LookaheadSet collision = altLook[i].intersection(altLook[j]);
        if ( !collision.isNil() ) {
          //System.out.println("collision (non-LL(1)): "+collision.toString(this));
          decisionIsLL_1 = false;
          break outer;
        }
      }
    }

    boolean foundConfoundingPredicate =
      ll1Analyzer.detectConfoundingPredicates(decisionStartState);
    if ( decisionIsLL_1 && !foundConfoundingPredicate ) {
      // build an LL(1) optimized DFA with edge for each altLook[i]
      if ( NFAToDFAConverter.debug ) {
        System.out.println("decision "+decision+" is simple LL(1)");
      }
      DFA lookaheadDFA = new LL1DFA(decision, decisionStartState, altLook);
      setLookaheadDFA(decision, lookaheadDFA);
      updateLineColumnToLookaheadDFAMap(lookaheadDFA);
      return lookaheadDFA;
    }

    // not LL(1) but perhaps we can solve with simplified predicate search
    // even if k=1 set manually, only resolve here if we have preds; i.e.,
    // don't resolve etc...

    /*
    SemanticContext visiblePredicates =
      ll1Analyzer.getPredicates(decisionStartState);
    boolean foundConfoundingPredicate =
      ll1Analyzer.detectConfoundingPredicates(decisionStartState);
      */

    // exit if not forced k=1 or we found a predicate situation we
    // can't handle: predicates in rules invoked from this decision.
    if ( getUserMaxLookahead(decision)!=1 || // not manually set to k=1
       !getAutoBacktrackMode(decision) ||
       foundConfoundingPredicate )
    {
      //System.out.println("trying LL(*)");
      return null;
    }

    List<IntervalSet> edges = new ArrayList<IntervalSet>();
    for (int i = 1; i < altLook.length; i++) {
      LookaheadSet s = altLook[i];
      edges.add(s.tokenTypeSet);
    }
    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);
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.antlr.analysis.LookaheadSet

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.