📄 lexgen.java
字号:
// Method to reinitialize the jjrounds array. ostr.println(staticString + "private final void ReInitRounds()"); ostr.println("{"); ostr.println(" int i;"); ostr.println(" jjround = 0x" + Integer.toHexString(Integer.MIN_VALUE + 1)+ ";"); ostr.println(" for (i = " + stateSetSize + "; i-- > 0;)"); ostr.println(" jjrounds[i] = 0x" + Integer.toHexString(Integer.MIN_VALUE) + ";"); ostr.println("}"); // Reinit method for reinitializing the parser (for static parsers). ostr.println(staticString + "public void ReInit(" + charStreamName + " stream, int lexState)"); ostr.println("{"); ostr.println(" ReInit(stream);"); ostr.println(" SwitchTo(lexState);"); ostr.println("}"); ostr.println(staticString + "public void SwitchTo(int lexState)"); ostr.println("{"); ostr.println(" if (lexState >= " + lexStateName.length + " || lexState < 0)"); ostr.println(" throw new TokenMgrError(\"Error: Ignoring invalid lexical state : \"" + " + lexState + \". State unchanged.\", TokenMgrError.INVALID_LEXICAL_STATE);"); ostr.println(" else"); ostr.println(" curLexState = lexState;"); ostr.println("}"); ostr.println(""); } // Assumes l != 0L static char MaxChar(long l) { for (int i = 64; i-- > 0; ) if ((l & (1L << i)) != 0L) return (char)i; return 0xffff; } static void DumpFillToken() { ostr.println(staticString + "protected Token jjFillToken()"); ostr.println("{"); ostr.println(" Token t = Token.newToken(jjmatchedKind);"); ostr.println(" t.kind = jjmatchedKind;"); if (hasEmptyMatch) { ostr.println(" if (jjmatchedPos < 0)"); ostr.println(" {"); ostr.println(" if (image == null)"); ostr.println(" t.image = \"\";"); ostr.println(" else"); ostr.println(" t.image = image.toString();"); if (keepLineCol) { ostr.println(" t.beginLine = t.endLine = input_stream.getBeginLine();"); ostr.println(" t.beginColumn = t.endColumn = input_stream.getBeginColumn();"); } ostr.println(" }"); ostr.println(" else"); ostr.println(" {"); ostr.println(" String im = jjstrLiteralImages[jjmatchedKind];"); ostr.println(" t.image = (im == null) ? input_stream.GetImage() : im;"); if (keepLineCol) { ostr.println(" t.beginLine = input_stream.getBeginLine();"); ostr.println(" t.beginColumn = input_stream.getBeginColumn();"); ostr.println(" t.endLine = input_stream.getEndLine();"); ostr.println(" t.endColumn = input_stream.getEndColumn();"); } ostr.println(" }"); } else { ostr.println(" String im = jjstrLiteralImages[jjmatchedKind];"); ostr.println(" t.image = (im == null) ? input_stream.GetImage() : im;"); if (keepLineCol) { ostr.println(" t.beginLine = input_stream.getBeginLine();"); ostr.println(" t.beginColumn = input_stream.getBeginColumn();"); ostr.println(" t.endLine = input_stream.getEndLine();"); ostr.println(" t.endColumn = input_stream.getEndColumn();"); } } ostr.println(" return t;"); ostr.println("}"); } static void DumpGetNextToken() { int i; ostr.println(""); ostr.println(staticString + "int curLexState = " + defaultLexState + ";"); ostr.println(staticString + "int defaultLexState = " + defaultLexState + ";"); ostr.println(staticString + "int jjnewStateCnt;"); ostr.println(staticString + "int jjround;"); ostr.println(staticString + "int jjmatchedPos;"); ostr.println(staticString + "int jjmatchedKind;"); ostr.println(""); ostr.println("public " + staticString + "Token getNextToken()" + " "); ostr.println("{"); ostr.println(" int kind;"); ostr.println(" Token specialToken = null;"); ostr.println(" Token matchedToken;"); ostr.println(" int curPos = 0;"); ostr.println(""); ostr.println(" EOFLoop :\n for (;;)"); ostr.println(" { "); ostr.println(" try "); ostr.println(" { "); ostr.println(" curChar = input_stream.BeginToken();"); ostr.println(" } "); ostr.println(" catch(java.io.IOException e)"); ostr.println(" { "); if (Options.B("DEBUG_TOKEN_MANAGER")) ostr.println(" debugStream.println(\"Returning the <EOF> token.\");"); ostr.println(" jjmatchedKind = 0;"); ostr.println(" matchedToken = jjFillToken();"); if (hasSpecial) ostr.println(" matchedToken.specialToken = specialToken;"); if (nextStateForEof != null || actForEof != null) ostr.println(" TokenLexicalActions(matchedToken);"); if (Options.B("COMMON_TOKEN_ACTION")) ostr.println(" CommonTokenAction(matchedToken);"); ostr.println(" return matchedToken;"); ostr.println(" }"); if (hasMoreActions || hasSkipActions || hasTokenActions) { ostr.println(" image = null;"); ostr.println(" jjimageLen = 0;"); } ostr.println(""); String prefix = ""; if (hasMore) { ostr.println(" for (;;)"); ostr.println(" {"); prefix = " "; } String endSwitch = ""; String caseStr = ""; // this also sets up the start state of the nfa if (maxLexStates > 1) { ostr.println(prefix + " switch(curLexState)"); ostr.println(prefix + " {"); endSwitch = prefix + " }"; caseStr = prefix + " case "; prefix += " "; } prefix += " "; for(i = 0; i < maxLexStates; i++) { if (maxLexStates > 1) ostr.println(caseStr + i + ":"); if (singlesToSkip[i].HasTransitions()) { // added the backup(0) to make JIT happy ostr.println(prefix + "try { input_stream.backup(0);"); if (singlesToSkip[i].asciiMoves[0] != 0L && singlesToSkip[i].asciiMoves[1] != 0L) { ostr.println(prefix + " while ((curChar < 64" + " && (0x" + Long.toHexString(singlesToSkip[i].asciiMoves[0]) + "L & (1L << curChar)) != 0L) || \n" + prefix + " (curChar >> 6) == 1" + " && (0x" + Long.toHexString(singlesToSkip[i].asciiMoves[1]) + "L & (1L << (curChar & 077))) != 0L)"); } else if (singlesToSkip[i].asciiMoves[1] == 0L) { ostr.println(prefix + " while (curChar <= " + (int)MaxChar(singlesToSkip[i].asciiMoves[0]) + " && (0x" + Long.toHexString(singlesToSkip[i].asciiMoves[0]) + "L & (1L << curChar)) != 0L)"); } else if (singlesToSkip[i].asciiMoves[0] == 0L) { ostr.println(prefix + " while (curChar > 63 && curChar <= " + ((int)MaxChar(singlesToSkip[i].asciiMoves[1]) + 64) + " && (0x" + Long.toHexString(singlesToSkip[i].asciiMoves[1]) + "L & (1L << (curChar & 077))) != 0L)"); } if (Options.B("DEBUG_TOKEN_MANAGER")) { ostr.println(prefix + "{"); ostr.println(" debugStream.println(" + (maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Skipping character : \" + " + "TokenMgrError.addEscapes(String.valueOf(curChar)) + \" (\" + (int)curChar + \")\");"); } ostr.println(prefix + " curChar = input_stream.BeginToken();"); if (Options.B("DEBUG_TOKEN_MANAGER")) ostr.println(prefix + "}"); ostr.println(prefix + "}"); ostr.println(prefix + "catch (java.io.IOException e1) { continue EOFLoop; }"); } if (initMatch[i] != Integer.MAX_VALUE && initMatch[i] != 0) { if (Options.B("DEBUG_TOKEN_MANAGER")) ostr.println(" debugStream.println(\" Matched the empty string as \" + tokenImage[" + initMatch[i] + "] + \" token.\");"); ostr.println(prefix + "jjmatchedKind = " + initMatch[i] + ";"); ostr.println(prefix + "jjmatchedPos = -1;"); ostr.println(prefix + "curPos = 0;"); } else { ostr.println(prefix + "jjmatchedKind = 0x" + Integer.toHexString(Integer.MAX_VALUE) + ";"); ostr.println(prefix + "jjmatchedPos = 0;"); } if (Options.B("DEBUG_TOKEN_MANAGER")) ostr.println(" debugStream.println(" + (maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + "\"Current character : \" + " + "TokenMgrError.addEscapes(String.valueOf(curChar)) + \" (\" + (int)curChar + \")\");"); ostr.println(prefix + "curPos = jjMoveStringLiteralDfa0_" + i + "();"); if (canMatchAnyChar[i] != -1) { if (initMatch[i] != Integer.MAX_VALUE && initMatch[i] != 0) ostr.println(prefix + "if (jjmatchedPos < 0 || (jjmatchedPos == 0 && jjmatchedKind > " + canMatchAnyChar[i] + "))"); else ostr.println(prefix + "if (jjmatchedPos == 0 && jjmatchedKind > " + canMatchAnyChar[i] + ")"); ostr.println(prefix + "{"); if (Options.B("DEBUG_TOKEN_MANAGER")) ostr.println(" debugStream.println(\" Current character matched as a \" + tokenImage[" + canMatchAnyChar[i] + "] + \" token.\");"); ostr.println(prefix + " jjmatchedKind = " + canMatchAnyChar[i] + ";"); if (initMatch[i] != Integer.MAX_VALUE && initMatch[i] != 0) ostr.println(prefix + " jjmatchedPos = 0;"); ostr.println(prefix + "}"); } if (maxLexStates > 1) ostr.println(prefix + "break;"); } if (maxLexStates > 1) ostr.println(endSwitch); else if (maxLexStates == 0) ostr.println(" jjmatchedKind = 0x" + Integer.toHexString(Integer.MAX_VALUE) + ";"); if (maxLexStates > 1) prefix = " "; else prefix = ""; if (maxLexStates > 0) { ostr.println(prefix + " if (jjmatchedKind != 0x" + Integer.toHexString(Integer.MAX_VALUE) + ")"); ostr.println(prefix + " {"); ostr.println(prefix + " if (jjmatchedPos + 1 < curPos)"); if (Options.B("DEBUG_TOKEN_MANAGER")) { ostr.println(prefix + " {"); ostr.println(prefix + " debugStream.println(\" Putting back \" + (curPos - jjmatchedPos - 1) + \" characters into the input stream.\");"); } ostr.println(prefix + " input_stream.backup(curPos - jjmatchedPos - 1);"); if (Options.B("DEBUG_TOKEN_MANAGER")) ostr.println(prefix + " }"); if (Options.B("DEBUG_TOKEN_MANAGER")) { if (Options.B("JAVA_UNICODE_ESCAPE") || Options.B("USER_CHAR_STREAM")) ostr.println(" debugStream.println(\"****** FOUND A \" + tokenImage[jjmatchedKind] + \" MATCH (\" + TokenMgrError.addEscapes(new String(input_stream.GetSuffix(jjmatchedPos + 1))) + \") ******\\n\");"); else ostr.println(" debugStream.println(\"****** FOUND A \" + tokenImage[jjmatchedKind] + \" MATCH (\" + TokenMgrError.addEscapes(new String(input_stream.GetSuffix(jjmatchedPos + 1))) + \") ******\\n\");"); } if (hasSkip || hasMore || hasSpecial) { ostr.println(prefix + " if ((jjtoToken[jjmatchedKind >> 6] & " + "(1L << (jjmatchedKind & 077))) != 0L)"); ostr.println(prefix + " {"); } ostr.println(prefix + " matchedToken = jjFillToken();"); if (hasSpecial) ostr.println(prefix + " matchedToken.specialToken = specialToken;"); if (hasTokenActions) ostr.println(prefix + " TokenLexicalActions(matchedToken);"); if (maxLexStates > 1) { ostr.println(" if (jjnewLexState[jjmatchedKind] != -1)"); ostr.println(prefix + " curLexState = jjnewLexState[jjmatchedKind];"); } if (Options.B("COMMON_TOKEN_ACTION")) ostr.println(prefix + " CommonTokenAction(matchedToken);"); ostr.println(prefix + " return matchedToken;"); if (hasSkip || hasMore || hasSpecial) { ostr.println(prefix + " }"); if (hasSkip || hasSpecial) { if (hasMore) { ostr.println(prefix + " else if ((jjtoSkip[jjmatchedKind >> 6] & " + "(1L << (jjmatchedKind & 077))) != 0L)"); } else ostr.println(prefix + " else"); ostr.println(prefix + " {"); if (hasSpecial) { ostr.println(prefix + " if ((jjtoSpecial[jjmatchedKind >> 6] & " + "(1L << (jjmatchedKind & 077))) != 0L)"); ostr.println(prefix + " {"); ostr.println(prefix + " matchedToken = jjFillToken();"); ostr.println(prefix + " if (specialToken == null)"); ostr.println(prefix + " specialToken = matchedToken;"); ostr.println(prefix + " else"); ostr.println(prefix + " {"); ostr.println(prefix + " matchedToken.specialToken = specialToken;"); ostr.println(prefix + " specialToken = (specialToken.next = matchedToken);"); ostr.println(prefix + " }"); if (hasSkipActions) ostr.println(prefix + " SkipLexicalActions(matchedToken);"); ostr.println(prefix + " }"); if (hasSkipActions) { ostr.println(prefix + " else "); ostr.println(prefix + " SkipLexicalActions(null);"); } } else if (hasSkipActions) ostr.println(prefix + " SkipLexicalActions(null);"); if (maxLexStates > 1) { ostr.println(" if (jjnewLexState[jjmatchedKind] != -1)"); ostr.println(prefix + " curLexState = jjnewLexState[jjmatchedKind];"); } ostr.println(prefix + " continue EOFLoop;"); ostr.println(prefix + " }");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -