Package org.antlr.misc

Examples of org.antlr.misc.OrderedHashSet


   *  from the set of NFA states reachable from any NFA
   *  state in DFA state d.
   */
  protected void findNewDFAStatesAndAddDFATransitions(DFAState d) {
    //System.out.println("work on DFA state "+d);
    OrderedHashSet labels = d.getReachableLabels();
    //System.out.println("reachable labels="+labels);

    /*
    System.out.println("|reachable|/|nfaconfigs|="+
        labels.size()+"/"+d.getNFAConfigurations().size()+"="+
        labels.size()/(float)d.getNFAConfigurations().size());
    */

    // normally EOT is the "default" clause and decisions just
    // choose that last clause when nothing else matches.  DFA conversion
    // continues searching for a unique sequence that predicts the
    // various alts or until it finds EOT.  So this rule
    //
    // DUH : ('x'|'y')* "xy!";
    //
    // does not need a greedy indicator.  The following rule works fine too
    //
    // A : ('x')+ ;
    //
    // When the follow branch could match what is in the loop, by default,
    // the nondeterminism is resolved in favor of the loop.  You don't
    // get a warning because the only way to get this condition is if
    // the DFA conversion hits the end of the token.  In that case,
    // we're not *sure* what will happen next, but it could be anything.
    // Anyway, EOT is the default case which means it will never be matched
    // as resolution goes to the lowest alt number.  Exit branches are
    // always alt n+1 for n alts in a block.
    //
    // When a loop is nongreedy and we find an EOT transition, the DFA
    // state should become an accept state, predicting exit of loop.  It's
    // just reversing the resolution of ambiguity.
    // TODO: should this be done in the resolveAmbig method?
    Label EOTLabel = new Label(Label.EOT);
    boolean containsEOT = labels!=null && labels.contains(EOTLabel);
    if ( !dfa.isGreedy() && containsEOT ) {
      convertToEOTAcceptState(d);
      return; // no more work to do on this accept state
    }

    // if in filter mode for lexer, want to match shortest not longest
    // string so if we see an EOT edge emanating from this state, then
    // convert this state to an accept state.  This only counts for
    // The Tokens rule as all other decisions must continue to look for
    // longest match.
    // [Taking back out a few days later on Jan 17, 2006.  This could
    //  be an option for the future, but this was wrong soluion for
    //  filtering.]
    /*
    if ( dfa.nfa.grammar.type==Grammar.LEXER && containsEOT ) {
      String filterOption = (String)dfa.nfa.grammar.getOption("filter");
      boolean filterMode = filterOption!=null && filterOption.equals("true");
      if ( filterMode && d.dfa.isTokensRuleDecision() ) {
        DFAState t = reach(d, EOTLabel);
        if ( t.getNFAConfigurations().size()>0 ) {
          convertToEOTAcceptState(d);
          //System.out.println("state "+d+" has EOT target "+t.stateNumber);
          return;
        }
      }
    }
    */

    int numberOfEdgesEmanating = 0;
    Map targetToLabelMap = new HashMap();
    // for each label that could possibly emanate from NFAStates of d
    int numLabels = 0;
    if ( labels!=null ) {
      numLabels = labels.size();
    }
    for (int i=0; i<numLabels; i++) {
      Label label = (Label)labels.get(i);
      DFAState t = reach(d, label);
      if ( debug ) {
        System.out.println("DFA state after reach "+label+" "+d+"-" +
                   label.toString(dfa.nfa.grammar)+"->"+t);
      }
View Full Code Here


   *  from the set of NFA states reachable from any NFA
   *  state in DFA state d.
   */
  protected void findNewDFAStatesAndAddDFATransitions(DFAState d) {
    //System.out.println("work on DFA state "+d);
    OrderedHashSet labels = d.getReachableLabels();
    //System.out.println("reachable labels="+labels);

    /*
    System.out.println("|reachable|/|nfaconfigs|="+
        labels.size()+"/"+d.getNFAConfigurations().size()+"="+
        labels.size()/(float)d.getNFAConfigurations().size());
    */

    // normally EOT is the "default" clause and decisions just
    // choose that last clause when nothing else matches.  DFA conversion
    // continues searching for a unique sequence that predicts the
    // various alts or until it finds EOT.  So this rule
    //
    // DUH : ('x'|'y')* "xy!";
    //
    // does not need a greedy indicator.  The following rule works fine too
    //
    // A : ('x')+ ;
    //
    // When the follow branch could match what is in the loop, by default,
    // the nondeterminism is resolved in favor of the loop.  You don't
    // get a warning because the only way to get this condition is if
    // the DFA conversion hits the end of the token.  In that case,
    // we're not *sure* what will happen next, but it could be anything.
    // Anyway, EOT is the default case which means it will never be matched
    // as resolution goes to the lowest alt number.  Exit branches are
    // always alt n+1 for n alts in a block.
    //
    // When a loop is nongreedy and we find an EOT transition, the DFA
    // state should become an accept state, predicting exit of loop.  It's
    // just reversing the resolution of ambiguity.
    // TODO: should this be done in the resolveAmbig method?
    Label EOTLabel = new Label(Label.EOT);
    boolean containsEOT = labels!=null && labels.contains(EOTLabel);
    if ( !dfa.isGreedy() && containsEOT ) {
      convertToEOTAcceptState(d);
      return; // no more work to do on this accept state
    }

    // if in filter mode for lexer, want to match shortest not longest
    // string so if we see an EOT edge emanating from this state, then
    // convert this state to an accept state.  This only counts for
    // The Tokens rule as all other decisions must continue to look for
    // longest match.
    // [Taking back out a few days later on Jan 17, 2006.  This could
    //  be an option for the future, but this was wrong soluion for
    //  filtering.]
    /*
    if ( dfa.nfa.grammar.type==Grammar.LEXER && containsEOT ) {
      String filterOption = (String)dfa.nfa.grammar.getOption("filter");
      boolean filterMode = filterOption!=null && filterOption.equals("true");
      if ( filterMode && d.dfa.isTokensRuleDecision() ) {
        DFAState t = reach(d, EOTLabel);
        if ( t.getNFAConfigurations().size()>0 ) {
          convertToEOTAcceptState(d);
          //System.out.println("state "+d+" has EOT target "+t.stateNumber);
          return;
        }
      }
    }
    */

    int numberOfEdgesEmanating = 0;
    Map targetToLabelMap = new HashMap();
    // for each label that could possibly emanate from NFAStates of d
    int numLabels = 0;
    if ( labels!=null ) {
      numLabels = labels.size();
    }
    for (int i=0; i<numLabels; i++) {
      Label label = (Label)labels.get(i);
      DFAState t = reach(d, label);
      if ( debug ) {
        System.out.println("DFA state after reach "+label+" "+d+"-" +
                   label.toString(dfa.nfa.grammar)+"->"+t);
      }
View Full Code Here

   *  from the set of NFA states reachable from any NFA
   *  state in DFA state d.
   */
  protected void findNewDFAStatesAndAddDFATransitions(DFAState d) {
    //System.out.println("work on DFA state "+d);
    OrderedHashSet labels = d.getReachableLabels();
    /*
    System.out.println("reachable="+labels.toString());
    System.out.println("|reachable|/|nfaconfigs|="+
        labels.size()+"/"+d.getNFAConfigurations().size()+"="+
        labels.size()/(float)d.getNFAConfigurations().size());
    */

    // normally EOT is the "default" clause and decisions just
    // choose that last clause when nothing else matches.  DFA conversion
    // continues searching for a unique sequence that predicts the
    // various alts or until it finds EOT.  So this rule
    //
    // DUH : ('x'|'y')* "xy!";
    //
    // does not need a greedy indicator.  The following rule works fine too
    //
    // A : ('x')+ ;
    //
    // When the follow branch could match what is in the loop, by default,
    // the nondeterminism is resolved in favor of the loop.  You don't
    // get a warning because the only way to get this condition is if
    // the DFA conversion hits the end of the token.  In that case,
    // we're not *sure* what will happen next, but it could be anything.
    // Anyway, EOT is the default case which means it will never be matched
    // as resolution goes to the lowest alt number.  Exit branches are
    // always alt n+1 for n alts in a block.
    //
    // When a loop is nongreedy and we find an EOT transition, the DFA
    // state should become an accept state, predicting exit of loop.  It's
    // just reversing the resolution of ambiguity.
    // TODO: should this be done in the resolveAmbig method?
    Label EOTLabel = new Label(Label.EOT);
    boolean containsEOT = labels.contains(EOTLabel);
    if ( !dfa.isGreedy() && containsEOT ) {
      convertToEOTAcceptState(d);
      return; // no more work to do on this accept state
    }

    // if in filter mode for lexer, want to match shortest not longest
    // string so if we see an EOT edge emanating from this state, then
    // convert this state to an accept state.  This only counts for
    // The Tokens rule as all other decisions must continue to look for
    // longest match.
    // [Taking back out a few days later on Jan 17, 2006.  This could
    //  be an option for the future, but this was wrong soluion for
    //  filtering.]
    /*
    if ( dfa.nfa.grammar.type==Grammar.LEXER && containsEOT ) {
      String filterOption = (String)dfa.nfa.grammar.getOption("filter");
      boolean filterMode = filterOption!=null && filterOption.equals("true");
      if ( filterMode && d.dfa.isTokensRuleDecision() ) {
        DFAState t = reach(d, EOTLabel);
        if ( t.getNFAConfigurations().size()>0 ) {
          convertToEOTAcceptState(d);
          //System.out.println("state "+d+" has EOT target "+t.stateNumber);
          return;
        }
      }
    }
    */

    int numberOfEdgesEmanating = 0;
    Map targetToLabelMap = new HashMap();
    // for each label that could possibly emanate from NFAStates of d
    // (abort if we find any closure operation on a configuration of d
    //  that finds multiple alts with recursion, non-LL(*), as we cannot
    //  trust any reach operations from d since we are blind to some
    //  paths.  Leave state a dead-end and try to resolve with preds)
    for (int i=0; !d.abortedDueToMultipleRecursiveAlts && i<labels.size(); i++) {
      Label label = (Label)labels.get(i);
      DFAState t = reach(d, label);
      if ( debug ) {
        System.out.println("DFA state after reach "+d+"-" +
                   label.toString(dfa.nfa.grammar)+"->"+t);
      }
View Full Code Here

   *  from the set of NFA states reachable from any NFA
   *  state in DFA state d.
   */
  protected void findNewDFAStatesAndAddDFATransitions(DFAState d) {
    //System.out.println("work on DFA state "+d);
    OrderedHashSet labels = d.getReachableLabels();
    //System.out.println("reachable labels="+labels);

    /*
    System.out.println("|reachable|/|nfaconfigs|="+
        labels.size()+"/"+d.getNFAConfigurations().size()+"="+
        labels.size()/(float)d.getNFAConfigurations().size());
    */

    // normally EOT is the "default" clause and decisions just
    // choose that last clause when nothing else matches.  DFA conversion
    // continues searching for a unique sequence that predicts the
    // various alts or until it finds EOT.  So this rule
    //
    // DUH : ('x'|'y')* "xy!";
    //
    // does not need a greedy indicator.  The following rule works fine too
    //
    // A : ('x')+ ;
    //
    // When the follow branch could match what is in the loop, by default,
    // the nondeterminism is resolved in favor of the loop.  You don't
    // get a warning because the only way to get this condition is if
    // the DFA conversion hits the end of the token.  In that case,
    // we're not *sure* what will happen next, but it could be anything.
    // Anyway, EOT is the default case which means it will never be matched
    // as resolution goes to the lowest alt number.  Exit branches are
    // always alt n+1 for n alts in a block.
    //
    // When a loop is nongreedy and we find an EOT transition, the DFA
    // state should become an accept state, predicting exit of loop.  It's
    // just reversing the resolution of ambiguity.
    // TODO: should this be done in the resolveAmbig method?
    Label EOTLabel = new Label(Label.EOT);
    boolean containsEOT = labels!=null && labels.contains(EOTLabel);
    if ( !dfa.isGreedy() && containsEOT ) {
      convertToEOTAcceptState(d);
      return; // no more work to do on this accept state
    }

    // if in filter mode for lexer, want to match shortest not longest
    // string so if we see an EOT edge emanating from this state, then
    // convert this state to an accept state.  This only counts for
    // The Tokens rule as all other decisions must continue to look for
    // longest match.
    // [Taking back out a few days later on Jan 17, 2006.  This could
    //  be an option for the future, but this was wrong soluion for
    //  filtering.]
    /*
    if ( dfa.nfa.grammar.type==Grammar.LEXER && containsEOT ) {
      String filterOption = (String)dfa.nfa.grammar.getOption("filter");
      boolean filterMode = filterOption!=null && filterOption.equals("true");
      if ( filterMode && d.dfa.isTokensRuleDecision() ) {
        DFAState t = reach(d, EOTLabel);
        if ( t.getNFAConfigurations().size()>0 ) {
          convertToEOTAcceptState(d);
          //System.out.println("state "+d+" has EOT target "+t.stateNumber);
          return;
        }
      }
    }
    */

    int numberOfEdgesEmanating = 0;
    Map targetToLabelMap = new HashMap();
    // for each label that could possibly emanate from NFAStates of d
    int numLabels = 0;
    if ( labels!=null ) {
      numLabels = labels.size();
    }
    for (int i=0; i<numLabels; i++) {
      Label label = (Label)labels.get(i);
      DFAState t = reach(d, label);
      if ( debug ) {
        System.out.println("DFA state after reach "+label+" "+d+"-" +
                   label.toString(dfa.nfa.grammar)+"->"+t);
      }
View Full Code Here

   *  from the set of NFA states reachable from any NFA
   *  state in DFA state d.
   */
  protected void findNewDFAStatesAndAddDFATransitions(DFAState d) {
    //System.out.println("work on DFA state "+d);
    OrderedHashSet labels = d.getReachableLabels();
    //System.out.println("reachable labels="+labels);

    /*
    System.out.println("|reachable|/|nfaconfigs|="+
        labels.size()+"/"+d.getNFAConfigurations().size()+"="+
        labels.size()/(float)d.getNFAConfigurations().size());
    */

    // normally EOT is the "default" clause and decisions just
    // choose that last clause when nothing else matches.  DFA conversion
    // continues searching for a unique sequence that predicts the
    // various alts or until it finds EOT.  So this rule
    //
    // DUH : ('x'|'y')* "xy!";
    //
    // does not need a greedy indicator.  The following rule works fine too
    //
    // A : ('x')+ ;
    //
    // When the follow branch could match what is in the loop, by default,
    // the nondeterminism is resolved in favor of the loop.  You don't
    // get a warning because the only way to get this condition is if
    // the DFA conversion hits the end of the token.  In that case,
    // we're not *sure* what will happen next, but it could be anything.
    // Anyway, EOT is the default case which means it will never be matched
    // as resolution goes to the lowest alt number.  Exit branches are
    // always alt n+1 for n alts in a block.
    //
    // When a loop is nongreedy and we find an EOT transition, the DFA
    // state should become an accept state, predicting exit of loop.  It's
    // just reversing the resolution of ambiguity.
    // TODO: should this be done in the resolveAmbig method?
    Label EOTLabel = new Label(Label.EOT);
    boolean containsEOT = labels!=null && labels.contains(EOTLabel);
    if ( !dfa.isGreedy() && containsEOT ) {
      convertToEOTAcceptState(d);
      return; // no more work to do on this accept state
    }

    // if in filter mode for lexer, want to match shortest not longest
    // string so if we see an EOT edge emanating from this state, then
    // convert this state to an accept state.  This only counts for
    // The Tokens rule as all other decisions must continue to look for
    // longest match.
    // [Taking back out a few days later on Jan 17, 2006.  This could
    //  be an option for the future, but this was wrong soluion for
    //  filtering.]
    /*
    if ( dfa.nfa.grammar.type==Grammar.LEXER && containsEOT ) {
      String filterOption = (String)dfa.nfa.grammar.getOption("filter");
      boolean filterMode = filterOption!=null && filterOption.equals("true");
      if ( filterMode && d.dfa.isTokensRuleDecision() ) {
        DFAState t = reach(d, EOTLabel);
        if ( t.getNFAConfigurations().size()>0 ) {
          convertToEOTAcceptState(d);
          //System.out.println("state "+d+" has EOT target "+t.stateNumber);
          return;
        }
      }
    }
    */

    int numberOfEdgesEmanating = 0;
    Map targetToLabelMap = new HashMap();
    // for each label that could possibly emanate from NFAStates of d
    int numLabels = 0;
    if ( labels!=null ) {
      numLabels = labels.size();
    }
    for (int i=0; i<numLabels; i++) {
      Label label = (Label)labels.get(i);
      DFAState t = reach(d, label);
      if ( debug ) {
        System.out.println("DFA state after reach "+label+" "+d+"-" +
                   label.toString(dfa.nfa.grammar)+"->"+t);
      }
View Full Code Here

TOP

Related Classes of org.antlr.misc.OrderedHashSet

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.