PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/src/ecaAnalysis/Parser/SimpleCharStream.java

https://gitlab.com/MichelangeloDiamanti/ecaProject
Java | 475 lines | 356 code | 71 blank | 48 comment | 45 complexity | 3d958ff884dda33e57956ad1d8de8818 MD5 | raw file
  1. /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */
  2. /* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
  3. package ecaAnalysis.Parser;
  4. /**
  5. * An implementation of interface CharStream, where the stream is assumed to
  6. * contain only ASCII characters (without unicode processing).
  7. */
  8. public class SimpleCharStream
  9. {
  10. /** Whether parser is static. */
  11. public static final boolean staticFlag = true;
  12. static int bufsize;
  13. static int available;
  14. static int tokenBegin;
  15. /** Position in buffer. */
  16. static public int bufpos = -1;
  17. static protected int bufline[];
  18. static protected int bufcolumn[];
  19. static protected int column = 0;
  20. static protected int line = 1;
  21. static protected boolean prevCharIsCR = false;
  22. static protected boolean prevCharIsLF = false;
  23. static protected java.io.Reader inputStream;
  24. static protected char[] buffer;
  25. static protected int maxNextCharInd = 0;
  26. static protected int inBuf = 0;
  27. static protected int tabSize = 8;
  28. static protected void setTabSize(int i) { tabSize = i; }
  29. static protected int getTabSize(int i) { return tabSize; }
  30. static protected void ExpandBuff(boolean wrapAround)
  31. {
  32. char[] newbuffer = new char[bufsize + 2048];
  33. int newbufline[] = new int[bufsize + 2048];
  34. int newbufcolumn[] = new int[bufsize + 2048];
  35. try
  36. {
  37. if (wrapAround)
  38. {
  39. System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
  40. System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
  41. buffer = newbuffer;
  42. System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
  43. System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
  44. bufline = newbufline;
  45. System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
  46. System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
  47. bufcolumn = newbufcolumn;
  48. maxNextCharInd = (bufpos += (bufsize - tokenBegin));
  49. }
  50. else
  51. {
  52. System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
  53. buffer = newbuffer;
  54. System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
  55. bufline = newbufline;
  56. System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
  57. bufcolumn = newbufcolumn;
  58. maxNextCharInd = (bufpos -= tokenBegin);
  59. }
  60. }
  61. catch (Throwable t)
  62. {
  63. throw new Error(t.getMessage());
  64. }
  65. bufsize += 2048;
  66. available = bufsize;
  67. tokenBegin = 0;
  68. }
  69. static protected void FillBuff() throws java.io.IOException
  70. {
  71. if (maxNextCharInd == available)
  72. {
  73. if (available == bufsize)
  74. {
  75. if (tokenBegin > 2048)
  76. {
  77. bufpos = maxNextCharInd = 0;
  78. available = tokenBegin;
  79. }
  80. else if (tokenBegin < 0)
  81. bufpos = maxNextCharInd = 0;
  82. else
  83. ExpandBuff(false);
  84. }
  85. else if (available > tokenBegin)
  86. available = bufsize;
  87. else if ((tokenBegin - available) < 2048)
  88. ExpandBuff(true);
  89. else
  90. available = tokenBegin;
  91. }
  92. int i;
  93. try {
  94. if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1)
  95. {
  96. inputStream.close();
  97. throw new java.io.IOException();
  98. }
  99. else
  100. maxNextCharInd += i;
  101. return;
  102. }
  103. catch(java.io.IOException e) {
  104. --bufpos;
  105. backup(0);
  106. if (tokenBegin == -1)
  107. tokenBegin = bufpos;
  108. throw e;
  109. }
  110. }
  111. /** Start. */
  112. static public char BeginToken() throws java.io.IOException
  113. {
  114. tokenBegin = -1;
  115. char c = readChar();
  116. tokenBegin = bufpos;
  117. return c;
  118. }
  119. static protected void UpdateLineColumn(char c)
  120. {
  121. column++;
  122. if (prevCharIsLF)
  123. {
  124. prevCharIsLF = false;
  125. line += (column = 1);
  126. }
  127. else if (prevCharIsCR)
  128. {
  129. prevCharIsCR = false;
  130. if (c == '\n')
  131. {
  132. prevCharIsLF = true;
  133. }
  134. else
  135. line += (column = 1);
  136. }
  137. switch (c)
  138. {
  139. case '\r' :
  140. prevCharIsCR = true;
  141. break;
  142. case '\n' :
  143. prevCharIsLF = true;
  144. break;
  145. case '\t' :
  146. column--;
  147. column += (tabSize - (column % tabSize));
  148. break;
  149. default :
  150. break;
  151. }
  152. bufline[bufpos] = line;
  153. bufcolumn[bufpos] = column;
  154. }
  155. /** Read a character. */
  156. static public char readChar() throws java.io.IOException
  157. {
  158. if (inBuf > 0)
  159. {
  160. --inBuf;
  161. if (++bufpos == bufsize)
  162. bufpos = 0;
  163. return buffer[bufpos];
  164. }
  165. if (++bufpos >= maxNextCharInd)
  166. FillBuff();
  167. char c = buffer[bufpos];
  168. UpdateLineColumn(c);
  169. return c;
  170. }
  171. @Deprecated
  172. /**
  173. * @deprecated
  174. * @see #getEndColumn
  175. */
  176. static public int getColumn() {
  177. return bufcolumn[bufpos];
  178. }
  179. @Deprecated
  180. /**
  181. * @deprecated
  182. * @see #getEndLine
  183. */
  184. static public int getLine() {
  185. return bufline[bufpos];
  186. }
  187. /** Get token end column number. */
  188. static public int getEndColumn() {
  189. return bufcolumn[bufpos];
  190. }
  191. /** Get token end line number. */
  192. static public int getEndLine() {
  193. return bufline[bufpos];
  194. }
  195. /** Get token beginning column number. */
  196. static public int getBeginColumn() {
  197. return bufcolumn[tokenBegin];
  198. }
  199. /** Get token beginning line number. */
  200. static public int getBeginLine() {
  201. return bufline[tokenBegin];
  202. }
  203. /** Backup a number of characters. */
  204. static public void backup(int amount) {
  205. inBuf += amount;
  206. if ((bufpos -= amount) < 0)
  207. bufpos += bufsize;
  208. }
  209. /** Constructor. */
  210. public SimpleCharStream(java.io.Reader dstream, int startline,
  211. int startcolumn, int buffersize)
  212. {
  213. if (inputStream != null)
  214. throw new Error("\n ERROR: Second call to the constructor of a static SimpleCharStream.\n" +
  215. " You must either use ReInit() or set the JavaCC option STATIC to false\n" +
  216. " during the generation of this class.");
  217. inputStream = dstream;
  218. line = startline;
  219. column = startcolumn - 1;
  220. available = bufsize = buffersize;
  221. buffer = new char[buffersize];
  222. bufline = new int[buffersize];
  223. bufcolumn = new int[buffersize];
  224. }
  225. /** Constructor. */
  226. public SimpleCharStream(java.io.Reader dstream, int startline,
  227. int startcolumn)
  228. {
  229. this(dstream, startline, startcolumn, 4096);
  230. }
  231. /** Constructor. */
  232. public SimpleCharStream(java.io.Reader dstream)
  233. {
  234. this(dstream, 1, 1, 4096);
  235. }
  236. /** Reinitialise. */
  237. public void ReInit(java.io.Reader dstream, int startline,
  238. int startcolumn, int buffersize)
  239. {
  240. inputStream = dstream;
  241. line = startline;
  242. column = startcolumn - 1;
  243. if (buffer == null || buffersize != buffer.length)
  244. {
  245. available = bufsize = buffersize;
  246. buffer = new char[buffersize];
  247. bufline = new int[buffersize];
  248. bufcolumn = new int[buffersize];
  249. }
  250. prevCharIsLF = prevCharIsCR = false;
  251. tokenBegin = inBuf = maxNextCharInd = 0;
  252. bufpos = -1;
  253. }
  254. /** Reinitialise. */
  255. public void ReInit(java.io.Reader dstream, int startline,
  256. int startcolumn)
  257. {
  258. ReInit(dstream, startline, startcolumn, 4096);
  259. }
  260. /** Reinitialise. */
  261. public void ReInit(java.io.Reader dstream)
  262. {
  263. ReInit(dstream, 1, 1, 4096);
  264. }
  265. /** Constructor. */
  266. public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
  267. int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
  268. {
  269. this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  270. }
  271. /** Constructor. */
  272. public SimpleCharStream(java.io.InputStream dstream, int startline,
  273. int startcolumn, int buffersize)
  274. {
  275. this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  276. }
  277. /** Constructor. */
  278. public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
  279. int startcolumn) throws java.io.UnsupportedEncodingException
  280. {
  281. this(dstream, encoding, startline, startcolumn, 4096);
  282. }
  283. /** Constructor. */
  284. public SimpleCharStream(java.io.InputStream dstream, int startline,
  285. int startcolumn)
  286. {
  287. this(dstream, startline, startcolumn, 4096);
  288. }
  289. /** Constructor. */
  290. public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
  291. {
  292. this(dstream, encoding, 1, 1, 4096);
  293. }
  294. /** Constructor. */
  295. public SimpleCharStream(java.io.InputStream dstream)
  296. {
  297. this(dstream, 1, 1, 4096);
  298. }
  299. /** Reinitialise. */
  300. public void ReInit(java.io.InputStream dstream, String encoding, int startline,
  301. int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
  302. {
  303. ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
  304. }
  305. /** Reinitialise. */
  306. public void ReInit(java.io.InputStream dstream, int startline,
  307. int startcolumn, int buffersize)
  308. {
  309. ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
  310. }
  311. /** Reinitialise. */
  312. public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
  313. {
  314. ReInit(dstream, encoding, 1, 1, 4096);
  315. }
  316. /** Reinitialise. */
  317. public void ReInit(java.io.InputStream dstream)
  318. {
  319. ReInit(dstream, 1, 1, 4096);
  320. }
  321. /** Reinitialise. */
  322. public void ReInit(java.io.InputStream dstream, String encoding, int startline,
  323. int startcolumn) throws java.io.UnsupportedEncodingException
  324. {
  325. ReInit(dstream, encoding, startline, startcolumn, 4096);
  326. }
  327. /** Reinitialise. */
  328. public void ReInit(java.io.InputStream dstream, int startline,
  329. int startcolumn)
  330. {
  331. ReInit(dstream, startline, startcolumn, 4096);
  332. }
  333. /** Get token literal value. */
  334. static public String GetImage()
  335. {
  336. if (bufpos >= tokenBegin)
  337. return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
  338. else
  339. return new String(buffer, tokenBegin, bufsize - tokenBegin) +
  340. new String(buffer, 0, bufpos + 1);
  341. }
  342. /** Get the suffix. */
  343. static public char[] GetSuffix(int len)
  344. {
  345. char[] ret = new char[len];
  346. if ((bufpos + 1) >= len)
  347. System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
  348. else
  349. {
  350. System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
  351. len - bufpos - 1);
  352. System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
  353. }
  354. return ret;
  355. }
  356. /** Reset buffer when finished. */
  357. static public void Done()
  358. {
  359. buffer = null;
  360. bufline = null;
  361. bufcolumn = null;
  362. }
  363. /**
  364. * Method to adjust line and column numbers for the start of a token.
  365. */
  366. static public void adjustBeginLineColumn(int newLine, int newCol)
  367. {
  368. int start = tokenBegin;
  369. int len;
  370. if (bufpos >= tokenBegin)
  371. {
  372. len = bufpos - tokenBegin + inBuf + 1;
  373. }
  374. else
  375. {
  376. len = bufsize - tokenBegin + bufpos + 1 + inBuf;
  377. }
  378. int i = 0, j = 0, k = 0;
  379. int nextColDiff = 0, columnDiff = 0;
  380. while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
  381. {
  382. bufline[j] = newLine;
  383. nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
  384. bufcolumn[j] = newCol + columnDiff;
  385. columnDiff = nextColDiff;
  386. i++;
  387. }
  388. if (i < len)
  389. {
  390. bufline[j] = newLine++;
  391. bufcolumn[j] = newCol + columnDiff;
  392. while (i++ < len)
  393. {
  394. if (bufline[j = start % bufsize] != bufline[++start % bufsize])
  395. bufline[j] = newLine++;
  396. else
  397. bufline[j] = newLine;
  398. }
  399. }
  400. line = bufline[j];
  401. column = bufcolumn[j];
  402. }
  403. }
  404. /* JavaCC - OriginalChecksum=bcf8957eb3dcae2f8072b39d044c4957 (do not edit this line) */