⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rstringliteral.java

📁 java 编译器java复杂编译器,可以编译java文件的类库
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                 ostr.println(");");              }              else              {                 ostr.print("         return ");                 ostr.print("jjMoveStringLiteralDfa" + (i + 1) +                                LexGen.lexStateSuffix + "(");                 for (j = 0; j < maxLongsReqd - 1; j++)                    if ((i + 1) <= maxLenForActive[j] + 1)                    {                       if (atLeastOne)                          ostr.print(", ");                       else                          atLeastOne = true;                       if (info.validKinds[j] != 0L)                          ostr.print("active" + j + ", 0x" +                                  Long.toHexString(info.validKinds[j]) + "L");                       else                          ostr.print("active" + j + ", 0L");                    }                 if ((i + 1) <= maxLenForActive[j] + 1)                 {                    if (atLeastOne)                       ostr.print(", ");                    if (info.validKinds[j] != 0L)                       ostr.print("active" + j + ", 0x" +                                  Long.toHexString(info.validKinds[j]) + "L");                    else                       ostr.print("active" + j + ", 0L");                 }                 ostr.println(");");              }           }           else           {              // A very special case.              if (i == 0 && LexGen.mixed[LexGen.lexStateIndex])              {                 if (NfaState.generatedStates != 0)                    ostr.println("         return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", 0);");                 else                    ostr.println("         return 1;");              }              else if (i != 0) // No more str literals to look for              {                 ostr.println("         break;");                 startNfaNeeded = true;              }           }        }        /* default means that the current character is not in any of the           strings at this position. */        ostr.println("      default :");        if (Options.B("DEBUG_TOKEN_MANAGER"))           ostr.println("      debugStream.println(\"   No string literal matches possible.\");");        if (NfaState.generatedStates != 0)        {           if (i == 0)           {              /* This means no string literal is possible. Just move nfa with                 this guy and return. */              ostr.println("         return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", 0);");           }           else           {              ostr.println("         break;");              startNfaNeeded = true;           }        }        else        {           ostr.println("         return " + (i + 1) + ";");        }        ostr.println("   }");        if (i != 0)        {          if (startNfaNeeded)          {           if (!LexGen.mixed[LexGen.lexStateIndex] && NfaState.generatedStates != 0)           {              /* Here, a string literal is successfully matched and no more                 string literals are possible. So set the kind and state set                 upto and including this position for the matched string. */              ostr.print("   return jjStartNfa" + LexGen.lexStateSuffix + "(" + (i - 1) + ", ");              for (k = 0; k < maxLongsReqd - 1; k++)                 if (i <= maxLenForActive[k])                    ostr.print("active" + k + ", ");                 else                    ostr.print("0L, ");              if (i <= maxLenForActive[k])                 ostr.println("active" + k + ");");              else                 ostr.println("0L);");           }           else if (NfaState.generatedStates != 0)              ostr.println("   return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", " + i + ");");           else              ostr.println("   return " + (i + 1) + ";");          }        }        ostr.println("}");     }  }  static final int GetStrKind(String str)  {     for (int i = 0; i < maxStrKind; i++)     {        if (LexGen.lexStates[i] != LexGen.lexStateIndex)           continue;        String image = allImages[i];        if (image != null && image.equals(str))           return i;     }     return Integer.MAX_VALUE;  }  static void GenerateNfaStartStates(java.io.PrintWriter ostr,                                                NfaState initialState)  {     boolean[] seen = new boolean[NfaState.generatedStates];     Hashtable stateSets = new Hashtable();     String stateSetString  = "";     int i, j, kind, jjmatchedPos = 0;     int maxKindsReqd = maxStrKind / 64 + 1;     long[] actives;     Vector newStates = new Vector();     Vector oldStates = null, jjtmpStates;     statesForPos = new Hashtable[maxLen];     intermediateKinds = new int[maxStrKind + 1][];     intermediateMatchedPos = new int[maxStrKind + 1][];     for (i = 0; i < maxStrKind; i++)     {        if (LexGen.lexStates[i] != LexGen.lexStateIndex)           continue;        String image = allImages[i];        if (image == null || image.length() < 1)           continue;        try        {           if ((oldStates = (Vector)initialState.epsilonMoves.clone()) == null ||               oldStates.size() == 0)           {              DumpNfaStartStatesCode(statesForPos, ostr);              return;           }        }        catch(Exception e)        {           JavaCCErrors.semantic_error("Error cloning state vector");        }        intermediateKinds[i] = new int[image.length()];        intermediateMatchedPos[i] = new int[image.length()];        jjmatchedPos = 0;        kind = Integer.MAX_VALUE;        for (j = 0; j < image.length(); j++)        {           if (oldStates == null || oldStates.size() <= 0)           {              // Here, j > 0              kind = intermediateKinds[i][j] = intermediateKinds[i][j - 1];              jjmatchedPos = intermediateMatchedPos[i][j] = intermediateMatchedPos[i][j - 1];           }           else           {              kind = NfaState.MoveFromSet(image.charAt(j), oldStates, newStates);              oldStates.removeAllElements();              if (j == 0 && kind != Integer.MAX_VALUE &&                  LexGen.canMatchAnyChar[LexGen.lexStateIndex] != -1 &&                  kind > LexGen.canMatchAnyChar[LexGen.lexStateIndex])                 kind = LexGen.canMatchAnyChar[LexGen.lexStateIndex];              if (GetStrKind(image.substring(0, j + 1)) < kind)              {                 intermediateKinds[i][j] = kind = Integer.MAX_VALUE;                 jjmatchedPos = 0;              }              else if (kind != Integer.MAX_VALUE)              {                 intermediateKinds[i][j] = kind;                 jjmatchedPos = intermediateMatchedPos[i][j] = j;              }              else if (j == 0)                 kind = intermediateKinds[i][j] = Integer.MAX_VALUE;              else              {                 kind = intermediateKinds[i][j] = intermediateKinds[i][j - 1];                 jjmatchedPos = intermediateMatchedPos[i][j] = intermediateMatchedPos[i][j - 1];              }              stateSetString = NfaState.GetStateSetString(newStates);           }           if (kind == Integer.MAX_VALUE &&               (newStates == null || newStates.size() == 0))              continue;           int p;           if (stateSets.get(stateSetString) == null)           {              stateSets.put(stateSetString, stateSetString);              for (p = 0; p < newStates.size(); p++)              {                 if (seen[((NfaState)newStates.elementAt(p)).stateName])                    ((NfaState)newStates.elementAt(p)).inNextOf++;                 else                    seen[((NfaState)newStates.elementAt(p)).stateName] = true;              }           }           else           {              for (p = 0; p < newStates.size(); p++)                 seen[((NfaState)newStates.elementAt(p)).stateName] = true;           }           jjtmpStates = oldStates;           oldStates = newStates;           (newStates = jjtmpStates).removeAllElements();           if (statesForPos[j] == null)              statesForPos[j] = new Hashtable();           if ((actives = ((long[])statesForPos[j].get(kind + ", " +                                    jjmatchedPos + ", " + stateSetString))) == null)           {              actives = new long[maxKindsReqd];              statesForPos[j].put(kind + ", " + jjmatchedPos + ", " +                                                 stateSetString, actives);           }           actives[i / 64] |= 1L << (i % 64);           //String name = NfaState.StoreStateSet(stateSetString);        }     }     DumpNfaStartStatesCode(statesForPos, ostr);  }  static void DumpNfaStartStatesCode(Hashtable[] statesForPos,                                              java.io.PrintWriter ostr)  {     int i, maxKindsReqd = maxStrKind / 64 + 1;     boolean condGenerated = false;     int ind = 0;     if (maxStrKind == 0) // No need to generate this function        return;     ostr.print("private" + (Options.B("STATIC") ? " static" : "") + " final int jjStopStringLiteralDfa" +                  LexGen.lexStateSuffix + "(int pos, ");     for (i = 0; i < maxKindsReqd - 1; i++)        ostr.print("long active" + i + ", ");     ostr.println("long active" + i + ")\n{");     if (Options.B("DEBUG_TOKEN_MANAGER"))        ostr.println("      debugStream.println(\"   No more string literal token matches are possible.\");");     ostr.println("   switch (pos)\n   {");     for (i = 0; i < maxLen - 1; i++)     {        if (statesForPos[i] == null)           continue;        ostr.println("      case " + i + ":");        Enumeration e = statesForPos[i].keys();        while (e.hasMoreElements())        {           String stateSetString = (String)e.nextElement();           long[] actives = (long[])statesForPos[i].get(stateSetString);           for (int j = 0; j < maxKindsReqd; j++)           {              if (actives[j] == 0L)                 continue;              if (condGenerated)                 ostr.print(" || ");              else                 ostr.print("         if (");              condGenerated = true;              ostr.print("(active" + j + " & 0x" +                          Long.toHexString(actives[j]) + "L) != 0L");           }           if (condGenerated)           {              ostr.println(")");              String kindStr = stateSetString.substring(0,                                       ind = stateSetString.indexOf(", "));              String afterKind = stateSetString.substring(ind + 2);              int jjmatchedPos = Integer.parseInt(                           afterKind.substring(0, afterKind.indexOf(", ")));              if (!kindStr.equals(String.valueOf(Integer.MAX_VALUE)))                 ostr.println("         {");              if (!kindStr.equals(String.valueOf(Integer.MAX_VALUE)))              {                 if (i == 0)                 {                    ostr.println("            jjmatchedKind = " + kindStr + ";");                    if ((LexGen.initMatch[LexGen.lexStateIndex] != 0 &&                        LexGen.initMatch[LexGen.lexStateIndex] != Integer.MAX_VALUE))                       ostr.println("            jjmatchedPos = 0;");                 }                 else if (i == jjmatchedPos)                 {                    if (subStringAtPos[i])                    {                       ostr.println("            if (jjmatchedPos != " + i + ")");                       ostr.println("            {");                       ostr.println("               jjmatchedKind = " + kindStr + ";");                       ostr.println("               jjmatchedPos = " + i + ";");                       ostr.println("            }");                    }                    else                    {                       ostr.println("            jjmatchedKind = " + kindStr + ";");                       ostr.println("            jjmatchedPos = " + i + ";");                    }                 }                 else                 {                    if (jjmatchedPos > 0)                       ostr.println("            if (jjmatchedPos < " + jjmatchedPos + ")");                    else                       ostr.println("            if (jjmatchedPos == 0)");                    ostr.println("            {");                    ostr.println("               jjmatchedKind = " + kindStr + ";");                    ostr.println("               jjmatchedPos = " + jjmatchedPos + ";");                    ostr.println("            }");                 }              }              kindStr = stateSetString.substring(0,                                    ind = stateSetString.indexOf(", "));              afterKind = stateSetString.substring(ind + 2);              stateSetString = afterKind.substring(                                       afterKind.indexOf(", ") + 2);              if (stateSetString.equals("null;"))                 ostr.println("            return -1;");              else                 ostr.println("            return " +                    NfaState.AddStartStateSet(stateSetString) + ";");              if (!kindStr.equals(String.valueOf(Integer.MAX_VALUE)))                 ostr.println("         }");              condGenerated = false;           }        }        ostr.println("         return -1;");     }     ostr.println("      default :");     ostr.println("         return -1;");     ostr.println("   }");     ostr.println("}");     ostr.print("private" + (Options.B("STATIC") ? " static" : "") + " final int jjStartNfa" +                  LexGen.lexStateSuffix + "(int pos, ");     for (i = 0; i < maxKindsReqd - 1; i++)        ostr.print("long active" + i + ", ");     ostr.println("long active" + i + ")\n{");     if (LexGen.mixed[LexGen.lexStateIndex])     {         if (NfaState.generatedStates != 0)            ostr.println("   return jjMoveNfa" + LexGen.lexStateSuffix + "(" + NfaState.InitStateName() + ", pos + 1);");         else            ostr.println("   return pos + 1;");         ostr.println("}");         return;     }     ostr.print("   return jjMoveNfa" + LexGen.lexStateSuffix + "(" +               "jjStopStringLiteralDfa" + LexGen.lexStateSuffix + "(pos, ");     for (i = 0; i < maxKindsReqd - 1; i++)        ostr.print("active" + i + ", ");     ostr.print("active" + i + ")");     ostr.println(", pos + 1);");     ostr.println("}");  }   public static void reInit()   {      maxStrKind = 0;      maxLen = 0;      charCnt = 0;      charPosKind = new Vector();      maxLenForActive = new int[100];      allImages = null;      intermediateKinds = null;      intermediateMatchedPos = null;      startStateCnt = 0;      subString = null;      subStringAtPos = null;      statesForPos = null;      boilerPlateDumped = false;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -