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

📄 lexgen.java

📁 java 编译器java复杂编译器,可以编译java文件的类库
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
              {                 ((RStringLiteral)curRE).GenerateDfa(ostr, curRE.ordinal);                 if (i != 0 && !mixed[lexStateIndex] && ignoring != ignore)                    mixed[lexStateIndex] = true;              }              else if (curRE.CanMatchAnyChar())              {                 if (canMatchAnyChar[lexStateIndex] == -1 ||                     canMatchAnyChar[lexStateIndex] > curRE.ordinal)                    canMatchAnyChar[lexStateIndex] = curRE.ordinal;              }              else              {                 Nfa temp;                 if (curRE instanceof RChoice)                    choices.addElement(curRE);                 temp = curRE.GenerateNfa(ignore);                 temp.end.isFinal = true;                 temp.end.kind = curRE.ordinal;                 initialState.AddMove(temp.start);              }              if (kinds.length < curRE.ordinal)              {                 int[] tmp = new int[curRE.ordinal + 1];                 System.arraycopy(kinds, 0, tmp, 0, kinds.length);                 kinds = tmp;              }              //System.out.println("   ordina : " + curRE.ordinal);              kinds[curRE.ordinal] = kind;              if (respec.nextState != null &&                  !respec.nextState.equals(lexStateName[lexStateIndex]))                 newLexState[curRE.ordinal] = respec.nextState;              if (respec.act != null && respec.act.action_tokens != null &&                  respec.act.action_tokens.size() > 0)                 actions[curRE.ordinal] = respec.act;              switch(kind)              {                 case TokenProduction.SPECIAL :                    hasSkipActions |= (actions[curRE.ordinal] != null) ||                                      (newLexState[curRE.ordinal] != null);                    hasSpecial = true;                    toSpecial[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64);                    toSkip[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64);                    break;                 case TokenProduction.SKIP :                    hasSkipActions |= (actions[curRE.ordinal] != null);                    hasSkip = true;                    toSkip[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64);                    break;                 case TokenProduction.MORE :                    hasMoreActions |= (actions[curRE.ordinal] != null);                    hasMore = true;                    toMore[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64);                    if (newLexState[curRE.ordinal] != null)                       canReachOnMore[GetIndex(newLexState[curRE.ordinal])] = true;                    else                       canReachOnMore[lexStateIndex] = true;                    break;                 case TokenProduction.TOKEN :                    hasTokenActions |= (actions[curRE.ordinal] != null);                    hasToken = true;                    toToken[curRE.ordinal / 64] |= 1L << (curRE.ordinal % 64);                    break;              }           }        }        // Generate a static block for initializing the nfa transitions        NfaState.ComputeClosures();        for (i = 0; i < initialState.epsilonMoves.size(); i++)           ((NfaState)initialState.epsilonMoves.elementAt(i)).GenerateCode();        if (hasNfa[lexStateIndex] = (NfaState.generatedStates != 0))        {           initialState.GenerateCode();           initialState.GenerateInitMoves(ostr);        }        if (initialState.kind != Integer.MAX_VALUE && initialState.kind != 0)        {           if ((toSkip[initialState.kind / 64] & (1L << initialState.kind)) != 0L ||               (toSpecial[initialState.kind / 64] & (1L << initialState.kind)) != 0L)              hasSkipActions = true;           else if ((toMore[initialState.kind / 64] & (1L << initialState.kind)) != 0L)              hasMoreActions = true;           else              hasTokenActions = true;           if (initMatch[lexStateIndex] == 0 ||               initMatch[lexStateIndex] > initialState.kind)           {              initMatch[lexStateIndex] = initialState.kind;              hasEmptyMatch = true;           }        }        else if (initMatch[lexStateIndex] == 0)           initMatch[lexStateIndex] = Integer.MAX_VALUE;        RStringLiteral.FillSubString();        if (hasNfa[lexStateIndex] && !mixed[lexStateIndex])           RStringLiteral.GenerateNfaStartStates(ostr, initialState);        RStringLiteral.DumpDfaCode(ostr);        if (hasNfa[lexStateIndex])           NfaState.DumpMoveNfa(ostr);        if (stateSetSize < NfaState.generatedStates)           stateSetSize = NfaState.generatedStates;     }     for (i = 0; i < choices.size(); i++)        ((RChoice)choices.elementAt(i)).CheckUnmatchability();     NfaState.DumpStateSets(ostr);     CheckEmptyStringMatch();     NfaState.DumpNonAsciiMoveMethods(ostr);     RStringLiteral.DumpStrLiteralImages(ostr);     DumpStaticVarDeclarations();     DumpFillToken();     DumpGetNextToken();     if (Options.B("DEBUG_TOKEN_MANAGER"))     {        NfaState.DumpStatesForKind(ostr);        DumpDebugMethods();     }     if (hasLoop)     {        ostr.println(staticString + "int[] jjemptyLineNo = new int[" + maxLexStates + "];");        ostr.println(staticString + "int[] jjemptyColNo = new int[" + maxLexStates + "];");        ostr.println(staticString + "boolean[] jjbeenHere = new boolean[" + maxLexStates + "];");     }     if (hasSkipActions)        DumpSkipActions();     if (hasMoreActions)        DumpMoreActions();     if (hasTokenActions)        DumpTokenActions();     ostr.println(/*{*/ "}");     ostr.close();  }  static void CheckEmptyStringMatch()  {     int i, j, k, len;     boolean[] seen = new boolean[maxLexStates];     boolean[] done = new boolean[maxLexStates];     String cycle;     String reList;     Outer:     for (i = 0; i < maxLexStates; i++)     {        if (done[i] || initMatch[i] == 0 || initMatch[i] == Integer.MAX_VALUE ||            canMatchAnyChar[i] != -1)           continue;        done[i] = true;        len = 0;        cycle = "";        reList = "";        for (k = 0; k < maxLexStates; k++)           seen[k] = false;        j = i;        seen[i] = true;        cycle += lexStateName[j] + "-->";        while (newLexState[initMatch[j]] != null)        {           cycle += newLexState[initMatch[j]];           if (seen[j = GetIndex(newLexState[initMatch[j]])])              break;           cycle += "-->";           done[j] = true;           seen[j] = true;           if (initMatch[j] == 0 || initMatch[j] == Integer.MAX_VALUE ||               canMatchAnyChar[j] != -1)              continue Outer;           if (len != 0)              reList += "; ";           reList += "line " + rexprs[initMatch[j]].line + ", column " +                      rexprs[initMatch[j]].column;           len++;        }        if (newLexState[initMatch[j]] == null)           cycle += lexStateName[lexStates[initMatch[j]]];        for (k = 0; k < maxLexStates; k++)           canLoop[k] |= seen[k];        hasLoop = true;        if (len == 0)           JavaCCErrors.warning(rexprs[initMatch[i]],                "Regular expression" + ((rexprs[initMatch[i]].label.equals(""))                      ? "" : (" for " + rexprs[initMatch[i]].label)) +								" can be matched by the empty string (\"\") in lexical state " + 								lexStateName[i] + ". This can result in an endless loop of " +								"empty string matches.");					 else					 {						 JavaCCErrors.warning(rexprs[initMatch[i]],								"Regular expression" + ((rexprs[initMatch[i]].label.equals(""))										? "" : (" for " + rexprs[initMatch[i]].label)) +								" can be matched by the empty string (\"\") in lexical state " +                 lexStateName[i] + ". This regular expression along with the " +                "regular expressions at " + reList + " forms the cycle \n   " +                cycle + "\ncontaining regular expressions with empty matches." +                " This can result in an endless loop of empty string matches.");        }     }  }  static void PrintArrayInitializer(int noElems)  {     ostr.print("{");     for (int i = 0; i < noElems; i++)     {        if (i % 25 == 0)           ostr.print("\n   ");        ostr.print("0, ");     }     ostr.println("\n};");  }  static void DumpStaticVarDeclarations()  {      int i;      String charStreamName;      ostr.println("public static final String[] lexStateNames = {");      for (i = 0; i < maxLexStates; i++)         ostr.println("   \"" + lexStateName[i] + "\", ");      ostr.println("};");      if (maxLexStates > 1)      {         ostr.print("public static final int[] jjnewLexState = {");         for (i = 0; i < maxOrdinal; i++)         {            if (i % 25 == 0)               ostr.print("\n   ");            if (newLexState[i] == null)               ostr.print("-1, ");            else               ostr.print(GetIndex(newLexState[i]) + ", ");         }         ostr.println("\n};");      }      if (hasSkip || hasMore || hasSpecial)      {         // Bit vector for TOKEN         ostr.print("static final long[] jjtoToken = {");         for (i = 0; i < maxOrdinal / 64 + 1; i++)         {            if (i % 4 == 0)               ostr.print("\n   ");            ostr.print("0x" + Long.toHexString(toToken[i]) + "L, ");         }         ostr.println("\n};");      }      if (hasSkip || hasSpecial)      {         // Bit vector for SKIP         ostr.print("static final long[] jjtoSkip = {");         for (i = 0; i < maxOrdinal / 64 + 1; i++)         {            if (i % 4 == 0)               ostr.print("\n   ");            ostr.print("0x" + Long.toHexString(toSkip[i]) + "L, ");         }         ostr.println("\n};");      }      if (hasSpecial)      {         // Bit vector for SPECIAL         ostr.print("static final long[] jjtoSpecial = {");         for (i = 0; i < maxOrdinal / 64 + 1; i++)         {            if (i % 4 == 0)               ostr.print("\n   ");            ostr.print("0x" + Long.toHexString(toSpecial[i]) + "L, ");         }         ostr.println("\n};");      }      if (hasMore)      {         // Bit vector for MORE         ostr.print("static final long[] jjtoMore = {");         for (i = 0; i < maxOrdinal / 64 + 1; i++)         {            if (i % 4 == 0)               ostr.print("\n   ");            ostr.print("0x" + Long.toHexString(toMore[i]) + "L, ");         }         ostr.println("\n};");      }      if (Options.B("USER_CHAR_STREAM"))         charStreamName = "CharStream";      else      {         if (Options.B("JAVA_UNICODE_ESCAPE"))            charStreamName = "JavaCharStream";         else            charStreamName = "SimpleCharStream";      }      ostr.println(staticString + "protected " + charStreamName + " input_stream;");      ostr.println(staticString + "private final int[] jjrounds = " +                      "new int[" + stateSetSize + "];");      ostr.println(staticString + "private final int[] jjstateSet = " +                      "new int[" + (2 * stateSetSize) + "];");      if (hasMoreActions || hasSkipActions || hasTokenActions)      {         ostr.println(staticString + "StringBuffer image;");         ostr.println(staticString + "int jjimageLen;");         ostr.println(staticString + "int lengthOfMatch;");      }      ostr.println(staticString + "protected char curChar;");      ostr.println("public " + tokMgrClassName + "(" + charStreamName + " stream)");      ostr.println("{");      if (Options.B("STATIC") && !Options.B("USER_CHAR_STREAM"))      {         ostr.println("   if (input_stream != null)");         ostr.println("      throw new TokenMgrError(\"ERROR: Second call to constructor of static lexer. You must use ReInit() to initialize the static variables.\", TokenMgrError.STATIC_LEXER_ERROR);");      }      else if (!Options.B("USER_CHAR_STREAM"))      {         if (Options.B("JAVA_UNICODE_ESCAPE"))            ostr.println("   if (JavaCharStream.staticFlag)");         else            ostr.println("   if (SimpleCharStream.staticFlag)");         ostr.println("      throw new Error(\"ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.\");");      }      ostr.println("   input_stream = stream;");      ostr.println("}");      ostr.println("public " + tokMgrClassName + "(" + charStreamName + " stream, int lexState)");      ostr.println("{");      ostr.println("   this(stream);");      ostr.println("   SwitchTo(lexState);");      ostr.println("}");      // Reinit method for reinitializing the parser (for static parsers).      ostr.println(staticString + "public void ReInit(" + charStreamName + " stream)");      ostr.println("{");      ostr.println("   jjmatchedPos = jjnewStateCnt = 0;");      ostr.println("   curLexState = defaultLexState;");      ostr.println("   input_stream = stream;");      ostr.println("   ReInitRounds();");      ostr.println("}");

⌨️ 快捷键说明

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