示例#1
0
 /** EOT (end of token) is a label that indicates when the DFA conversion
  *  algorithm would "fall off the end of a lexer rule".  It normally
  *  means the default clause.  So for ('a'..'z')+ you would see a DFA
  *  with a state that has a..z and EOT emanating from it.  a..z would
  *  jump to a state predicting alt 1 and EOT would jump to a state
  *  predicting alt 2 (the exit loop branch).  EOT implies anything other
  *  than a..z.  If for some reason, the set is "all char" such as with
  *  the wildcard '.', then EOT cannot match anything.  For example,
  *
  *     BLOCK : '{' (.)* '}'
  *
  *  consumes all char until EOF when greedy=true.  When all edges are
  *  combined for the DFA state after matching '}', you will find that
  *  it is all char.  The EOT transition has nothing to match and is
  *  unreachable.  The findNewDFAStatesAndAddDFATransitions() method
  *  must know to ignore the EOT, so we simply remove it from the
  *  reachable labels.  Later analysis will find that the exit branch
  *  is not predicted by anything.  For greedy=false, we leave only
  *  the EOT label indicating that the DFA should stop immediately
  *  and predict the exit branch. The reachable labels are often a
  *  set of disjoint values like: [<EOT>, 42, {0..41, 43..65534}]
  *  due to DFA conversion so must construct a pure set to see if
  *  it is same as Label.ALLCHAR.
  *
  *  Only do this for Lexers.
  *
  *  If EOT coexists with ALLCHAR:
  *  1. If not greedy, modify the labels parameter to be EOT
  *  2. If greedy, remove EOT from the labels set
  */
 protected boolean ReachableLabelsEOTCoexistsWithAllChar(OrderedHashSet labels)
 {
     Label eot = new Label(Label.EOT);
     if ( !labels.containsKey(eot) ) {
         return false;
     }
     [email protected]("### contains EOT");
     bool containsAllChar = false;
     IntervalSet completeVocab = new IntervalSet();
     int n = labels.size();
     for (int i=0; i<n; i++) {
         Label rl = (Label)labels.get(i);
         if ( !rl.Equals(eot) ) {
             completeVocab.addAll(rl.Set());
         }
     }
     [email protected]("completeVocab="+completeVocab);
     if ( completeVocab.Equals(Label.ALLCHAR) ) {
         [email protected]("all char");
         containsAllChar = true;
     }
     return containsAllChar;
 }