Esempio n. 1
0
 public void consumeToken(Token token) {
   if (dump) System.out.println("consume token " + token);
   if (!inDecision()) {
     stats.numTokens++;
     return;
   }
   if (lastRealTokenTouchedInDecision == null
       || lastRealTokenTouchedInDecision.getTokenIndex() < token.getTokenIndex()) {
     lastRealTokenTouchedInDecision = token;
   }
   DecisionEvent d = currentDecision();
   // compute lookahead depth
   int thisRefIndex = token.getTokenIndex();
   int numHidden = getNumberOfHiddenTokens(d.startIndex, thisRefIndex);
   int depth = thisRefIndex - d.startIndex - numHidden + 1; // +1 counts consuming start token as 1
   // d.maxk = Math.max(d.maxk, depth);
   if (dump)
     System.out.println(
         "consume "
             + thisRefIndex
             + " "
             + depth
             + " tokens ahead in "
             + d.decision.ruleName
             + "-"
             + d.decision.decision
             + " start index "
             + d.startIndex);
 }
Esempio n. 2
0
 /** Track refs to lookahead if in a fixed/nonfixed decision. */
 public void LT(int i, Token t) {
   if (inDecision() && i > 0) {
     DecisionEvent d = currentDecision();
     if (dump)
       System.out.println(
           "LT("
               + i
               + ")="
               + t
               + " index "
               + t.getTokenIndex()
               + " relative to "
               + d.decision.ruleName
               + "-"
               + d.decision.decision
               + " start index "
               + d.startIndex);
     if (lastRealTokenTouchedInDecision == null
         || lastRealTokenTouchedInDecision.getTokenIndex() < t.getTokenIndex()) {
       lastRealTokenTouchedInDecision = t;
       if (dump) System.out.println("set last token " + lastRealTokenTouchedInDecision);
     }
     // get starting index off stack
     //			int stackTop = lookaheadStack.size()-1;
     //			Integer startingIndex = (Integer)lookaheadStack.get(stackTop);
     //			// compute lookahead depth
     //			int thisRefIndex = parser.getTokenStream().index();
     //			int numHidden =
     //				getNumberOfHiddenTokens(startingIndex.intValue(), thisRefIndex);
     //			int depth = i + thisRefIndex - startingIndex.intValue() - numHidden;
     //			/*
     //			System.out.println("LT("+i+") @ index "+thisRefIndex+" is depth "+depth+
     //				" max is "+maxLookaheadInCurrentDecision);
     //			*/
     //			if ( depth>maxLookaheadInCurrentDecision ) {
     //				maxLookaheadInCurrentDecision = depth;
     //			}
     //			d.maxk = currentDecision()/
   }
 }
Esempio n. 3
0
  public void exitDecision(int decisionNumber) {
    DecisionEvent d = decisionStack.pop();
    d.stopTime = System.currentTimeMillis();

    int lastTokenIndex = lastRealTokenTouchedInDecision.getTokenIndex();
    int numHidden = getNumberOfHiddenTokens(d.startIndex, lastTokenIndex);
    int depth =
        lastTokenIndex - d.startIndex - numHidden + 1; // +1 counts consuming start token as 1
    d.k = depth;
    d.decision.maxk = Math.max(d.decision.maxk, depth);

    if (dump)
      System.out.println(
          "exitDecision "
              + decisionNumber
              + " in "
              + d.decision.ruleName
              + " lookahead "
              + d.k
              + " max token "
              + lastRealTokenTouchedInDecision);
    decisionEvents.add(d); // done with decision; track all
  }