/src/main/java/com/bog/model/ast/BrainfuckTokenManager.java

https://gitlab.com/bog/qbic · Java · 307 lines · 278 code · 17 blank · 12 comment · 41 complexity · 10abeb455b06a04b0543ab37315fd93f MD5 · raw file

  1. /* Generated By:JJTree&JavaCC: Do not edit this line. BrainfuckTokenManager.java */
  2. package com.bog.model.ast;
  3. /** Token Manager. */
  4. public class BrainfuckTokenManager implements BrainfuckConstants
  5. {
  6. /** Debug output. */
  7. public java.io.PrintStream debugStream = System.out;
  8. /** Set debug output. */
  9. public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
  10. private final int jjStopStringLiteralDfa_0(int pos, long active0)
  11. {
  12. switch (pos)
  13. {
  14. default :
  15. return -1;
  16. }
  17. }
  18. private final int jjStartNfa_0(int pos, long active0)
  19. {
  20. return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
  21. }
  22. private int jjStopAtPos(int pos, int kind)
  23. {
  24. jjmatchedKind = kind;
  25. jjmatchedPos = pos;
  26. return pos + 1;
  27. }
  28. private int jjMoveStringLiteralDfa0_0()
  29. {
  30. switch(curChar)
  31. {
  32. case 43:
  33. return jjStopAtPos(0, 1);
  34. case 44:
  35. return jjStopAtPos(0, 6);
  36. case 45:
  37. return jjStopAtPos(0, 2);
  38. case 46:
  39. return jjStopAtPos(0, 5);
  40. case 60:
  41. return jjStopAtPos(0, 3);
  42. case 62:
  43. return jjStopAtPos(0, 4);
  44. case 91:
  45. return jjStopAtPos(0, 7);
  46. case 93:
  47. return jjStopAtPos(0, 8);
  48. default :
  49. return jjMoveNfa_0(0, 0);
  50. }
  51. }
  52. private int jjMoveNfa_0(int startState, int curPos)
  53. {
  54. int startsAt = 0;
  55. jjnewStateCnt = 1;
  56. int i = 1;
  57. jjstateSet[0] = startState;
  58. int kind = 0x7fffffff;
  59. for (;;)
  60. {
  61. if (++jjround == 0x7fffffff)
  62. ReInitRounds();
  63. if (curChar < 64)
  64. {
  65. long l = 1L << curChar;
  66. do
  67. {
  68. switch(jjstateSet[--i])
  69. {
  70. case 0:
  71. if ((0xafff838600000000L & l) == 0L)
  72. break;
  73. kind = 9;
  74. jjstateSet[jjnewStateCnt++] = 0;
  75. break;
  76. default : break;
  77. }
  78. } while(i != startsAt);
  79. }
  80. else if (curChar < 128)
  81. {
  82. long l = 1L << (curChar & 077);
  83. do
  84. {
  85. switch(jjstateSet[--i])
  86. {
  87. case 0:
  88. if ((0x2ffffffe17fffffeL & l) == 0L)
  89. break;
  90. kind = 9;
  91. jjstateSet[jjnewStateCnt++] = 0;
  92. break;
  93. default : break;
  94. }
  95. } while(i != startsAt);
  96. }
  97. else
  98. {
  99. int i2 = (curChar & 0xff) >> 6;
  100. long l2 = 1L << (curChar & 077);
  101. do
  102. {
  103. switch(jjstateSet[--i])
  104. {
  105. default : break;
  106. }
  107. } while(i != startsAt);
  108. }
  109. if (kind != 0x7fffffff)
  110. {
  111. jjmatchedKind = kind;
  112. jjmatchedPos = curPos;
  113. kind = 0x7fffffff;
  114. }
  115. ++curPos;
  116. if ((i = jjnewStateCnt) == (startsAt = 1 - (jjnewStateCnt = startsAt)))
  117. return curPos;
  118. try { curChar = input_stream.readChar(); }
  119. catch(java.io.IOException e) { return curPos; }
  120. }
  121. }
  122. static final int[] jjnextStates = {
  123. };
  124. /** Token literal values. */
  125. public static final String[] jjstrLiteralImages = {
  126. "", "\53", "\55", "\74", "\76", "\56", "\54", "\133", "\135", null, null, null,
  127. null, };
  128. /** Lexer state names. */
  129. public static final String[] lexStateNames = {
  130. "DEFAULT",
  131. };
  132. static final long[] jjtoToken = {
  133. 0x3ffL,
  134. };
  135. static final long[] jjtoSkip = {
  136. 0x1c00L,
  137. };
  138. protected SimpleCharStream input_stream;
  139. private final int[] jjrounds = new int[1];
  140. private final int[] jjstateSet = new int[2];
  141. protected char curChar;
  142. /** Constructor. */
  143. public BrainfuckTokenManager(SimpleCharStream stream){
  144. if (SimpleCharStream.staticFlag)
  145. throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
  146. input_stream = stream;
  147. }
  148. /** Constructor. */
  149. public BrainfuckTokenManager(SimpleCharStream stream, int lexState){
  150. this(stream);
  151. SwitchTo(lexState);
  152. }
  153. /** Reinitialise parser. */
  154. public void ReInit(SimpleCharStream stream)
  155. {
  156. jjmatchedPos = jjnewStateCnt = 0;
  157. curLexState = defaultLexState;
  158. input_stream = stream;
  159. ReInitRounds();
  160. }
  161. private void ReInitRounds()
  162. {
  163. int i;
  164. jjround = 0x80000001;
  165. for (i = 1; i-- > 0;)
  166. jjrounds[i] = 0x80000000;
  167. }
  168. /** Reinitialise parser. */
  169. public void ReInit(SimpleCharStream stream, int lexState)
  170. {
  171. ReInit(stream);
  172. SwitchTo(lexState);
  173. }
  174. /** Switch to specified lex state. */
  175. public void SwitchTo(int lexState)
  176. {
  177. if (lexState >= 1 || lexState < 0)
  178. throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
  179. else
  180. curLexState = lexState;
  181. }
  182. protected Token jjFillToken()
  183. {
  184. final Token t;
  185. final String curTokenImage;
  186. final int beginLine;
  187. final int endLine;
  188. final int beginColumn;
  189. final int endColumn;
  190. String im = jjstrLiteralImages[jjmatchedKind];
  191. curTokenImage = (im == null) ? input_stream.GetImage() : im;
  192. beginLine = input_stream.getBeginLine();
  193. beginColumn = input_stream.getBeginColumn();
  194. endLine = input_stream.getEndLine();
  195. endColumn = input_stream.getEndColumn();
  196. t = Token.newToken(jjmatchedKind, curTokenImage);
  197. t.beginLine = beginLine;
  198. t.endLine = endLine;
  199. t.beginColumn = beginColumn;
  200. t.endColumn = endColumn;
  201. return t;
  202. }
  203. int curLexState = 0;
  204. int defaultLexState = 0;
  205. int jjnewStateCnt;
  206. int jjround;
  207. int jjmatchedPos;
  208. int jjmatchedKind;
  209. /** Get the next Token. */
  210. public Token getNextToken()
  211. {
  212. Token matchedToken;
  213. int curPos = 0;
  214. EOFLoop :
  215. for (;;)
  216. {
  217. try
  218. {
  219. curChar = input_stream.BeginToken();
  220. }
  221. catch(java.io.IOException e)
  222. {
  223. jjmatchedKind = 0;
  224. matchedToken = jjFillToken();
  225. return matchedToken;
  226. }
  227. try { input_stream.backup(0);
  228. while (curChar <= 32 && (0x100000600L & (1L << curChar)) != 0L)
  229. curChar = input_stream.BeginToken();
  230. }
  231. catch (java.io.IOException e1) { continue EOFLoop; }
  232. jjmatchedKind = 0x7fffffff;
  233. jjmatchedPos = 0;
  234. curPos = jjMoveStringLiteralDfa0_0();
  235. if (jjmatchedKind != 0x7fffffff)
  236. {
  237. if (jjmatchedPos + 1 < curPos)
  238. input_stream.backup(curPos - jjmatchedPos - 1);
  239. if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
  240. {
  241. matchedToken = jjFillToken();
  242. return matchedToken;
  243. }
  244. else
  245. {
  246. continue EOFLoop;
  247. }
  248. }
  249. int error_line = input_stream.getEndLine();
  250. int error_column = input_stream.getEndColumn();
  251. String error_after = null;
  252. boolean EOFSeen = false;
  253. try { input_stream.readChar(); input_stream.backup(1); }
  254. catch (java.io.IOException e1) {
  255. EOFSeen = true;
  256. error_after = curPos <= 1 ? "" : input_stream.GetImage();
  257. if (curChar == '\n' || curChar == '\r') {
  258. error_line++;
  259. error_column = 0;
  260. }
  261. else
  262. error_column++;
  263. }
  264. if (!EOFSeen) {
  265. input_stream.backup(1);
  266. error_after = curPos <= 1 ? "" : input_stream.GetImage();
  267. }
  268. throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
  269. }
  270. }
  271. private void jjCheckNAdd(int state)
  272. {
  273. if (jjrounds[state] != jjround)
  274. {
  275. jjstateSet[jjnewStateCnt++] = state;
  276. jjrounds[state] = jjround;
  277. }
  278. }
  279. private void jjAddStates(int start, int end)
  280. {
  281. do {
  282. jjstateSet[jjnewStateCnt++] = jjnextStates[start];
  283. } while (start++ != end);
  284. }
  285. private void jjCheckNAddTwoStates(int state1, int state2)
  286. {
  287. jjCheckNAdd(state1);
  288. jjCheckNAdd(state2);
  289. }
  290. }