nfastate.java
来自「java 编译器java复杂编译器,可以编译java文件的类库」· Java 代码 · 共 2,249 行 · 第 1/5 页
JAVA
2,249 行
for (c = 0; c <= r; c++) loBytes[hiByte][c / 64] |= (1L << (c % 64)); } } long[] common = null; boolean[] done = new boolean[256]; for (i = 0; i <= 255; i++) { if (done[i] || (done[i] = loBytes[i][0] == 0 && loBytes[i][1] == 0 && loBytes[i][2] == 0 && loBytes[i][3] == 0)) continue; for (j = i + 1; j < 256; j++) { if (done[j]) continue; if (loBytes[i][0] == loBytes[j][0] && loBytes[i][1] == loBytes[j][1] && loBytes[i][2] == loBytes[j][2] && loBytes[i][3] == loBytes[j][3]) { done[j] = true; if (common == null) { done[i] = true; common = new long[4]; common[i / 64] |= (1L << (i % 64)); } common[j / 64] |= (1L << (j % 64)); } } if (common != null) { Integer ind; String tmp; tmp = "{\n 0x" + Long.toHexString(common[0]) + "L, " + "0x" + Long.toHexString(common[1]) + "L, " + "0x" + Long.toHexString(common[2]) + "L, " + "0x" + Long.toHexString(common[3]) + "L\n};"; if ((ind = (Integer)lohiByteTab.get(tmp)) == null) { allBitVectors.addElement(tmp); if (!AllBitsSet(tmp)) ostr.println("static final long[] jjbitVec" + lohiByteCnt + " = " + tmp); lohiByteTab.put(tmp, ind = new Integer(lohiByteCnt++)); } tmpIndices[cnt++] = ind.intValue(); tmp = "{\n 0x" + Long.toHexString(loBytes[i][0]) + "L, " + "0x" + Long.toHexString(loBytes[i][1]) + "L, " + "0x" + Long.toHexString(loBytes[i][2]) + "L, " + "0x" + Long.toHexString(loBytes[i][3]) + "L\n};"; if ((ind = (Integer)lohiByteTab.get(tmp)) == null) { allBitVectors.addElement(tmp); if (!AllBitsSet(tmp)) ostr.println("static final long[] jjbitVec" + lohiByteCnt + " = " + tmp); lohiByteTab.put(tmp, ind = new Integer(lohiByteCnt++)); } tmpIndices[cnt++] = ind.intValue(); common = null; } } nonAsciiMoveIndices = new int[cnt]; System.arraycopy(tmpIndices, 0, nonAsciiMoveIndices, 0, cnt);/* System.out.println("state : " + stateName + " cnt : " + cnt); while (cnt > 0) { System.out.print(nonAsciiMoveIndices[cnt - 1] + ", " + nonAsciiMoveIndices[cnt - 2] + ", "); cnt -= 2; } System.out.println("");*/ for (i = 0; i < 256; i++) { if (done[i]) loBytes[i] = null; else { //System.out.print(i + ", "); String tmp; Integer ind; tmp = "{\n 0x" + Long.toHexString(loBytes[i][0]) + "L, " + "0x" + Long.toHexString(loBytes[i][1]) + "L, " + "0x" + Long.toHexString(loBytes[i][2]) + "L, " + "0x" + Long.toHexString(loBytes[i][3]) + "L\n};"; if ((ind = (Integer)lohiByteTab.get(tmp)) == null) { allBitVectors.addElement(tmp); if (!AllBitsSet(tmp)) ostr.println("static final long[] jjbitVec" + lohiByteCnt + " = " + tmp); lohiByteTab.put(tmp, ind = new Integer(lohiByteCnt++)); } if (loByteVec == null) loByteVec = new Vector(); loByteVec.addElement(new Integer(i)); loByteVec.addElement(ind); } } //System.out.println(""); UpdateDuplicateNonAsciiMoves(); } private void UpdateDuplicateNonAsciiMoves() { for (int i = 0; i < nonAsciiTableForMethod.size(); i++) { NfaState tmp = (NfaState)nonAsciiTableForMethod.elementAt(i); if (EqualLoByteVectors(loByteVec, tmp.loByteVec) && EqualNonAsciiMoveIndices(nonAsciiMoveIndices, tmp.nonAsciiMoveIndices)) { nonAsciiMethod = i; return; } } nonAsciiMethod = nonAsciiTableForMethod.size(); nonAsciiTableForMethod.addElement(this); } private static boolean EqualLoByteVectors(Vector vec1, Vector vec2) { if (vec1 == null || vec2 == null) return false; if (vec1 == vec2) return true; if (vec1.size() != vec2.size()) return false; for (int i = 0; i < vec1.size(); i++) { if (((Integer)vec1.elementAt(i)).intValue() != ((Integer)vec2.elementAt(i)).intValue()) return false; } return true; } private static boolean EqualNonAsciiMoveIndices(int[] moves1, int[] moves2) { if (moves1 == moves2) return true; if (moves1 == null || moves2 == null) return false; if (moves1.length != moves2.length) return false; for (int i = 0; i < moves1.length;i++) { if (moves1[i] != moves2[i]) return false; } return true; } static String allBits = "{\n 0xffffffffffffffffL, " + "0xffffffffffffffffL, " + "0xffffffffffffffffL, " + "0xffffffffffffffffL\n};"; static boolean AllBitsSet(String bitVec) { return bitVec.equals(allBits); } static int AddStartStateSet(String stateSetString) { return AddCompositeStateSet(stateSetString, true); } private static int AddCompositeStateSet(String stateSetString, boolean starts) { Integer stateNameToReturn; if ((stateNameToReturn = (Integer)stateNameForComposite.get(stateSetString)) != null) return stateNameToReturn.intValue(); int toRet = 0; int[] nameSet = (int[])allNextStates.get(stateSetString); if (!starts) stateBlockTable.put(stateSetString, stateSetString); if (nameSet == null) throw new Error("JavaCC Bug: Please send mail to sankar@cs.stanford.edu; nameSet null for : " + stateSetString); if (nameSet.length == 1) { stateNameToReturn = new Integer(nameSet[0]); stateNameForComposite.put(stateSetString, stateNameToReturn); return nameSet[0]; } for (int i = 0; i < nameSet.length; i++) { if (nameSet[i] == -1) continue; NfaState st = (NfaState)indexedAllStates.elementAt(nameSet[i]); st.isComposite = true; st.compositeStates = nameSet; } while (toRet < nameSet.length && (starts && ((NfaState)indexedAllStates.elementAt(nameSet[toRet])).inNextOf > 1)) toRet++; Enumeration e = compositeStateTable.keys(); String s; while (e.hasMoreElements()) { s = (String)e.nextElement(); if (!s.equals(stateSetString) && Intersect(stateSetString, s)) { int[] other = (int[])compositeStateTable.get(s); while (toRet < nameSet.length && ((starts && ((NfaState)indexedAllStates.elementAt(nameSet[toRet])).inNextOf > 1) || ElemOccurs(nameSet[toRet], other) >= 0)) toRet++; } } int tmp; if (toRet >= nameSet.length) { if (dummyStateIndex == -1) tmp = dummyStateIndex = generatedStates; else tmp = ++dummyStateIndex; } else tmp = nameSet[toRet]; stateNameToReturn = new Integer(tmp); stateNameForComposite.put(stateSetString, stateNameToReturn); compositeStateTable.put(stateSetString, nameSet); return tmp; } private static int StateNameForComposite(String stateSetString) { return ((Integer)stateNameForComposite.get(stateSetString)).intValue(); } static int InitStateName() { String s = LexGen.initialState.GetEpsilonMovesString(); if (LexGen.initialState.usefulEpsilonMoves != 0) return StateNameForComposite(s); return -1; } public void GenerateInitMoves(java.io.PrintWriter ostr) { GetEpsilonMovesString(); if (epsilonMovesString == null) epsilonMovesString = "null;"; AddStartStateSet(epsilonMovesString); } static Hashtable tableToDump = new Hashtable(); static Vector orderedStateSet = new Vector(); static int lastIndex = 0; private static int[] GetStateSetIndicesForUse(String arrayString) { int[] ret; int[] set = (int[])allNextStates.get(arrayString); if ((ret = (int[])tableToDump.get(arrayString)) == null) { ret = new int[2]; ret[0] = lastIndex; ret[1] = lastIndex + set.length - 1; lastIndex += set.length; tableToDump.put(arrayString, ret); orderedStateSet.addElement(set); } return ret; } public static void DumpStateSets(java.io.PrintWriter ostr) { int cnt = 0; ostr.print("static final int[] jjnextStates = {"); for (int i = 0; i < orderedStateSet.size(); i++) { int[] set = (int[])orderedStateSet.elementAt(i); for (int j = 0; j < set.length; j++) { if (cnt++ % 16 == 0) ostr.print("\n "); ostr.print(set[j] + ", "); } } ostr.println("\n};"); } static String GetStateSetString(int[] states) { String retVal = "{ "; for (int i = 0; i < states.length; ) { retVal += states[i] + ", "; if (i++ > 0 && i % 16 == 0) retVal += "\n"; } retVal += "};"; allNextStates.put(retVal, states); return retVal; } static String GetStateSetString(Vector states) { if (states == null || states.size() == 0) return "null;"; int[] set = new int[states.size()]; String retVal = "{ "; for (int i = 0; i < states.size(); ) { int k; retVal += (k = ((NfaState)states.elementAt(i)).stateName) + ", "; set[i] = k; if (i++ > 0 && i % 16 == 0) retVal += "\n"; } retVal += "};"; allNextStates.put(retVal, set); return retVal; } static int NumberOfBitsSet(long l) { int ret = 0; for (int i = 0; i < 63; i++) if (((l >> i) & 1L) != 0L) ret++; return ret; } static int OnlyOneBitSet(long l) { int oneSeen = -1; for (int i = 0; i < 64; i++) if (((l >> i) & 1L) != 0L) { if (oneSeen >= 0) return -1; oneSeen = i; } return oneSeen; } private static int ElemOccurs(int elem, int[] arr) { for (int i = arr.length; i-- > 0;) if (arr[i] == elem) return i; return -1; } private boolean FindCommonBlocks() { if (next == null || next.usefulEpsilonMoves <= 1) return false; if (stateDone == null) stateDone = new boolean[generatedStates]; String set = next.epsilonMovesString; int[] nameSet = (int[])allNextStates.get(set); if (nameSet.length <= 2 || compositeStateTable.get(set) != null) return false; int i; int freq[] = new int[nameSet.length]; boolean live[] = new boolean[nameSet.length]; int[] count = new int[allNextStates.size()]; for (i = 0; i < nameSet.length; i++) { if (nameSet[i] != -1) { if (live[i] = !stateDone[nameSet[i]]) count[0]++; } } int j, blockLen = 0, commonFreq = 0; Enumeration e = allNextStates.keys(); boolean needUpdate; while (e.hasMoreElements()) { String s; int[] tmpSet = (int[])allNextStates.get(s = (String)e.nextElement()); if (tmpSet == nameSet)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?