From ac2aba725c8ffb2ebe1b108af5a8cd048f949936 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Sun, 8 Oct 2023 10:50:39 +0200 Subject: [PATCH 1/2] detailed output tests added --- .../helger/pgcc/AbstractJavaCCTestCase.java | 30 + .../helger/pgcc/parser/output/OutputTest.java | 134 + .../JavaCC/AbstractCharStream.java | 543 ++ .../JavaCCGrammar/JavaCC/CharStream.java | 123 + .../JavaCCGrammar/JavaCC/JavaCCParser.java | 7659 +++++++++++++++++ .../JavaCC/JavaCCParserConstants.java | 384 + .../JavaCCGrammar/JavaCC/JavaCharStream.java | 326 + .../JavaCCGrammar/JavaCC/ParseException.java | 187 + .../JavaCCGrammar/JavaCC/Token.java | 130 + .../JavaCC/TokenMgrException.java | 144 + .../Example1/AbstractCharStream.java | 543 ++ .../Lookahead/Example1/CharStream.java | 123 + .../Lookahead/Example1/Example.java | 252 + .../Lookahead/Example1/ExampleConstants.java | 27 + .../Example1/ExampleTokenManager.java | 261 + .../Lookahead/Example1/ParseException.java | 187 + .../Lookahead/Example1/SimpleCharStream.java | 125 + .../outputTest/Lookahead/Example1/Token.java | 130 + .../Lookahead/Example1/TokenMgrException.java | 144 + .../Digest/AbstractCharStream.java | 543 ++ .../MailProcessing/Digest/CharStream.java | 123 + .../MailProcessing/Digest/Digest.java | 333 + .../Digest/DigestConstants.java | 72 + .../Digest/DigestTokenManager.java | 1148 +++ .../MailProcessing/Digest/ParseException.java | 187 + .../Digest/SimpleCharStream.java | 125 + .../MailProcessing/Digest/Token.java | 130 + .../Digest/TokenMgrException.java | 144 + .../Faq/AbstractCharStream.java | 543 ++ .../MailProcessing/Faq/CharStream.java | 123 + .../outputTest/MailProcessing/Faq/Faq.java | 368 + .../MailProcessing/Faq/FaqConstants.java | 72 + .../MailProcessing/Faq/FaqTokenManager.java | 1148 +++ .../MailProcessing/Faq/ParseException.java | 187 + .../MailProcessing/Faq/SimpleCharStream.java | 125 + .../outputTest/MailProcessing/Faq/Token.java | 130 + .../MailProcessing/Faq/TokenMgrException.java | 144 + .../IdList/AbstractCharStream.java | 543 ++ .../SimpleExamples/IdList/CharStream.java | 123 + .../SimpleExamples/IdList/IdList.java | 252 + .../IdList/IdListConstants.java | 27 + .../IdList/IdListTokenManager.java | 340 + .../SimpleExamples/IdList/ParseException.java | 187 + .../IdList/SimpleCharStream.java | 125 + .../SimpleExamples/IdList/Token.java | 130 + .../IdList/TokenMgrException.java | 144 + .../NL_Xlator/AbstractCharStream.java | 543 ++ .../SimpleExamples/NL_Xlator/CharStream.java | 123 + .../SimpleExamples/NL_Xlator/NL_Xlator.java | 360 + .../NL_Xlator/NL_XlatorConstants.java | 35 + .../NL_Xlator/NL_XlatorTokenManager.java | 359 + .../NL_Xlator/ParseException.java | 187 + .../NL_Xlator/SimpleCharStream.java | 125 + .../SimpleExamples/NL_Xlator/Token.java | 130 + .../NL_Xlator/TokenMgrException.java | 144 + .../Simple1/AbstractCharStream.java | 543 ++ .../SimpleExamples/Simple1/CharStream.java | 123 + .../Simple1/ParseException.java | 187 + .../SimpleExamples/Simple1/Simple1.java | 282 + .../Simple1/Simple1Constants.java | 24 + .../Simple1/Simple1TokenManager.java | 248 + .../Simple1/SimpleCharStream.java | 125 + .../SimpleExamples/Simple1/Token.java | 130 + .../Simple1/TokenMgrException.java | 144 + .../Simple2/AbstractCharStream.java | 543 ++ .../SimpleExamples/Simple2/CharStream.java | 123 + .../Simple2/ParseException.java | 187 + .../SimpleExamples/Simple2/Simple2.java | 256 + .../Simple2/Simple2Constants.java | 26 + .../Simple2/Simple2TokenManager.java | 259 + .../Simple2/SimpleCharStream.java | 125 + .../SimpleExamples/Simple2/Token.java | 130 + .../Simple2/TokenMgrException.java | 144 + .../Simple3/AbstractCharStream.java | 543 ++ .../SimpleExamples/Simple3/CharStream.java | 123 + .../Simple3/ParseException.java | 187 + .../SimpleExamples/Simple3/Simple3.java | 259 + .../Simple3/Simple3Constants.java | 30 + .../Simple3/Simple3TokenManager.java | 259 + .../Simple3/SimpleCharStream.java | 125 + .../SimpleExamples/Simple3/Token.java | 130 + .../Simple3/TokenMgrException.java | 144 + 82 files changed, 26373 insertions(+) create mode 100644 src/test/java/com/helger/pgcc/parser/output/OutputTest.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/CharStream.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParser.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParserConstants.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCharStream.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/ParseException.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/Token.java create mode 100644 src/test/resources/outputTest/JavaCCGrammar/JavaCC/TokenMgrException.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/CharStream.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/Example.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/ExampleConstants.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/ExampleTokenManager.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/ParseException.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/Token.java create mode 100644 src/test/resources/outputTest/Lookahead/Example1/TokenMgrException.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/CharStream.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/Digest.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/DigestConstants.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/DigestTokenManager.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/ParseException.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/Token.java create mode 100644 src/test/resources/outputTest/MailProcessing/Digest/TokenMgrException.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/CharStream.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/Faq.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/FaqConstants.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/FaqTokenManager.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/ParseException.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/Token.java create mode 100644 src/test/resources/outputTest/MailProcessing/Faq/TokenMgrException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/CharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/IdList.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/IdListConstants.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/IdListTokenManager.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/ParseException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/Token.java create mode 100644 src/test/resources/outputTest/SimpleExamples/IdList/TokenMgrException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/CharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_Xlator.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorConstants.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorTokenManager.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/ParseException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/Token.java create mode 100644 src/test/resources/outputTest/SimpleExamples/NL_Xlator/TokenMgrException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/CharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/ParseException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/Simple1.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/Simple1Constants.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/Simple1TokenManager.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/Token.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple1/TokenMgrException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/CharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/ParseException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/Simple2.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/Simple2Constants.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/Simple2TokenManager.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/Token.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple2/TokenMgrException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/AbstractCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/CharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/ParseException.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/Simple3.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/Simple3Constants.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/Simple3TokenManager.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/SimpleCharStream.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/Token.java create mode 100644 src/test/resources/outputTest/SimpleExamples/Simple3/TokenMgrException.java diff --git a/src/test/java/com/helger/pgcc/AbstractJavaCCTestCase.java b/src/test/java/com/helger/pgcc/AbstractJavaCCTestCase.java index e21df191..1ba1f920 100644 --- a/src/test/java/com/helger/pgcc/AbstractJavaCCTestCase.java +++ b/src/test/java/com/helger/pgcc/AbstractJavaCCTestCase.java @@ -64,4 +64,34 @@ public String getJJInputDirectory () // return "src/org/javacc/parser/"; // return "src/main/javacc/org/javacc/parser/"; } + + /** + * Where the input jj files are located + * + * @return the directory name String relative to the root + */ + public String getTestResourcesDirectory () + { + return "src/test/resources/"; + } + + /** + * Where the examples files are located + * + * @return the directory name String relative to the root + */ + public String getExamplesDirectory () + { + return "examples/"; + } + + /** + * Where the target files are located + * + * @return the directory name String relative to the root + */ + public String getTargetDirectory () + { + return "target/"; + } } diff --git a/src/test/java/com/helger/pgcc/parser/output/OutputTest.java b/src/test/java/com/helger/pgcc/parser/output/OutputTest.java new file mode 100644 index 00000000..64b5ebf8 --- /dev/null +++ b/src/test/java/com/helger/pgcc/parser/output/OutputTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2017-2023 Philip Helger, pgcc@helger.com + * + * Copyright 2011 Google Inc. All Rights Reserved. + * Author: sreeni@google.com (Sreeni Viswanadha) + * + * Copyright (c) 2006, Sun Microsystems, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.helger.pgcc.parser.output; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.nio.charset.StandardCharsets; + +import org.junit.Test; + +import com.helger.commons.io.file.FileOperations; +import com.helger.commons.io.file.FileSystemIterator; +import com.helger.commons.io.file.SimpleFileIO; +import com.helger.pgcc.AbstractJavaCCTestCase; +import com.helger.pgcc.parser.Main; + +/** + * Test cases running some examples and checking to output to support + * output formating and refactorings. + * + * @author RBRi + */ +public final class OutputTest extends AbstractJavaCCTestCase +{ + @Test + public void simple1 () throws Exception + { + test("SimpleExamples/Simple1.jj"); + } + + @Test + public void simple2 () throws Exception + { + test("SimpleExamples/Simple2.jj"); + } + + @Test + public void simple3 () throws Exception + { + test("SimpleExamples/Simple3.jj"); + } + + @Test + public void simpleExamplesIdList () throws Exception + { + test("SimpleExamples/IdList.jj"); + } + + @Test + public void simpleExamplesNLXlator () throws Exception + { + test("SimpleExamples/NL_Xlator.jj"); + } + + @Test + public void javaCCGrammarJavaCC () throws Exception + { + test("JavaCCGrammar/JavaCC.jj"); + } + + @Test + public void lookaheadExample1 () throws Exception + { + test("Lookahead/Example1.jj"); + } + + @Test + public void mailProcessingDigest () throws Exception + { + test("MailProcessing/Digest.jj"); + } + + @Test + public void mailProcessingFaq () throws Exception + { + test("MailProcessing/Faq.jj"); + } + + private void test (String inputFile) throws Exception + { + File outputDirectory = new File(getTargetDirectory() + "outputTest"); + FileOperations.deleteDirRecursiveIfExisting(outputDirectory); + FileOperations.createDir(outputDirectory); + + String options = "-OUTPUT_DIRECTORY=" + outputDirectory.getAbsolutePath(); + + Main.mainProgram(new String[] {options, getExamplesDirectory () + inputFile}); + + // assert the result + File expectationDir = new File(getTestResourcesDirectory () + "outputTest/" + inputFile.substring(0, inputFile.lastIndexOf('.'))); + + FileSystemIterator generatedFiles = new FileSystemIterator(outputDirectory); + for (File generatedFile : generatedFiles) { + String generated = SimpleFileIO.getFileAsString(generatedFile, StandardCharsets.UTF_8); + + File expectedFile = new File(expectationDir, generatedFile.getName()); + String expected = SimpleFileIO.getFileAsString(expectedFile, StandardCharsets.UTF_8); + + assertEquals("The generated file '" + generatedFile.getName() + "' differs from the expected one.", expected, generated); + } + } +} diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/AbstractCharStream.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/CharStream.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParser.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParser.java new file mode 100644 index 00000000..717499ba --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParser.java @@ -0,0 +1,7659 @@ +/* JavaCCParser.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. JavaCCParser.java */ +public class JavaCCParser implements JavaCCParserConstants { + + public static void main(String args[]) { + JavaCCParser parser; + if (args.length == 0) { + System.out.println("JavaCC Parser: Reading from standard input . . ."); + parser = new JavaCCParser(System.in); + } else if (args.length == 1) { + System.out.println("JavaCC Parser: Reading from file " + args[0] + " . . ."); + try { + parser = new JavaCCParser(new java.io.FileInputStream(args[0])); + } catch (java.io.FileNotFoundException e) { + System.out.println("JavaCC Parser: File " + args[0] + " not found."); + return; + } + } else { + System.out.println("JavaCC Parser: Usage is one of:"); + System.out.println(" java JavaCCParser < inputfile"); + System.out.println("OR"); + System.out.println(" java JavaCCParser inputfile"); + return; + } + try { + parser.javacc_input(); + System.out.println("JavaCC Parser: Java program parsed successfully."); + } catch (ParseException e) { + System.out.println(e.getMessage()); + System.out.println("JavaCC Parser: Encountered errors during parse."); + } + } + + /* + * Returns true if the next token is not in the FOLLOW list of "expansion". + * It is used to decide when the end of an "expansion" has been reached. + */ + static private boolean notTailOfExpansionUnit() { + Token t; + t = getToken(1); + if (t.kind == BIT_OR || t.kind == COMMA || t.kind == RPAREN || t.kind == RBRACE || t.kind == RBRACKET) return false; + return true; + } + +/************************************************ + * THE JAVACC GRAMMAR SPECIFICATION STARTS HERE * + ************************************************/ + final public +void javacc_input() throws ParseException { + javacc_options(); + jj_consume_token(_PARSER_BEGIN); + jj_consume_token(LPAREN); + identifier(); + jj_consume_token(RPAREN); + CompilationUnit(); + jj_consume_token(_PARSER_END); + jj_consume_token(LPAREN); + identifier(); + jj_consume_token(RPAREN); + label_1: + while (true) { + production(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case VOID: + case IDENTIFIER: + case LT:{ + break; + } + default: + jj_la1[0] = jj_gen; + break label_1; + } + } + jj_consume_token(0); +} + + final public void javacc_options() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS:{ + jj_consume_token(_OPTIONS); + jj_consume_token(LBRACE); + label_2: + while (true) { + option_binding(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _LOOKAHEAD: + case _IGNORE_CASE: + case STATIC: + case IDENTIFIER:{ + break; + } + default: + jj_la1[1] = jj_gen; + break label_2; + } + } + jj_consume_token(RBRACE); + break; + } + default: + jj_la1[2] = jj_gen; + ; + } +} + + final public void option_binding() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case IDENTIFIER:{ + jj_consume_token(IDENTIFIER); + break; + } + case _LOOKAHEAD:{ + jj_consume_token(_LOOKAHEAD); + break; + } + case _IGNORE_CASE:{ + jj_consume_token(_IGNORE_CASE); + break; + } + case STATIC:{ + jj_consume_token(STATIC); + break; + } + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(ASSIGN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INTEGER_LITERAL:{ + IntegerLiteral(); + break; + } + case FALSE: + case TRUE:{ + BooleanLiteral(); + break; + } + case STRING_LITERAL:{ + StringLiteral(); + break; + } + default: + jj_la1[4] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + jj_consume_token(SEMICOLON); +} + + final public void production() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _JAVACODE:{ + javacode_production(); + break; + } + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case LT:{ + regular_expr_production(); + break; + } + case _TOKEN_MGR_DECLS:{ + token_manager_decls(); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case VOID: + case IDENTIFIER:{ + bnf_production(); + break; + } + default: + jj_la1[5] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void javacode_production() throws ParseException { + jj_consume_token(_JAVACODE); + ResultType(); + identifier(); + FormalParameters(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case THROWS:{ + jj_consume_token(THROWS); + Name(); + label_3: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[6] = jj_gen; + break label_3; + } + jj_consume_token(COMMA); + Name(); + } + break; + } + default: + jj_la1[7] = jj_gen; + ; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 126:{ + node_descriptor(); + break; + } + default: + jj_la1[8] = jj_gen; + ; + } + Block(); +} + + final public void bnf_production() throws ParseException { + ResultType(); + identifier(); + FormalParameters(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case THROWS:{ + jj_consume_token(THROWS); + Name(); + label_4: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[9] = jj_gen; + break label_4; + } + jj_consume_token(COMMA); + Name(); + } + break; + } + default: + jj_la1[10] = jj_gen; + ; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 126:{ + node_descriptor(); + break; + } + default: + jj_la1[11] = jj_gen; + ; + } + jj_consume_token(COLON); + Block(); + jj_consume_token(LBRACE); + expansion_choices(); + jj_consume_token(RBRACE); +} + + final public void regular_expr_production() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LT:{ + if (jj_2_1(2)) { + jj_consume_token(LT); + jj_consume_token(STAR); + jj_consume_token(GT); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LT:{ + jj_consume_token(LT); + jj_consume_token(IDENTIFIER); + label_5: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[12] = jj_gen; + break label_5; + } + jj_consume_token(COMMA); + jj_consume_token(IDENTIFIER); + } + jj_consume_token(GT); + break; + } + default: + jj_la1[13] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + break; + } + default: + jj_la1[14] = jj_gen; + ; + } + regexpr_kind(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + jj_consume_token(LBRACKET); + jj_consume_token(_IGNORE_CASE); + jj_consume_token(RBRACKET); + break; + } + default: + jj_la1[15] = jj_gen; + ; + } + jj_consume_token(COLON); + jj_consume_token(LBRACE); + regexpr_spec(); + label_6: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BIT_OR:{ + break; + } + default: + jj_la1[16] = jj_gen; + break label_6; + } + jj_consume_token(BIT_OR); + regexpr_spec(); + } + jj_consume_token(RBRACE); +} + + final public void token_manager_decls() throws ParseException { + jj_consume_token(_TOKEN_MGR_DECLS); + jj_consume_token(COLON); + ClassBody(); +} + + final public void regexpr_kind() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _TOKEN:{ + jj_consume_token(_TOKEN); + break; + } + case _SPECIAL_TOKEN:{ + jj_consume_token(_SPECIAL_TOKEN); + break; + } + case _SKIP:{ + jj_consume_token(_SKIP); + break; + } + case _MORE:{ + jj_consume_token(_MORE); + break; + } + default: + jj_la1[17] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void regexpr_spec() throws ParseException { + regular_expression(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACE:{ + Block(); + break; + } + default: + jj_la1[18] = jj_gen; + ; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COLON:{ + jj_consume_token(COLON); + jj_consume_token(IDENTIFIER); + break; + } + default: + jj_la1[19] = jj_gen; + ; + } +} + + final public void expansion_choices() throws ParseException { + expansion(); + label_7: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BIT_OR:{ + break; + } + default: + jj_la1[20] = jj_gen; + break label_7; + } + jj_consume_token(BIT_OR); + expansion(); + } +} + + final public void expansion() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _LOOKAHEAD:{ + jj_consume_token(_LOOKAHEAD); + jj_consume_token(LPAREN); + local_lookahead(); + jj_consume_token(RPAREN); + break; + } + default: + jj_la1[21] = jj_gen; + ; + } + label_8: + while (true) { + expansion_unit(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 126:{ + node_descriptor(); + break; + } + default: + jj_la1[22] = jj_gen; + ; + } + if (notTailOfExpansionUnit()) { + } else { + break label_8; + } + } +} + + final public void local_lookahead() throws ParseException {boolean commaAtEnd = false, emptyLA = true; + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INTEGER_LITERAL:{ + IntegerLiteral(); +emptyLA = false; + break; + } + default: + jj_la1[23] = jj_gen; + ; + } + if (!emptyLA && (getToken(1).kind != RPAREN)) { + jj_consume_token(COMMA); +commaAtEnd = true; + } else { + ; + } + if (getToken(1).kind != RPAREN && getToken(1).kind != LBRACE) { + expansion_choices(); +emptyLA = false; commaAtEnd = false; + } else { + ; + } + if (!emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN)) { + jj_consume_token(COMMA); +commaAtEnd = true; + } else { + ; + } + if (emptyLA || commaAtEnd) { + jj_consume_token(LBRACE); + Expression(); + jj_consume_token(RBRACE); + } else { + ; + } +} + + final public void expansion_unit() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _LOOKAHEAD:{ + jj_consume_token(_LOOKAHEAD); + jj_consume_token(LPAREN); + local_lookahead(); + jj_consume_token(RPAREN); + break; + } + case LBRACE:{ + Block(); + break; + } + case LBRACKET:{ + jj_consume_token(LBRACKET); + expansion_choices(); + jj_consume_token(RBRACKET); + break; + } + case TRY:{ + jj_consume_token(TRY); + jj_consume_token(LBRACE); + expansion_choices(); + jj_consume_token(RBRACE); + label_9: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case CATCH:{ + break; + } + default: + jj_la1[24] = jj_gen; + break label_9; + } + jj_consume_token(CATCH); + jj_consume_token(LPAREN); + Name(); + jj_consume_token(IDENTIFIER); + jj_consume_token(RPAREN); + Block(); + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case FINALLY:{ + jj_consume_token(FINALLY); + Block(); + break; + } + default: + jj_la1[25] = jj_gen; + ; + } + break; + } + default: + jj_la1[29] = jj_gen; + if (jj_2_3(2147483647)) { + if (jj_2_2(2147483647)) { + PrimaryExpression(); + jj_consume_token(ASSIGN); + } else { + ; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STRING_LITERAL: + case LT:{ + regular_expression(); + break; + } + case IDENTIFIER:{ + identifier(); + Arguments(); + break; + } + default: + jj_la1[26] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LPAREN:{ + jj_consume_token(LPAREN); + expansion_choices(); + jj_consume_token(RPAREN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case HOOK: + case PLUS: + case STAR:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PLUS:{ + jj_consume_token(PLUS); + break; + } + case STAR:{ + jj_consume_token(STAR); + break; + } + case HOOK:{ + jj_consume_token(HOOK); + break; + } + default: + jj_la1[27] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[28] = jj_gen; + ; + } + break; + } + default: + jj_la1[30] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } +} + + final public void regular_expression() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STRING_LITERAL:{ + StringLiteral(); + break; + } + default: + jj_la1[33] = jj_gen; + if (jj_2_4(3)) { + jj_consume_token(LT); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case IDENTIFIER: + case 126:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 126:{ + jj_consume_token(126); + break; + } + default: + jj_la1[31] = jj_gen; + ; + } + identifier(); + jj_consume_token(COLON); + break; + } + default: + jj_la1[32] = jj_gen; + ; + } + complex_regular_expression_choices(); + jj_consume_token(GT); + } else if (jj_2_5(2)) { + jj_consume_token(LT); + identifier(); + jj_consume_token(GT); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LT:{ + jj_consume_token(LT); + jj_consume_token(_EOF); + jj_consume_token(GT); + break; + } + default: + jj_la1[34] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } +} + + final public void complex_regular_expression_choices() throws ParseException { + complex_regular_expression(); + label_10: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BIT_OR:{ + break; + } + default: + jj_la1[35] = jj_gen; + break label_10; + } + jj_consume_token(BIT_OR); + complex_regular_expression(); + } +} + + final public void complex_regular_expression() throws ParseException { + label_11: + while (true) { + complex_regular_expression_unit(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STRING_LITERAL: + case LPAREN: + case LBRACKET: + case LT: + case TILDE:{ + break; + } + default: + jj_la1[36] = jj_gen; + break label_11; + } + } +} + + final public void complex_regular_expression_unit() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STRING_LITERAL:{ + StringLiteral(); + break; + } + case LT:{ + jj_consume_token(LT); + identifier(); + jj_consume_token(GT); + break; + } + case LBRACKET: + case TILDE:{ + character_list(); + break; + } + case LPAREN:{ + jj_consume_token(LPAREN); + complex_regular_expression_choices(); + jj_consume_token(RPAREN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case HOOK: + case PLUS: + case STAR:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PLUS:{ + jj_consume_token(PLUS); + break; + } + case STAR:{ + jj_consume_token(STAR); + break; + } + case HOOK:{ + jj_consume_token(HOOK); + break; + } + default: + jj_la1[37] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[38] = jj_gen; + ; + } + break; + } + default: + jj_la1[39] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void character_list() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case TILDE:{ + jj_consume_token(TILDE); + break; + } + default: + jj_la1[40] = jj_gen; + ; + } + jj_consume_token(LBRACKET); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STRING_LITERAL:{ + character_descriptor(); + label_12: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[41] = jj_gen; + break label_12; + } + jj_consume_token(COMMA); + character_descriptor(); + } + break; + } + default: + jj_la1[42] = jj_gen; + ; + } + jj_consume_token(RBRACKET); +} + + final public void character_descriptor() throws ParseException { + StringLiteral(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case MINUS:{ + jj_consume_token(MINUS); + StringLiteral(); + break; + } + default: + jj_la1[43] = jj_gen; + ; + } +} + + final public void identifier() throws ParseException { + jj_consume_token(IDENTIFIER); +} + +/********************************************** + * THE JJTREE PRODUCTIONS START HERE * + **********************************************/ + final public +void node_descriptor() throws ParseException { + jj_consume_token(126); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case IDENTIFIER:{ + jj_consume_token(IDENTIFIER); + break; + } + case VOID:{ + jj_consume_token(VOID); + break; + } + default: + jj_la1[44] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LPAREN:{ + jj_consume_token(LPAREN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case GT:{ + jj_consume_token(GT); + break; + } + default: + jj_la1[45] = jj_gen; + ; + } + node_descriptor_expression(); + jj_consume_token(RPAREN); + break; + } + default: + jj_la1[46] = jj_gen; + ; + } +} + + void node_descriptor_expression() throws ParseException {Token tok; + int nesting = 1; + while (true) { + tok = getToken(1); + if (tok.kind == 0) { + throw new ParseException(); + } + if (tok.kind == LPAREN) nesting++; + if (tok.kind == RPAREN) { + nesting--; + if (nesting == 0) break; + } + tok = getNextToken(); + } + } + +/********************************************** + * THE JAVA GRAMMAR SPECIFICATION STARTS HERE * + **********************************************/ + +/* + * The Java grammar is modified to use sequences of tokens + * for the missing tokens - those that include "<<" and ">>". + */ + +/* + * The following production defines Java identifiers - it + * includes the reserved words of JavaCC also. + */ + final public +void JavaIdentifier() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case IDENTIFIER:{ + jj_consume_token(IDENTIFIER); + break; + } + case _OPTIONS:{ + jj_consume_token(_OPTIONS); + break; + } + case _LOOKAHEAD:{ + jj_consume_token(_LOOKAHEAD); + break; + } + case _IGNORE_CASE:{ + jj_consume_token(_IGNORE_CASE); + break; + } + case _PARSER_BEGIN:{ + jj_consume_token(_PARSER_BEGIN); + break; + } + case _PARSER_END:{ + jj_consume_token(_PARSER_END); + break; + } + case _JAVACODE:{ + jj_consume_token(_JAVACODE); + break; + } + case _TOKEN:{ + jj_consume_token(_TOKEN); + break; + } + case _SPECIAL_TOKEN:{ + jj_consume_token(_SPECIAL_TOKEN); + break; + } + case _MORE:{ + jj_consume_token(_MORE); + break; + } + case _SKIP:{ + jj_consume_token(_SKIP); + break; + } + case _TOKEN_MGR_DECLS:{ + jj_consume_token(_TOKEN_MGR_DECLS); + break; + } + case _EOF:{ + jj_consume_token(_EOF); + break; + } + default: + jj_la1[47] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + +/* + * The productions for the missing code follows. Obviously + * these productions accept more than what is legal in Java, + * but that is OK for our purposes. + */ + final public +void ShiftOps() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LT:{ + jj_consume_token(LT); + jj_consume_token(LT); + break; + } + case GT:{ + jj_consume_token(GT); + jj_consume_token(GT); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case GT:{ + jj_consume_token(GT); + break; + } + default: + jj_la1[48] = jj_gen; + ; + } + break; + } + default: + jj_la1[49] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void OtherAssignmentOps() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LT:{ + jj_consume_token(LT); + jj_consume_token(LE); + break; + } + case GT:{ + jj_consume_token(GT); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case GT:{ + jj_consume_token(GT); + break; + } + default: + jj_la1[50] = jj_gen; + ; + } + jj_consume_token(GE); + break; + } + default: + jj_la1[51] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + +/* + * Program structuring syntax follows. + */ + final public +void CompilationUnit() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PACKAGE:{ + PackageDeclaration(); + break; + } + default: + jj_la1[52] = jj_gen; + ; + } + label_13: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case IMPORT:{ + break; + } + default: + jj_la1[53] = jj_gen; + break label_13; + } + ImportDeclaration(); + } + label_14: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case CLASS: + case FINAL: + case INTERFACE: + case PUBLIC: + case SEMICOLON:{ + break; + } + default: + jj_la1[54] = jj_gen; + break label_14; + } + TypeDeclaration(); + } +} + + final public void JavaCompilationUnit() throws ParseException { + CompilationUnit(); + jj_consume_token(0); +} + + final public void PackageDeclaration() throws ParseException { + jj_consume_token(PACKAGE); + Name(); + jj_consume_token(SEMICOLON); +} + + final public void ImportDeclaration() throws ParseException { + jj_consume_token(IMPORT); + Name(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case DOT:{ + jj_consume_token(DOT); + jj_consume_token(STAR); + break; + } + default: + jj_la1[55] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +} + + final public void TypeDeclaration() throws ParseException { + if (jj_2_6(2147483647)) { + ClassDeclaration(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case INTERFACE: + case PUBLIC:{ + InterfaceDeclaration(); + break; + } + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[56] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + +/* + * Declaration syntax follows. + */ + final public +void ClassDeclaration() throws ParseException { + label_15: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case FINAL: + case PUBLIC:{ + break; + } + default: + jj_la1[57] = jj_gen; + break label_15; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT:{ + jj_consume_token(ABSTRACT); + break; + } + case FINAL:{ + jj_consume_token(FINAL); + break; + } + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + default: + jj_la1[58] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + UnmodifiedClassDeclaration(); +} + + final public void UnmodifiedClassDeclaration() throws ParseException { + jj_consume_token(CLASS); + JavaIdentifier(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case EXTENDS:{ + jj_consume_token(EXTENDS); + Name(); + break; + } + default: + jj_la1[59] = jj_gen; + ; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case IMPLEMENTS:{ + jj_consume_token(IMPLEMENTS); + NameList(); + break; + } + default: + jj_la1[60] = jj_gen; + ; + } + ClassBody(); +} + + final public void ClassBody() throws ParseException { + jj_consume_token(LBRACE); + label_16: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case DOUBLE: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case SYNCHRONIZED: + case TRANSIENT: + case VOID: + case VOLATILE: + case IDENTIFIER: + case LBRACE:{ + break; + } + default: + jj_la1[61] = jj_gen; + break label_16; + } + ClassBodyDeclaration(); + } + jj_consume_token(RBRACE); +} + + final public void NestedClassDeclaration() throws ParseException { + label_17: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case FINAL: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case STATIC:{ + break; + } + default: + jj_la1[62] = jj_gen; + break label_17; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STATIC:{ + jj_consume_token(STATIC); + break; + } + case ABSTRACT:{ + jj_consume_token(ABSTRACT); + break; + } + case FINAL:{ + jj_consume_token(FINAL); + break; + } + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + case PROTECTED:{ + jj_consume_token(PROTECTED); + break; + } + case PRIVATE:{ + jj_consume_token(PRIVATE); + break; + } + default: + jj_la1[63] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + UnmodifiedClassDeclaration(); +} + + final public void ClassBodyDeclaration() throws ParseException { + if (jj_2_7(2)) { + Initializer(); + } else if (jj_2_8(2147483647)) { + NestedClassDeclaration(); + } else if (jj_2_9(2147483647)) { + NestedInterfaceDeclaration(); + } else if (jj_2_10(2147483647)) { + ConstructorDeclaration(); + } else if (jj_2_11(2147483647)) { + MethodDeclaration(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FINAL: + case FLOAT: + case INT: + case LONG: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case TRANSIENT: + case VOLATILE: + case IDENTIFIER:{ + FieldDeclaration(); + break; + } + default: + jj_la1[64] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + +// This production is to determine lookahead only. + final public void MethodDeclarationLookahead() throws ParseException { + label_18: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case FINAL: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case STATIC: + case SYNCHRONIZED:{ + break; + } + default: + jj_la1[65] = jj_gen; + break label_18; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + case PROTECTED:{ + jj_consume_token(PROTECTED); + break; + } + case PRIVATE:{ + jj_consume_token(PRIVATE); + break; + } + case STATIC:{ + jj_consume_token(STATIC); + break; + } + case ABSTRACT:{ + jj_consume_token(ABSTRACT); + break; + } + case FINAL:{ + jj_consume_token(FINAL); + break; + } + case NATIVE:{ + jj_consume_token(NATIVE); + break; + } + case SYNCHRONIZED:{ + jj_consume_token(SYNCHRONIZED); + break; + } + default: + jj_la1[66] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + ResultType(); + JavaIdentifier(); + jj_consume_token(LPAREN); +} + + final public void InterfaceDeclaration() throws ParseException { + label_19: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case PUBLIC:{ + break; + } + default: + jj_la1[67] = jj_gen; + break label_19; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT:{ + jj_consume_token(ABSTRACT); + break; + } + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + default: + jj_la1[68] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + UnmodifiedInterfaceDeclaration(); +} + + final public void NestedInterfaceDeclaration() throws ParseException { + label_20: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case FINAL: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case STATIC:{ + break; + } + default: + jj_la1[69] = jj_gen; + break label_20; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STATIC:{ + jj_consume_token(STATIC); + break; + } + case ABSTRACT:{ + jj_consume_token(ABSTRACT); + break; + } + case FINAL:{ + jj_consume_token(FINAL); + break; + } + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + case PROTECTED:{ + jj_consume_token(PROTECTED); + break; + } + case PRIVATE:{ + jj_consume_token(PRIVATE); + break; + } + default: + jj_la1[70] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + UnmodifiedInterfaceDeclaration(); +} + + final public void UnmodifiedInterfaceDeclaration() throws ParseException { + jj_consume_token(INTERFACE); + JavaIdentifier(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case EXTENDS:{ + jj_consume_token(EXTENDS); + NameList(); + break; + } + default: + jj_la1[71] = jj_gen; + ; + } + jj_consume_token(LBRACE); + label_21: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case ABSTRACT: + case BOOLEAN: + case BYTE: + case CHAR: + case CLASS: + case DOUBLE: + case FINAL: + case FLOAT: + case INT: + case INTERFACE: + case LONG: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case SYNCHRONIZED: + case TRANSIENT: + case VOID: + case VOLATILE: + case IDENTIFIER:{ + break; + } + default: + jj_la1[72] = jj_gen; + break label_21; + } + InterfaceMemberDeclaration(); + } + jj_consume_token(RBRACE); +} + + final public void InterfaceMemberDeclaration() throws ParseException { + if (jj_2_12(2147483647)) { + NestedClassDeclaration(); + } else if (jj_2_13(2147483647)) { + NestedInterfaceDeclaration(); + } else if (jj_2_14(2147483647)) { + MethodDeclaration(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FINAL: + case FLOAT: + case INT: + case LONG: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case SHORT: + case STATIC: + case TRANSIENT: + case VOLATILE: + case IDENTIFIER:{ + FieldDeclaration(); + break; + } + default: + jj_la1[73] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + + final public void FieldDeclaration() throws ParseException { + label_22: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case FINAL: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case STATIC: + case TRANSIENT: + case VOLATILE:{ + break; + } + default: + jj_la1[74] = jj_gen; + break label_22; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + case PROTECTED:{ + jj_consume_token(PROTECTED); + break; + } + case PRIVATE:{ + jj_consume_token(PRIVATE); + break; + } + case STATIC:{ + jj_consume_token(STATIC); + break; + } + case FINAL:{ + jj_consume_token(FINAL); + break; + } + case TRANSIENT:{ + jj_consume_token(TRANSIENT); + break; + } + case VOLATILE:{ + jj_consume_token(VOLATILE); + break; + } + default: + jj_la1[75] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + Type(); + VariableDeclarator(); + label_23: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[76] = jj_gen; + break label_23; + } + jj_consume_token(COMMA); + VariableDeclarator(); + } + jj_consume_token(SEMICOLON); +} + + final public void VariableDeclarator() throws ParseException { + VariableDeclaratorId(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ASSIGN:{ + jj_consume_token(ASSIGN); + VariableInitializer(); + break; + } + default: + jj_la1[77] = jj_gen; + ; + } +} + + final public void VariableDeclaratorId() throws ParseException { + JavaIdentifier(); + label_24: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + break; + } + default: + jj_la1[78] = jj_gen; + break label_24; + } + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } +} + + final public void VariableInitializer() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACE:{ + ArrayInitializer(); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + Expression(); + break; + } + default: + jj_la1[79] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void ArrayInitializer() throws ParseException { + jj_consume_token(LBRACE); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + VariableInitializer(); + label_25: + while (true) { + if (jj_2_15(2)) { + } else { + break label_25; + } + jj_consume_token(COMMA); + VariableInitializer(); + } + break; + } + default: + jj_la1[80] = jj_gen; + ; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + jj_consume_token(COMMA); + break; + } + default: + jj_la1[81] = jj_gen; + ; + } + jj_consume_token(RBRACE); +} + + final public void MethodDeclaration() throws ParseException { + label_26: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ABSTRACT: + case FINAL: + case NATIVE: + case PRIVATE: + case PROTECTED: + case PUBLIC: + case STATIC: + case SYNCHRONIZED:{ + break; + } + default: + jj_la1[82] = jj_gen; + break label_26; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + case PROTECTED:{ + jj_consume_token(PROTECTED); + break; + } + case PRIVATE:{ + jj_consume_token(PRIVATE); + break; + } + case STATIC:{ + jj_consume_token(STATIC); + break; + } + case ABSTRACT:{ + jj_consume_token(ABSTRACT); + break; + } + case FINAL:{ + jj_consume_token(FINAL); + break; + } + case NATIVE:{ + jj_consume_token(NATIVE); + break; + } + case SYNCHRONIZED:{ + jj_consume_token(SYNCHRONIZED); + break; + } + default: + jj_la1[83] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + ResultType(); + MethodDeclarator(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case THROWS:{ + jj_consume_token(THROWS); + NameList(); + break; + } + default: + jj_la1[84] = jj_gen; + ; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACE:{ + Block(); + break; + } + case SEMICOLON:{ + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[85] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void MethodDeclarator() throws ParseException { + JavaIdentifier(); + FormalParameters(); + label_27: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + break; + } + default: + jj_la1[86] = jj_gen; + break label_27; + } + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } +} + + final public void FormalParameters() throws ParseException { + jj_consume_token(LPAREN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FINAL: + case FLOAT: + case INT: + case LONG: + case SHORT: + case IDENTIFIER:{ + FormalParameter(); + label_28: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[87] = jj_gen; + break label_28; + } + jj_consume_token(COMMA); + FormalParameter(); + } + break; + } + default: + jj_la1[88] = jj_gen; + ; + } + jj_consume_token(RPAREN); +} + + final public void FormalParameter() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case FINAL:{ + jj_consume_token(FINAL); + break; + } + default: + jj_la1[89] = jj_gen; + ; + } + Type(); + VariableDeclaratorId(); +} + + final public void ConstructorDeclaration() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PRIVATE: + case PROTECTED: + case PUBLIC:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PUBLIC:{ + jj_consume_token(PUBLIC); + break; + } + case PROTECTED:{ + jj_consume_token(PROTECTED); + break; + } + case PRIVATE:{ + jj_consume_token(PRIVATE); + break; + } + default: + jj_la1[90] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[91] = jj_gen; + ; + } + JavaIdentifier(); + FormalParameters(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case THROWS:{ + jj_consume_token(THROWS); + NameList(); + break; + } + default: + jj_la1[92] = jj_gen; + ; + } + jj_consume_token(LBRACE); + if (jj_2_16(2147483647)) { + ExplicitConstructorInvocation(); + } else { + ; + } + label_29: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CLASS: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case FINAL: + case FLOAT: + case FOR: + case IF: + case INT: + case INTERFACE: + case LONG: + case NEW: + case NULL: + case RETURN: + case SHORT: + case SUPER: + case SWITCH: + case SYNCHRONIZED: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR:{ + break; + } + default: + jj_la1[93] = jj_gen; + break label_29; + } + BlockStatement(); + } + jj_consume_token(RBRACE); +} + + final public void ExplicitConstructorInvocation() throws ParseException { + if (jj_2_18(2147483647)) { + jj_consume_token(THIS); + Arguments(); + jj_consume_token(SEMICOLON); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN:{ + if (jj_2_17(2)) { + PrimaryExpression(); + jj_consume_token(DOT); + } else { + ; + } + jj_consume_token(SUPER); + Arguments(); + jj_consume_token(SEMICOLON); + break; + } + default: + jj_la1[94] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + + final public void Initializer() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STATIC:{ + jj_consume_token(STATIC); + break; + } + default: + jj_la1[95] = jj_gen; + ; + } + Block(); +} + +/* + * Type, name and expression syntax follows. + */ + final public +void Type() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT:{ + PrimitiveType(); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case IDENTIFIER:{ + Name(); + break; + } + default: + jj_la1[96] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + label_30: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + break; + } + default: + jj_la1[97] = jj_gen; + break label_30; + } + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } +} + + final public void PrimitiveType() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BOOLEAN:{ + jj_consume_token(BOOLEAN); + break; + } + case CHAR:{ + jj_consume_token(CHAR); + break; + } + case BYTE:{ + jj_consume_token(BYTE); + break; + } + case SHORT:{ + jj_consume_token(SHORT); + break; + } + case INT:{ + jj_consume_token(INT); + break; + } + case LONG:{ + jj_consume_token(LONG); + break; + } + case FLOAT:{ + jj_consume_token(FLOAT); + break; + } + case DOUBLE:{ + jj_consume_token(DOUBLE); + break; + } + default: + jj_la1[98] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void ResultType() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case VOID:{ + jj_consume_token(VOID); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FLOAT: + case INT: + case LONG: + case SHORT: + case IDENTIFIER:{ + Type(); + break; + } + default: + jj_la1[99] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void Name() throws ParseException { + JavaIdentifier(); + label_31: + while (true) { + if (jj_2_19(2)) { + } else { + break label_31; + } + jj_consume_token(DOT); + JavaIdentifier(); + } +} + + final public void NameList() throws ParseException { + Name(); + label_32: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[100] = jj_gen; + break label_32; + } + jj_consume_token(COMMA); + Name(); + } +} + +/* + * Expression syntax follows. + */ + final public +void Expression() throws ParseException { + ConditionalExpression(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ASSIGN: + case GT: + case LT: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN:{ + AssignmentOperator(); + Expression(); + break; + } + default: + jj_la1[101] = jj_gen; + ; + } +} + + final public void AssignmentOperator() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ASSIGN:{ + jj_consume_token(ASSIGN); + break; + } + case STARASSIGN:{ + jj_consume_token(STARASSIGN); + break; + } + case SLASHASSIGN:{ + jj_consume_token(SLASHASSIGN); + break; + } + case REMASSIGN:{ + jj_consume_token(REMASSIGN); + break; + } + case PLUSASSIGN:{ + jj_consume_token(PLUSASSIGN); + break; + } + case MINUSASSIGN:{ + jj_consume_token(MINUSASSIGN); + break; + } + case ANDASSIGN:{ + jj_consume_token(ANDASSIGN); + break; + } + case XORASSIGN:{ + jj_consume_token(XORASSIGN); + break; + } + case ORASSIGN:{ + jj_consume_token(ORASSIGN); + break; + } + case GT: + case LT:{ + OtherAssignmentOps(); + break; + } + default: + jj_la1[102] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void ConditionalExpression() throws ParseException { + ConditionalOrExpression(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case HOOK:{ + jj_consume_token(HOOK); + Expression(); + jj_consume_token(COLON); + ConditionalExpression(); + break; + } + default: + jj_la1[103] = jj_gen; + ; + } +} + + final public void ConditionalOrExpression() throws ParseException { + ConditionalAndExpression(); + label_33: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SC_OR:{ + break; + } + default: + jj_la1[104] = jj_gen; + break label_33; + } + jj_consume_token(SC_OR); + ConditionalAndExpression(); + } +} + + final public void ConditionalAndExpression() throws ParseException { + InclusiveOrExpression(); + label_34: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SC_AND:{ + break; + } + default: + jj_la1[105] = jj_gen; + break label_34; + } + jj_consume_token(SC_AND); + InclusiveOrExpression(); + } +} + + final public void InclusiveOrExpression() throws ParseException { + ExclusiveOrExpression(); + label_35: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BIT_OR:{ + break; + } + default: + jj_la1[106] = jj_gen; + break label_35; + } + jj_consume_token(BIT_OR); + ExclusiveOrExpression(); + } +} + + final public void ExclusiveOrExpression() throws ParseException { + AndExpression(); + label_36: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case XOR:{ + break; + } + default: + jj_la1[107] = jj_gen; + break label_36; + } + jj_consume_token(XOR); + AndExpression(); + } +} + + final public void AndExpression() throws ParseException { + EqualityExpression(); + label_37: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BIT_AND:{ + break; + } + default: + jj_la1[108] = jj_gen; + break label_37; + } + jj_consume_token(BIT_AND); + EqualityExpression(); + } +} + + final public void EqualityExpression() throws ParseException { + InstanceOfExpression(); + label_38: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case EQ: + case NE:{ + break; + } + default: + jj_la1[109] = jj_gen; + break label_38; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case EQ:{ + jj_consume_token(EQ); + break; + } + case NE:{ + jj_consume_token(NE); + break; + } + default: + jj_la1[110] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + InstanceOfExpression(); + } +} + + final public void InstanceOfExpression() throws ParseException { + RelationalExpression(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INSTANCEOF:{ + jj_consume_token(INSTANCEOF); + Type(); + break; + } + default: + jj_la1[111] = jj_gen; + ; + } +} + + final public void RelationalExpression() throws ParseException { + ShiftExpression(); + label_39: + while (true) { + if (jj_2_20(2)) { + } else { + break label_39; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LT:{ + jj_consume_token(LT); + break; + } + case GT:{ + jj_consume_token(GT); + break; + } + case LE:{ + jj_consume_token(LE); + break; + } + case GE:{ + jj_consume_token(GE); + break; + } + default: + jj_la1[112] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + ShiftExpression(); + } +} + + final public void ShiftExpression() throws ParseException { + AdditiveExpression(); + label_40: + while (true) { + if (jj_2_21(3)) { + } else { + break label_40; + } + ShiftOps(); + AdditiveExpression(); + } +} + + final public void AdditiveExpression() throws ParseException { + MultiplicativeExpression(); + label_41: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PLUS: + case MINUS:{ + break; + } + default: + jj_la1[113] = jj_gen; + break label_41; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PLUS:{ + jj_consume_token(PLUS); + break; + } + case MINUS:{ + jj_consume_token(MINUS); + break; + } + default: + jj_la1[114] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + MultiplicativeExpression(); + } +} + + final public void MultiplicativeExpression() throws ParseException { + UnaryExpression(); + label_42: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STAR: + case SLASH: + case REM:{ + break; + } + default: + jj_la1[115] = jj_gen; + break label_42; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case STAR:{ + jj_consume_token(STAR); + break; + } + case SLASH:{ + jj_consume_token(SLASH); + break; + } + case REM:{ + jj_consume_token(REM); + break; + } + default: + jj_la1[116] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + UnaryExpression(); + } +} + + final public void UnaryExpression() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PLUS: + case MINUS:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case PLUS:{ + jj_consume_token(PLUS); + break; + } + case MINUS:{ + jj_consume_token(MINUS); + break; + } + default: + jj_la1[117] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + UnaryExpression(); + break; + } + case INCR:{ + PreIncrementExpression(); + break; + } + case DECR:{ + PreDecrementExpression(); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case BANG: + case TILDE:{ + UnaryExpressionNotPlusMinus(); + break; + } + default: + jj_la1[118] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void PreIncrementExpression() throws ParseException { + jj_consume_token(INCR); + PrimaryExpression(); +} + + final public void PreDecrementExpression() throws ParseException { + jj_consume_token(DECR); + PrimaryExpression(); +} + + final public void UnaryExpressionNotPlusMinus() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BANG: + case TILDE:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case TILDE:{ + jj_consume_token(TILDE); + break; + } + case BANG:{ + jj_consume_token(BANG); + break; + } + default: + jj_la1[119] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + UnaryExpression(); + break; + } + default: + jj_la1[120] = jj_gen; + if (jj_2_22(2147483647)) { + CastExpression(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN:{ + PostfixExpression(); + break; + } + default: + jj_la1[121] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } +} + +// This production is to determine lookahead only. The LOOKAHEAD specifications +// below are not used, but they are there just to indicate that we know about +// this. + final public void CastLookahead() throws ParseException { + if (jj_2_23(2)) { + jj_consume_token(LPAREN); + PrimitiveType(); + } else if (jj_2_24(2147483647)) { + jj_consume_token(LPAREN); + Name(); + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LPAREN:{ + jj_consume_token(LPAREN); + Name(); + jj_consume_token(RPAREN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case TILDE:{ + jj_consume_token(TILDE); + break; + } + case BANG:{ + jj_consume_token(BANG); + break; + } + case LPAREN:{ + jj_consume_token(LPAREN); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case IDENTIFIER:{ + JavaIdentifier(); + break; + } + case THIS:{ + jj_consume_token(THIS); + break; + } + case SUPER:{ + jj_consume_token(SUPER); + break; + } + case NEW:{ + jj_consume_token(NEW); + break; + } + case FALSE: + case NULL: + case TRUE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL:{ + Literal(); + break; + } + default: + jj_la1[122] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[123] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + + final public void PostfixExpression() throws ParseException { + PrimaryExpression(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INCR: + case DECR:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INCR:{ + jj_consume_token(INCR); + break; + } + case DECR:{ + jj_consume_token(DECR); + break; + } + default: + jj_la1[124] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[125] = jj_gen; + ; + } +} + + final public void CastExpression() throws ParseException { + if (jj_2_25(2147483647)) { + jj_consume_token(LPAREN); + Type(); + jj_consume_token(RPAREN); + UnaryExpression(); + } else if (jj_2_26(2147483647)) { + jj_consume_token(LPAREN); + Type(); + jj_consume_token(RPAREN); + UnaryExpressionNotPlusMinus(); + } else { + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void PrimaryExpression() throws ParseException { + PrimaryPrefix(); + label_43: + while (true) { + if (jj_2_27(2)) { + } else { + break label_43; + } + PrimarySuffix(); + } +} + + final public void PrimaryPrefix() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case FALSE: + case NULL: + case TRUE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL:{ + Literal(); + break; + } + case THIS:{ + jj_consume_token(THIS); + break; + } + case SUPER:{ + jj_consume_token(SUPER); + jj_consume_token(DOT); + JavaIdentifier(); + break; + } + case LPAREN:{ + jj_consume_token(LPAREN); + Expression(); + jj_consume_token(RPAREN); + break; + } + case NEW:{ + AllocationExpression(); + break; + } + default: + jj_la1[126] = jj_gen; + if (jj_2_28(2147483647)) { + ResultType(); + jj_consume_token(DOT); + jj_consume_token(CLASS); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case IDENTIFIER:{ + Name(); + break; + } + default: + jj_la1[127] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + } +} + + final public void PrimarySuffix() throws ParseException { + if (jj_2_29(2)) { + jj_consume_token(DOT); + jj_consume_token(THIS); + } else if (jj_2_30(2)) { + jj_consume_token(DOT); + AllocationExpression(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + jj_consume_token(LBRACKET); + Expression(); + jj_consume_token(RBRACKET); + break; + } + case DOT:{ + jj_consume_token(DOT); + JavaIdentifier(); + break; + } + case LPAREN:{ + Arguments(); + break; + } + default: + jj_la1[128] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + + final public void Literal() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INTEGER_LITERAL:{ + jj_consume_token(INTEGER_LITERAL); + break; + } + case FLOATING_POINT_LITERAL:{ + jj_consume_token(FLOATING_POINT_LITERAL); + break; + } + case CHARACTER_LITERAL:{ + jj_consume_token(CHARACTER_LITERAL); + break; + } + case STRING_LITERAL:{ + jj_consume_token(STRING_LITERAL); + break; + } + case FALSE: + case TRUE:{ + BooleanLiteral(); + break; + } + case NULL:{ + NullLiteral(); + break; + } + default: + jj_la1[129] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void IntegerLiteral() throws ParseException { + jj_consume_token(INTEGER_LITERAL); +} + + final public void BooleanLiteral() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case TRUE:{ + jj_consume_token(TRUE); + break; + } + case FALSE:{ + jj_consume_token(FALSE); + break; + } + default: + jj_la1[130] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void StringLiteral() throws ParseException { + jj_consume_token(STRING_LITERAL); +} + + final public void NullLiteral() throws ParseException { + jj_consume_token(NULL); +} + + final public void Arguments() throws ParseException { + jj_consume_token(LPAREN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + ArgumentList(); + break; + } + default: + jj_la1[131] = jj_gen; + ; + } + jj_consume_token(RPAREN); +} + + final public void ArgumentList() throws ParseException { + Expression(); + label_44: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[132] = jj_gen; + break label_44; + } + jj_consume_token(COMMA); + Expression(); + } +} + + final public void AllocationExpression() throws ParseException { + if (jj_2_31(2)) { + jj_consume_token(NEW); + PrimitiveType(); + ArrayDimsAndInits(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case NEW:{ + jj_consume_token(NEW); + Name(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + ArrayDimsAndInits(); + break; + } + case LPAREN:{ + Arguments(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACE:{ + ClassBody(); + break; + } + default: + jj_la1[133] = jj_gen; + ; + } + break; + } + default: + jj_la1[134] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[135] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + +/* + * The second LOOKAHEAD specification below is to parse to PrimarySuffix + * if there is an expression between the "[...]". + */ + final public void ArrayDimsAndInits() throws ParseException { + if (jj_2_34(2)) { + label_45: + while (true) { + jj_consume_token(LBRACKET); + Expression(); + jj_consume_token(RBRACKET); + if (jj_2_32(2)) { + } else { + break label_45; + } + } + label_46: + while (true) { + if (jj_2_33(2)) { + } else { + break label_46; + } + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + } + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + label_47: + while (true) { + jj_consume_token(LBRACKET); + jj_consume_token(RBRACKET); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACKET:{ + break; + } + default: + jj_la1[136] = jj_gen; + break label_47; + } + } + ArrayInitializer(); + break; + } + default: + jj_la1[137] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + +/* + * Statement syntax follows. + */ + final public +void Statement() throws ParseException { + if (jj_2_35(2)) { + LabeledStatement(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACE:{ + Block(); + break; + } + case SEMICOLON:{ + EmptyStatement(); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case INCR: + case DECR:{ + StatementExpression(); + jj_consume_token(SEMICOLON); + break; + } + case SWITCH:{ + SwitchStatement(); + break; + } + case IF:{ + IfStatement(); + break; + } + case WHILE:{ + WhileStatement(); + break; + } + case DO:{ + DoStatement(); + break; + } + case FOR:{ + ForStatement(); + break; + } + case BREAK:{ + BreakStatement(); + break; + } + case CONTINUE:{ + ContinueStatement(); + break; + } + case RETURN:{ + ReturnStatement(); + break; + } + case THROW:{ + ThrowStatement(); + break; + } + case SYNCHRONIZED:{ + SynchronizedStatement(); + break; + } + case TRY:{ + TryStatement(); + break; + } + default: + jj_la1[138] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + + final public void LabeledStatement() throws ParseException { + JavaIdentifier(); + jj_consume_token(COLON); + Statement(); +} + + final public void Block() throws ParseException { + jj_consume_token(LBRACE); + label_48: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CLASS: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case FINAL: + case FLOAT: + case FOR: + case IF: + case INT: + case INTERFACE: + case LONG: + case NEW: + case NULL: + case RETURN: + case SHORT: + case SUPER: + case SWITCH: + case SYNCHRONIZED: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR:{ + break; + } + default: + jj_la1[139] = jj_gen; + break label_48; + } + BlockStatement(); + } + jj_consume_token(RBRACE); +} + + final public void BlockStatement() throws ParseException { + if (jj_2_36(2147483647)) { + LocalVariableDeclaration(); + jj_consume_token(SEMICOLON); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case FLOAT: + case FOR: + case IF: + case INT: + case LONG: + case NEW: + case NULL: + case RETURN: + case SHORT: + case SUPER: + case SWITCH: + case SYNCHRONIZED: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR:{ + Statement(); + break; + } + case CLASS:{ + UnmodifiedClassDeclaration(); + break; + } + case INTERFACE:{ + UnmodifiedInterfaceDeclaration(); + break; + } + default: + jj_la1[140] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + + final public void LocalVariableDeclaration() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case FINAL:{ + jj_consume_token(FINAL); + break; + } + default: + jj_la1[141] = jj_gen; + ; + } + Type(); + VariableDeclarator(); + label_49: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[142] = jj_gen; + break label_49; + } + jj_consume_token(COMMA); + VariableDeclarator(); + } +} + + final public void EmptyStatement() throws ParseException { + jj_consume_token(SEMICOLON); +} + + final public void StatementExpression() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INCR:{ + PreIncrementExpression(); + break; + } + case DECR:{ + PreDecrementExpression(); + break; + } + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN:{ + PrimaryExpression(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ASSIGN: + case GT: + case LT: + case INCR: + case DECR: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN:{ + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case INCR:{ + jj_consume_token(INCR); + break; + } + case DECR:{ + jj_consume_token(DECR); + break; + } + case ASSIGN: + case GT: + case LT: + case PLUSASSIGN: + case MINUSASSIGN: + case STARASSIGN: + case SLASHASSIGN: + case ANDASSIGN: + case ORASSIGN: + case XORASSIGN: + case REMASSIGN:{ + AssignmentOperator(); + Expression(); + break; + } + default: + jj_la1[143] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + break; + } + default: + jj_la1[144] = jj_gen; + ; + } + break; + } + default: + jj_la1[145] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void SwitchStatement() throws ParseException { + jj_consume_token(SWITCH); + jj_consume_token(LPAREN); + Expression(); + jj_consume_token(RPAREN); + jj_consume_token(LBRACE); + label_50: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case CASE: + case _DEFAULT:{ + break; + } + default: + jj_la1[146] = jj_gen; + break label_50; + } + SwitchLabel(); + label_51: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BREAK: + case BYTE: + case CHAR: + case CLASS: + case CONTINUE: + case DO: + case DOUBLE: + case FALSE: + case FINAL: + case FLOAT: + case FOR: + case IF: + case INT: + case INTERFACE: + case LONG: + case NEW: + case NULL: + case RETURN: + case SHORT: + case SUPER: + case SWITCH: + case SYNCHRONIZED: + case THIS: + case THROW: + case TRUE: + case TRY: + case VOID: + case WHILE: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case LBRACE: + case SEMICOLON: + case INCR: + case DECR:{ + break; + } + default: + jj_la1[147] = jj_gen; + break label_51; + } + BlockStatement(); + } + } + jj_consume_token(RBRACE); +} + + final public void SwitchLabel() throws ParseException { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case CASE:{ + jj_consume_token(CASE); + Expression(); + jj_consume_token(COLON); + break; + } + case _DEFAULT:{ + jj_consume_token(_DEFAULT); + jj_consume_token(COLON); + break; + } + default: + jj_la1[148] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } +} + + final public void IfStatement() throws ParseException { + jj_consume_token(IF); + jj_consume_token(LPAREN); + Expression(); + jj_consume_token(RPAREN); + Statement(); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ELSE:{ + jj_consume_token(ELSE); + Statement(); + break; + } + default: + jj_la1[149] = jj_gen; + ; + } +} + + final public void WhileStatement() throws ParseException { + jj_consume_token(WHILE); + jj_consume_token(LPAREN); + Expression(); + jj_consume_token(RPAREN); + Statement(); +} + + final public void DoStatement() throws ParseException { + jj_consume_token(DO); + Statement(); + jj_consume_token(WHILE); + jj_consume_token(LPAREN); + Expression(); + jj_consume_token(RPAREN); + jj_consume_token(SEMICOLON); +} + + final public void ForStatement() throws ParseException { + jj_consume_token(FOR); + jj_consume_token(LPAREN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FINAL: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case INCR: + case DECR:{ + ForInit(); + break; + } + default: + jj_la1[150] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + Expression(); + break; + } + default: + jj_la1[151] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case INCR: + case DECR:{ + ForUpdate(); + break; + } + default: + jj_la1[152] = jj_gen; + ; + } + jj_consume_token(RPAREN); + Statement(); +} + + final public void ForInit() throws ParseException { + if (jj_2_37(2147483647)) { + LocalVariableDeclaration(); + } else { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case INCR: + case DECR:{ + StatementExpressionList(); + break; + } + default: + jj_la1[153] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } +} + + final public void StatementExpressionList() throws ParseException { + StatementExpression(); + label_52: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case COMMA:{ + break; + } + default: + jj_la1[154] = jj_gen; + break label_52; + } + jj_consume_token(COMMA); + StatementExpression(); + } +} + + final public void ForUpdate() throws ParseException { + StatementExpressionList(); +} + + final public void BreakStatement() throws ParseException { + jj_consume_token(BREAK); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case IDENTIFIER:{ + JavaIdentifier(); + break; + } + default: + jj_la1[155] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +} + + final public void ContinueStatement() throws ParseException { + jj_consume_token(CONTINUE); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case IDENTIFIER:{ + JavaIdentifier(); + break; + } + default: + jj_la1[156] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +} + + final public void ReturnStatement() throws ParseException { + jj_consume_token(RETURN); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case _OPTIONS: + case _LOOKAHEAD: + case _IGNORE_CASE: + case _PARSER_BEGIN: + case _PARSER_END: + case _JAVACODE: + case _TOKEN: + case _SPECIAL_TOKEN: + case _MORE: + case _SKIP: + case _TOKEN_MGR_DECLS: + case _EOF: + case BOOLEAN: + case BYTE: + case CHAR: + case DOUBLE: + case FALSE: + case FLOAT: + case INT: + case LONG: + case NEW: + case NULL: + case SHORT: + case SUPER: + case THIS: + case TRUE: + case VOID: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case CHARACTER_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: + case BANG: + case TILDE: + case INCR: + case DECR: + case PLUS: + case MINUS:{ + Expression(); + break; + } + default: + jj_la1[157] = jj_gen; + ; + } + jj_consume_token(SEMICOLON); +} + + final public void ThrowStatement() throws ParseException { + jj_consume_token(THROW); + Expression(); + jj_consume_token(SEMICOLON); +} + + final public void SynchronizedStatement() throws ParseException { + jj_consume_token(SYNCHRONIZED); + jj_consume_token(LPAREN); + Expression(); + jj_consume_token(RPAREN); + Block(); +} + + final public void TryStatement() throws ParseException { + jj_consume_token(TRY); + Block(); + label_53: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case CATCH:{ + break; + } + default: + jj_la1[158] = jj_gen; + break label_53; + } + jj_consume_token(CATCH); + jj_consume_token(LPAREN); + FormalParameter(); + jj_consume_token(RPAREN); + Block(); + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case FINALLY:{ + jj_consume_token(FINALLY); + Block(); + break; + } + default: + jj_la1[159] = jj_gen; + ; + } +} + + private boolean jj_2_1(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_1()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(0, xla); } + } + + private boolean jj_2_2(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_2()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(1, xla); } + } + + private boolean jj_2_3(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_3()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(2, xla); } + } + + private boolean jj_2_4(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_4()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(3, xla); } + } + + private boolean jj_2_5(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_5()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(4, xla); } + } + + private boolean jj_2_6(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_6()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(5, xla); } + } + + private boolean jj_2_7(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_7()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(6, xla); } + } + + private boolean jj_2_8(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_8()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(7, xla); } + } + + private boolean jj_2_9(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_9()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(8, xla); } + } + + private boolean jj_2_10(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_10()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(9, xla); } + } + + private boolean jj_2_11(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_11()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(10, xla); } + } + + private boolean jj_2_12(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_12()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(11, xla); } + } + + private boolean jj_2_13(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_13()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(12, xla); } + } + + private boolean jj_2_14(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_14()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(13, xla); } + } + + private boolean jj_2_15(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_15()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(14, xla); } + } + + private boolean jj_2_16(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_16()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(15, xla); } + } + + private boolean jj_2_17(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_17()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(16, xla); } + } + + private boolean jj_2_18(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_18()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(17, xla); } + } + + private boolean jj_2_19(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_19()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(18, xla); } + } + + private boolean jj_2_20(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_20()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(19, xla); } + } + + private boolean jj_2_21(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_21()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(20, xla); } + } + + private boolean jj_2_22(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_22()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(21, xla); } + } + + private boolean jj_2_23(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_23()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(22, xla); } + } + + private boolean jj_2_24(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_24()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(23, xla); } + } + + private boolean jj_2_25(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_25()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(24, xla); } + } + + private boolean jj_2_26(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_26()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(25, xla); } + } + + private boolean jj_2_27(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_27()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(26, xla); } + } + + private boolean jj_2_28(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_28()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(27, xla); } + } + + private boolean jj_2_29(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_29()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(28, xla); } + } + + private boolean jj_2_30(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_30()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(29, xla); } + } + + private boolean jj_2_31(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_31()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(30, xla); } + } + + private boolean jj_2_32(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_32()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(31, xla); } + } + + private boolean jj_2_33(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_33()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(32, xla); } + } + + private boolean jj_2_34(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_34()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(33, xla); } + } + + private boolean jj_2_35(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_35()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(34, xla); } + } + + private boolean jj_2_36(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_36()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(35, xla); } + } + + private boolean jj_2_37(int xla) + { + jj_la = xla; + jj_scanpos = token; + jj_lastpos = token; + try { return (!jj_3_37()); } + catch(LookaheadSuccess ls) { return true; } + finally { jj_save(36, xla); } + } + + private boolean jj_3R_79() + { + if (jj_3R_102()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_130()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_144() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(95)) { + jj_scanpos = xsp; + if (jj_scan_token(120)) { + jj_scanpos = xsp; + if (jj_scan_token(121)) { + jj_scanpos = xsp; + if (jj_scan_token(125)) { + jj_scanpos = xsp; + if (jj_scan_token(118)) { + jj_scanpos = xsp; + if (jj_scan_token(119)) { + jj_scanpos = xsp; + if (jj_scan_token(122)) { + jj_scanpos = xsp; + if (jj_scan_token(124)) { + jj_scanpos = xsp; + if (jj_scan_token(123)) { + jj_scanpos = xsp; + if (jj_3R_158()) return true; + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_158() + { + if (jj_3R_179()) return true; + return false; + } + + private boolean jj_3R_102() + { + if (jj_3R_119()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_143()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_119() + { + if (jj_3R_128()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_157()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_128() + { + if (jj_3R_141()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_178()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_130() + { + if (jj_3R_144()) return true; + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_141() + { + if (jj_3R_156()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_198()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_156() + { + if (jj_3R_177()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_207()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_143() + { + if (jj_scan_token(HOOK)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_102()) return true; + return false; + } + + private boolean jj_3R_177() + { + if (jj_3R_197()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_210()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_157() + { + if (jj_scan_token(SC_OR)) return true; + if (jj_3R_128()) return true; + return false; + } + + private boolean jj_3R_197() + { + if (jj_3R_206()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_216()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_178() + { + if (jj_scan_token(SC_AND)) return true; + if (jj_3R_141()) return true; + return false; + } + + private boolean jj_3R_206() + { + if (jj_3R_209()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_222()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_207() + { + if (jj_scan_token(XOR)) return true; + if (jj_3R_177()) return true; + return false; + } + + private boolean jj_3R_198() + { + if (jj_scan_token(BIT_OR)) return true; + if (jj_3R_156()) return true; + return false; + } + + private boolean jj_3_3() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(83)) { + jj_scanpos = xsp; + if (jj_scan_token(82)) { + jj_scanpos = xsp; + if (jj_scan_token(97)) { + jj_scanpos = xsp; + if (jj_3R_55()) return true; + } + } + } + return false; + } + + private boolean jj_3_2() + { + if (jj_3R_54()) return true; + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + private boolean jj_3_4() + { + if (jj_scan_token(LT)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_56()) jj_scanpos = xsp; + if (jj_3R_57()) return true; + if (jj_scan_token(GT)) return true; + return false; + } + + private boolean jj_3R_209() + { + if (jj_3R_71()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_20()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_210() + { + if (jj_scan_token(BIT_AND)) return true; + if (jj_3R_197()) return true; + return false; + } + + private boolean jj_3_5() + { + if (jj_scan_token(LT)) return true; + if (jj_scan_token(83)) return true; + return false; + } + + private boolean jj_3R_56() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(126)) jj_scanpos = xsp; + if (jj_scan_token(83)) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + private boolean jj_3R_216() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(102)) { + jj_scanpos = xsp; + if (jj_scan_token(105)) return true; + } + if (jj_3R_206()) return true; + return false; + } + + private boolean jj_3R_71() + { + if (jj_3R_73()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_21()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_57() + { + if (jj_3R_83()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_84()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_222() + { + if (jj_scan_token(INSTANCEOF)) return true; + if (jj_3R_81()) return true; + return false; + } + + private boolean jj_3R_73() + { + if (jj_3R_94()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_251()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_83() + { + Token xsp; + if (jj_3R_112()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_112()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_20() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(97)) { + jj_scanpos = xsp; + if (jj_scan_token(96)) { + jj_scanpos = xsp; + if (jj_scan_token(103)) { + jj_scanpos = xsp; + if (jj_scan_token(104)) return true; + } + } + } + if (jj_3R_71()) return true; + return false; + } + + private boolean jj_3R_112() + { + if (jj_3R_121()) return true; + return false; + } + + private boolean jj_3R_94() + { + if (jj_3R_116()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_256()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_121() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(82)) { + jj_scanpos = xsp; + if (jj_3R_131()) { + jj_scanpos = xsp; + if (jj_3R_132()) { + jj_scanpos = xsp; + if (jj_3R_133()) return true; + } + } + } + return false; + } + + private boolean jj_3R_131() + { + if (jj_scan_token(LT)) return true; + if (jj_scan_token(83)) return true; + return false; + } + + private boolean jj_3R_132() + { + if (jj_3R_148()) return true; + return false; + } + + private boolean jj_3R_116() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_124()) { + jj_scanpos = xsp; + if (jj_3R_125()) { + jj_scanpos = xsp; + if (jj_3R_126()) { + jj_scanpos = xsp; + if (jj_3R_127()) return true; + } + } + } + return false; + } + + private boolean jj_3R_124() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(110)) { + jj_scanpos = xsp; + if (jj_scan_token(111)) return true; + } + if (jj_3R_116()) return true; + return false; + } + + private boolean jj_3R_133() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_57()) return true; + return false; + } + + private boolean jj_3R_125() + { + if (jj_3R_138()) return true; + return false; + } + + private boolean jj_3R_126() + { + if (jj_3R_139()) return true; + return false; + } + + private boolean jj_3_21() + { + if (jj_3R_72()) return true; + if (jj_3R_73()) return true; + return false; + } + + private boolean jj_3R_55() + { + if (jj_3R_54()) return true; + if (jj_scan_token(ASSIGN)) return true; + return false; + } + + private boolean jj_3R_127() + { + if (jj_3R_140()) return true; + return false; + } + + private boolean jj_3R_148() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(99)) jj_scanpos = xsp; + if (jj_scan_token(LBRACKET)) return true; + xsp = jj_scanpos; + if (jj_3R_161()) jj_scanpos = xsp; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_138() + { + if (jj_scan_token(INCR)) return true; + if (jj_3R_54()) return true; + return false; + } + + private boolean jj_3R_182() + { + if (jj_scan_token(82)) return true; + return false; + } + + private boolean jj_3R_84() + { + if (jj_scan_token(BIT_OR)) return true; + return false; + } + + private boolean jj_3R_256() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(112)) { + jj_scanpos = xsp; + if (jj_scan_token(113)) { + jj_scanpos = xsp; + if (jj_scan_token(117)) return true; + } + } + if (jj_3R_116()) return true; + return false; + } + + private boolean jj_3R_251() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(110)) { + jj_scanpos = xsp; + if (jj_scan_token(111)) return true; + } + if (jj_3R_94()) return true; + return false; + } + + private boolean jj_3R_139() + { + if (jj_scan_token(DECR)) return true; + if (jj_3R_54()) return true; + return false; + } + + private boolean jj_3R_161() + { + if (jj_3R_182()) return true; + return false; + } + + private boolean jj_3R_140() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_153()) { + jj_scanpos = xsp; + if (jj_3R_154()) { + jj_scanpos = xsp; + if (jj_3R_155()) return true; + } + } + return false; + } + + private boolean jj_3R_153() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(99)) { + jj_scanpos = xsp; + if (jj_scan_token(98)) return true; + } + if (jj_3R_116()) return true; + return false; + } + + private boolean jj_3R_154() + { + if (jj_3R_175()) return true; + return false; + } + + private boolean jj_3R_155() + { + if (jj_3R_176()) return true; + return false; + } + + private boolean jj_3_22() + { + if (jj_3R_74()) return true; + return false; + } + + private boolean jj_3_23() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_75()) return true; + return false; + } + + private boolean jj_3R_74() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_23()) { + jj_scanpos = xsp; + if (jj_3R_95()) { + jj_scanpos = xsp; + if (jj_3R_96()) return true; + } + } + return false; + } + + private boolean jj_3R_95() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_63()) return true; + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_96() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_63()) return true; + if (jj_scan_token(RPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(99)) { + jj_scanpos = xsp; + if (jj_scan_token(98)) { + jj_scanpos = xsp; + if (jj_scan_token(86)) { + jj_scanpos = xsp; + if (jj_3R_117()) { + jj_scanpos = xsp; + if (jj_scan_token(66)) { + jj_scanpos = xsp; + if (jj_scan_token(63)) { + jj_scanpos = xsp; + if (jj_scan_token(54)) { + jj_scanpos = xsp; + if (jj_3R_118()) return true; + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_176() + { + if (jj_3R_54()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_279()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3_24() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_63()) return true; + if (jj_scan_token(LBRACKET)) return true; + return false; + } + + private boolean jj_3R_175() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_195()) { + jj_scanpos = xsp; + if (jj_3R_196()) return true; + } + return false; + } + + private boolean jj_3R_195() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_116()) return true; + return false; + } + + private boolean jj_3R_196() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_81()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_140()) return true; + return false; + } + + private boolean jj_3_25() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_75()) return true; + return false; + } + + private boolean jj_3R_54() + { + if (jj_3R_82()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_27()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_26() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_63()) return true; + return false; + } + + private boolean jj_3R_82() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_106()) { + jj_scanpos = xsp; + if (jj_scan_token(66)) { + jj_scanpos = xsp; + if (jj_3R_107()) { + jj_scanpos = xsp; + if (jj_3R_108()) { + jj_scanpos = xsp; + if (jj_3R_109()) { + jj_scanpos = xsp; + if (jj_3R_110()) { + jj_scanpos = xsp; + if (jj_3R_111()) return true; + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_106() + { + if (jj_3R_120()) return true; + return false; + } + + private boolean jj_3R_279() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(108)) { + jj_scanpos = xsp; + if (jj_scan_token(109)) return true; + } + return false; + } + + private boolean jj_3R_70() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(83)) { + jj_scanpos = xsp; + if (jj_scan_token(1)) { + jj_scanpos = xsp; + if (jj_scan_token(2)) { + jj_scanpos = xsp; + if (jj_scan_token(3)) { + jj_scanpos = xsp; + if (jj_scan_token(4)) { + jj_scanpos = xsp; + if (jj_scan_token(5)) { + jj_scanpos = xsp; + if (jj_scan_token(6)) { + jj_scanpos = xsp; + if (jj_scan_token(7)) { + jj_scanpos = xsp; + if (jj_scan_token(8)) { + jj_scanpos = xsp; + if (jj_scan_token(9)) { + jj_scanpos = xsp; + if (jj_scan_token(10)) { + jj_scanpos = xsp; + if (jj_scan_token(11)) { + jj_scanpos = xsp; + if (jj_scan_token(12)) return true; + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_107() + { + if (jj_scan_token(SUPER)) return true; + if (jj_scan_token(DOT)) return true; + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_108() + { + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_117() + { + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_109() + { + if (jj_3R_78()) return true; + return false; + } + + private boolean jj_3R_110() + { + if (jj_3R_77()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(CLASS)) return true; + return false; + } + + private boolean jj_3_27() + { + if (jj_3R_76()) return true; + return false; + } + + private boolean jj_3R_111() + { + if (jj_3R_63()) return true; + return false; + } + + private boolean jj_3_29() + { + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(THIS)) return true; + return false; + } + + private boolean jj_3R_76() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_29()) { + jj_scanpos = xsp; + if (jj_3_30()) { + jj_scanpos = xsp; + if (jj_3R_97()) { + jj_scanpos = xsp; + if (jj_3R_98()) { + jj_scanpos = xsp; + if (jj_3R_99()) return true; + } + } + } + } + return false; + } + + private boolean jj_3_28() + { + if (jj_3R_77()) return true; + if (jj_scan_token(DOT)) return true; + if (jj_scan_token(CLASS)) return true; + return false; + } + + private boolean jj_3_30() + { + if (jj_scan_token(DOT)) return true; + if (jj_3R_78()) return true; + return false; + } + + private boolean jj_3R_97() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_72() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_92()) { + jj_scanpos = xsp; + if (jj_3R_93()) return true; + } + return false; + } + + private boolean jj_3R_92() + { + if (jj_scan_token(LT)) return true; + if (jj_scan_token(LT)) return true; + return false; + } + + private boolean jj_3R_98() + { + if (jj_scan_token(DOT)) return true; + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_93() + { + if (jj_scan_token(GT)) return true; + if (jj_scan_token(GT)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(96)) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_99() + { + if (jj_3R_69()) return true; + return false; + } + + private boolean jj_3R_120() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(75)) { + jj_scanpos = xsp; + if (jj_scan_token(79)) { + jj_scanpos = xsp; + if (jj_scan_token(81)) { + jj_scanpos = xsp; + if (jj_scan_token(82)) { + jj_scanpos = xsp; + if (jj_3R_129()) { + jj_scanpos = xsp; + if (jj_scan_token(55)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3R_179() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_199()) { + jj_scanpos = xsp; + if (jj_3R_200()) return true; + } + return false; + } + + private boolean jj_3R_199() + { + if (jj_scan_token(LT)) return true; + if (jj_scan_token(LE)) return true; + return false; + } + + private boolean jj_3R_200() + { + if (jj_scan_token(GT)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(96)) jj_scanpos = xsp; + if (jj_scan_token(GE)) return true; + return false; + } + + private boolean jj_3R_129() + { + if (jj_3R_142()) return true; + return false; + } + + private boolean jj_3R_118() + { + if (jj_3R_120()) return true; + return false; + } + + private boolean jj_3R_142() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(70)) { + jj_scanpos = xsp; + if (jj_scan_token(40)) return true; + } + return false; + } + + private boolean jj_3R_69() + { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_91()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_91() + { + if (jj_3R_115()) return true; + return false; + } + + private boolean jj_3R_115() + { + if (jj_3R_79()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_123()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_31() + { + if (jj_scan_token(NEW)) return true; + if (jj_3R_75()) return true; + if (jj_3R_145()) return true; + return false; + } + + private boolean jj_3R_78() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_31()) { + jj_scanpos = xsp; + if (jj_3R_101()) return true; + } + return false; + } + + private boolean jj_3_6() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_58()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(CLASS)) return true; + return false; + } + + private boolean jj_3R_101() + { + if (jj_scan_token(NEW)) return true; + if (jj_3R_63()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_146()) { + jj_scanpos = xsp; + if (jj_3R_147()) return true; + } + return false; + } + + private boolean jj_3R_58() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(59)) return true; + } + } + return false; + } + + private boolean jj_3R_123() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_146() + { + if (jj_3R_145()) return true; + return false; + } + + private boolean jj_3R_147() + { + if (jj_3R_69()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_160()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_151() + { + if (jj_scan_token(CLASS)) return true; + if (jj_3R_70()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_237()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_238()) jj_scanpos = xsp; + if (jj_3R_181()) return true; + return false; + } + + private boolean jj_3_34() + { + Token xsp; + if (jj_3_32()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3_32()) { jj_scanpos = xsp; break; } + } + while (true) { + xsp = jj_scanpos; + if (jj_3_33()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_145() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_34()) { + jj_scanpos = xsp; + if (jj_3R_159()) return true; + } + return false; + } + + private boolean jj_3_32() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_159() + { + Token xsp; + if (jj_3R_180()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_180()) { jj_scanpos = xsp; break; } + } + if (jj_3R_114()) return true; + return false; + } + + private boolean jj_3R_181() + { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_202()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_180() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_160() + { + if (jj_3R_181()) return true; + return false; + } + + private boolean jj_3R_202() + { + if (jj_3R_208()) return true; + return false; + } + + private boolean jj_3R_217() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_223()) { jj_scanpos = xsp; break; } + } + if (jj_3R_151()) return true; + return false; + } + + private boolean jj_3R_223() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3_35() + { + if (jj_3R_80()) return true; + return false; + } + + private boolean jj_3R_150() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_35()) { + jj_scanpos = xsp; + if (jj_3R_162()) { + jj_scanpos = xsp; + if (jj_scan_token(92)) { + jj_scanpos = xsp; + if (jj_3R_163()) { + jj_scanpos = xsp; + if (jj_3R_164()) { + jj_scanpos = xsp; + if (jj_3R_165()) { + jj_scanpos = xsp; + if (jj_3R_166()) { + jj_scanpos = xsp; + if (jj_3R_167()) { + jj_scanpos = xsp; + if (jj_3R_168()) { + jj_scanpos = xsp; + if (jj_3R_169()) { + jj_scanpos = xsp; + if (jj_3R_170()) { + jj_scanpos = xsp; + if (jj_3R_171()) { + jj_scanpos = xsp; + if (jj_3R_172()) { + jj_scanpos = xsp; + if (jj_3R_173()) { + jj_scanpos = xsp; + if (jj_3R_174()) return true; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3_7() + { + if (jj_3R_59()) return true; + return false; + } + + private boolean jj_3R_162() + { + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_208() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_7()) { + jj_scanpos = xsp; + if (jj_3R_211()) { + jj_scanpos = xsp; + if (jj_3R_212()) { + jj_scanpos = xsp; + if (jj_3R_213()) { + jj_scanpos = xsp; + if (jj_3R_214()) { + jj_scanpos = xsp; + if (jj_3R_215()) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3R_211() + { + if (jj_3R_217()) return true; + return false; + } + + private boolean jj_3R_163() + { + if (jj_3R_183()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_164() + { + if (jj_3R_184()) return true; + return false; + } + + private boolean jj_3R_212() + { + if (jj_3R_218()) return true; + return false; + } + + private boolean jj_3R_237() + { + if (jj_scan_token(EXTENDS)) return true; + if (jj_3R_63()) return true; + return false; + } + + private boolean jj_3R_165() + { + if (jj_3R_185()) return true; + return false; + } + + private boolean jj_3R_213() + { + if (jj_3R_219()) return true; + return false; + } + + private boolean jj_3R_166() + { + if (jj_3R_186()) return true; + return false; + } + + private boolean jj_3R_167() + { + if (jj_3R_187()) return true; + return false; + } + + private boolean jj_3R_214() + { + if (jj_3R_220()) return true; + return false; + } + + private boolean jj_3_8() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_60()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(CLASS)) return true; + return false; + } + + private boolean jj_3R_168() + { + if (jj_3R_188()) return true; + return false; + } + + private boolean jj_3R_215() + { + if (jj_3R_221()) return true; + return false; + } + + private boolean jj_3R_60() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3R_169() + { + if (jj_3R_189()) return true; + return false; + } + + private boolean jj_3_9() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_61()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(INTERFACE)) return true; + return false; + } + + private boolean jj_3R_170() + { + if (jj_3R_190()) return true; + return false; + } + + private boolean jj_3R_61() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3_10() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_62()) jj_scanpos = xsp; + if (jj_3R_63()) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + private boolean jj_3R_171() + { + if (jj_3R_191()) return true; + return false; + } + + private boolean jj_3R_62() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + return false; + } + + private boolean jj_3R_64() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_86()) { jj_scanpos = xsp; break; } + } + if (jj_3R_77()) return true; + if (jj_3R_70()) return true; + if (jj_scan_token(LPAREN)) return true; + return false; + } + + private boolean jj_3R_172() + { + if (jj_3R_192()) return true; + return false; + } + + private boolean jj_3_11() + { + if (jj_3R_64()) return true; + return false; + } + + private boolean jj_3R_86() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) { + jj_scanpos = xsp; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(53)) { + jj_scanpos = xsp; + if (jj_scan_token(65)) return true; + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_173() + { + if (jj_3R_193()) return true; + return false; + } + + private boolean jj_3_33() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_174() + { + if (jj_3R_194()) return true; + return false; + } + + private boolean jj_3R_238() + { + if (jj_scan_token(IMPLEMENTS)) return true; + if (jj_3R_242()) return true; + return false; + } + + private boolean jj_3R_80() + { + if (jj_3R_70()) return true; + if (jj_scan_token(COLON)) return true; + if (jj_3R_150()) return true; + return false; + } + + private boolean jj_3R_218() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_224()) { jj_scanpos = xsp; break; } + } + if (jj_3R_152()) return true; + return false; + } + + private boolean jj_3R_85() + { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_113()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_224() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3R_152() + { + if (jj_scan_token(INTERFACE)) return true; + if (jj_3R_70()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_239()) jj_scanpos = xsp; + if (jj_scan_token(LBRACE)) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_240()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_113() + { + if (jj_3R_122()) return true; + return false; + } + + private boolean jj_3R_122() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_134()) { + jj_scanpos = xsp; + if (jj_3R_135()) { + jj_scanpos = xsp; + if (jj_3R_136()) { + jj_scanpos = xsp; + if (jj_3R_137()) return true; + } + } + } + return false; + } + + private boolean jj_3R_134() + { + if (jj_3R_149()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_135() + { + if (jj_3R_150()) return true; + return false; + } + + private boolean jj_3R_136() + { + if (jj_3R_151()) return true; + return false; + } + + private boolean jj_3R_240() + { + if (jj_3R_246()) return true; + return false; + } + + private boolean jj_3R_246() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_252()) { + jj_scanpos = xsp; + if (jj_3R_253()) { + jj_scanpos = xsp; + if (jj_3R_254()) { + jj_scanpos = xsp; + if (jj_3R_255()) return true; + } + } + } + return false; + } + + private boolean jj_3R_252() + { + if (jj_3R_217()) return true; + return false; + } + + private boolean jj_3R_137() + { + if (jj_3R_152()) return true; + return false; + } + + private boolean jj_3R_253() + { + if (jj_3R_218()) return true; + return false; + } + + private boolean jj_3_36() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(41)) jj_scanpos = xsp; + if (jj_3R_81()) return true; + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_254() + { + if (jj_3R_220()) return true; + return false; + } + + private boolean jj_3R_149() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(41)) jj_scanpos = xsp; + if (jj_3R_81()) return true; + if (jj_3R_235()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_257()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_255() + { + if (jj_3R_221()) return true; + return false; + } + + private boolean jj_3_12() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_65()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(CLASS)) return true; + return false; + } + + private boolean jj_3R_65() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3_13() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_66()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(INTERFACE)) return true; + return false; + } + + private boolean jj_3R_221() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_234()) { jj_scanpos = xsp; break; } + } + if (jj_3R_81()) return true; + if (jj_3R_235()) return true; + while (true) { + xsp = jj_scanpos; + if (jj_3R_236()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_66() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + } + } + } + return false; + } + + private boolean jj_3_14() + { + if (jj_3R_64()) return true; + return false; + } + + private boolean jj_3R_234() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) { + jj_scanpos = xsp; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(69)) { + jj_scanpos = xsp; + if (jj_scan_token(73)) return true; + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_235() + { + if (jj_3R_244()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_245()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_183() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_203()) { + jj_scanpos = xsp; + if (jj_3R_204()) { + jj_scanpos = xsp; + if (jj_3R_205()) return true; + } + } + return false; + } + + private boolean jj_3R_203() + { + if (jj_3R_138()) return true; + return false; + } + + private boolean jj_3R_239() + { + if (jj_scan_token(EXTENDS)) return true; + if (jj_3R_242()) return true; + return false; + } + + private boolean jj_3R_204() + { + if (jj_3R_139()) return true; + return false; + } + + private boolean jj_3R_205() + { + if (jj_3R_54()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_268()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_244() + { + if (jj_3R_70()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_250()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_268() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(108)) { + jj_scanpos = xsp; + if (jj_scan_token(109)) { + jj_scanpos = xsp; + if (jj_3R_273()) return true; + } + } + return false; + } + + private boolean jj_3R_67() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_87()) { + jj_scanpos = xsp; + if (jj_3R_88()) return true; + } + return false; + } + + private boolean jj_3R_87() + { + if (jj_3R_114()) return true; + return false; + } + + private boolean jj_3R_88() + { + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_273() + { + if (jj_3R_144()) return true; + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_184() + { + if (jj_scan_token(SWITCH)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_scan_token(LBRACE)) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_258()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_114() + { + if (jj_scan_token(LBRACE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_201()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_scan_token(93)) jj_scanpos = xsp; + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_236() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_235()) return true; + return false; + } + + private boolean jj_3R_258() + { + if (jj_3R_269()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_270()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_245() + { + if (jj_scan_token(ASSIGN)) return true; + if (jj_3R_67()) return true; + return false; + } + + private boolean jj_3R_250() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_201() + { + if (jj_3R_67()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_15()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_220() + { + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_230()) { jj_scanpos = xsp; break; } + } + if (jj_3R_77()) return true; + if (jj_3R_231()) return true; + xsp = jj_scanpos; + if (jj_3R_232()) jj_scanpos = xsp; + xsp = jj_scanpos; + if (jj_3R_233()) { + jj_scanpos = xsp; + if (jj_scan_token(92)) return true; + } + return false; + } + + private boolean jj_3R_257() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_235()) return true; + return false; + } + + private boolean jj_3R_269() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_274()) { + jj_scanpos = xsp; + if (jj_3R_275()) return true; + } + return false; + } + + private boolean jj_3R_274() + { + if (jj_scan_token(CASE)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + private boolean jj_3R_230() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) { + jj_scanpos = xsp; + if (jj_scan_token(62)) { + jj_scanpos = xsp; + if (jj_scan_token(25)) { + jj_scanpos = xsp; + if (jj_scan_token(41)) { + jj_scanpos = xsp; + if (jj_scan_token(53)) { + jj_scanpos = xsp; + if (jj_scan_token(65)) return true; + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_275() + { + if (jj_scan_token(_DEFAULT)) return true; + if (jj_scan_token(COLON)) return true; + return false; + } + + private boolean jj_3R_233() + { + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_231() + { + if (jj_3R_70()) return true; + if (jj_3R_226()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_243()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_185() + { + if (jj_scan_token(IF)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_150()) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_259()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_226() + { + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_241()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + return false; + } + + private boolean jj_3R_270() + { + if (jj_3R_122()) return true; + return false; + } + + private boolean jj_3R_186() + { + if (jj_scan_token(WHILE)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_150()) return true; + return false; + } + + private boolean jj_3R_241() + { + if (jj_3R_247()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_248()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_247() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(41)) jj_scanpos = xsp; + if (jj_3R_81()) return true; + if (jj_3R_244()) return true; + return false; + } + + private boolean jj_3_15() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_67()) return true; + return false; + } + + private boolean jj_3R_187() + { + if (jj_scan_token(DO)) return true; + if (jj_3R_150()) return true; + if (jj_scan_token(WHILE)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_219() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_225()) jj_scanpos = xsp; + if (jj_3R_70()) return true; + if (jj_3R_226()) return true; + xsp = jj_scanpos; + if (jj_3R_227()) jj_scanpos = xsp; + if (jj_scan_token(LBRACE)) return true; + xsp = jj_scanpos; + if (jj_3R_228()) jj_scanpos = xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_229()) { jj_scanpos = xsp; break; } + } + if (jj_scan_token(RBRACE)) return true; + return false; + } + + private boolean jj_3R_225() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(59)) { + jj_scanpos = xsp; + if (jj_scan_token(58)) { + jj_scanpos = xsp; + if (jj_scan_token(57)) return true; + } + } + return false; + } + + private boolean jj_3R_188() + { + if (jj_scan_token(FOR)) return true; + if (jj_scan_token(LPAREN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_260()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + xsp = jj_scanpos; + if (jj_3R_261()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + xsp = jj_scanpos; + if (jj_3R_262()) jj_scanpos = xsp; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_150()) return true; + return false; + } + + private boolean jj_3R_228() + { + if (jj_3R_68()) return true; + return false; + } + + private boolean jj_3R_229() + { + if (jj_3R_122()) return true; + return false; + } + + private boolean jj_3R_232() + { + if (jj_scan_token(THROWS)) return true; + if (jj_3R_242()) return true; + return false; + } + + private boolean jj_3R_68() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_89()) { + jj_scanpos = xsp; + if (jj_3R_90()) return true; + } + return false; + } + + private boolean jj_3R_89() + { + if (jj_scan_token(THIS)) return true; + if (jj_3R_69()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_271() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_276()) { + jj_scanpos = xsp; + if (jj_3R_277()) return true; + } + return false; + } + + private boolean jj_3R_276() + { + if (jj_3R_149()) return true; + return false; + } + + private boolean jj_3R_90() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3_17()) jj_scanpos = xsp; + if (jj_scan_token(SUPER)) return true; + if (jj_3R_69()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_248() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_247()) return true; + return false; + } + + private boolean jj_3R_277() + { + if (jj_3R_278()) return true; + return false; + } + + private boolean jj_3_17() + { + if (jj_3R_54()) return true; + if (jj_scan_token(DOT)) return true; + return false; + } + + private boolean jj_3_16() + { + if (jj_3R_68()) return true; + return false; + } + + private boolean jj_3R_260() + { + if (jj_3R_271()) return true; + return false; + } + + private boolean jj_3R_59() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(62)) jj_scanpos = xsp; + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_243() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3_18() + { + if (jj_scan_token(THIS)) return true; + if (jj_3R_69()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_278() + { + if (jj_3R_183()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_280()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3_37() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(41)) jj_scanpos = xsp; + if (jj_3R_81()) return true; + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_272() + { + if (jj_3R_278()) return true; + return false; + } + + private boolean jj_3R_259() + { + if (jj_scan_token(ELSE)) return true; + if (jj_3R_150()) return true; + return false; + } + + private boolean jj_3R_81() + { + Token xsp; + xsp = jj_scanpos; + if (jj_3R_103()) { + jj_scanpos = xsp; + if (jj_3R_104()) return true; + } + while (true) { + xsp = jj_scanpos; + if (jj_3R_105()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_103() + { + if (jj_3R_75()) return true; + return false; + } + + private boolean jj_3R_189() + { + if (jj_scan_token(BREAK)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_263()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_261() + { + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_75() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(26)) { + jj_scanpos = xsp; + if (jj_scan_token(31)) { + jj_scanpos = xsp; + if (jj_scan_token(28)) { + jj_scanpos = xsp; + if (jj_scan_token(61)) { + jj_scanpos = xsp; + if (jj_scan_token(50)) { + jj_scanpos = xsp; + if (jj_scan_token(52)) { + jj_scanpos = xsp; + if (jj_scan_token(43)) { + jj_scanpos = xsp; + if (jj_scan_token(37)) return true; + } + } + } + } + } + } + } + return false; + } + + private boolean jj_3R_190() + { + if (jj_scan_token(CONTINUE)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_264()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_227() + { + if (jj_scan_token(THROWS)) return true; + if (jj_3R_242()) return true; + return false; + } + + private boolean jj_3_1() + { + if (jj_scan_token(LT)) return true; + if (jj_scan_token(STAR)) return true; + return false; + } + + private boolean jj_3R_263() + { + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_191() + { + if (jj_scan_token(RETURN)) return true; + Token xsp; + xsp = jj_scanpos; + if (jj_3R_265()) jj_scanpos = xsp; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_280() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_183()) return true; + return false; + } + + private boolean jj_3R_104() + { + if (jj_3R_63()) return true; + return false; + } + + private boolean jj_3R_192() + { + if (jj_scan_token(THROW)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(SEMICOLON)) return true; + return false; + } + + private boolean jj_3R_264() + { + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_265() + { + if (jj_3R_79()) return true; + return false; + } + + private boolean jj_3R_77() + { + Token xsp; + xsp = jj_scanpos; + if (jj_scan_token(72)) { + jj_scanpos = xsp; + if (jj_3R_100()) return true; + } + return false; + } + + private boolean jj_3R_193() + { + if (jj_scan_token(SYNCHRONIZED)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_79()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_262() + { + if (jj_3R_272()) return true; + return false; + } + + private boolean jj_3R_100() + { + if (jj_3R_81()) return true; + return false; + } + + private boolean jj_3R_105() + { + if (jj_scan_token(LBRACKET)) return true; + if (jj_scan_token(RBRACKET)) return true; + return false; + } + + private boolean jj_3R_194() + { + if (jj_scan_token(TRY)) return true; + if (jj_3R_85()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_266()) { jj_scanpos = xsp; break; } + } + xsp = jj_scanpos; + if (jj_3R_267()) jj_scanpos = xsp; + return false; + } + + private boolean jj_3R_63() + { + if (jj_3R_70()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3_19()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_266() + { + if (jj_scan_token(CATCH)) return true; + if (jj_scan_token(LPAREN)) return true; + if (jj_3R_247()) return true; + if (jj_scan_token(RPAREN)) return true; + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3R_267() + { + if (jj_scan_token(FINALLY)) return true; + if (jj_3R_85()) return true; + return false; + } + + private boolean jj_3_19() + { + if (jj_scan_token(DOT)) return true; + if (jj_3R_70()) return true; + return false; + } + + private boolean jj_3R_242() + { + if (jj_3R_63()) return true; + Token xsp; + while (true) { + xsp = jj_scanpos; + if (jj_3R_249()) { jj_scanpos = xsp; break; } + } + return false; + } + + private boolean jj_3R_249() + { + if (jj_scan_token(COMMA)) return true; + if (jj_3R_63()) return true; + return false; + } + + /** Generated Token Manager. */ + public JavaCCParserTokenManager token_source; + JavaCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private Token jj_scanpos, jj_lastpos; + private int jj_la; + private int jj_gen; + final private int[] jj_la1 = new int[160]; + static private int[] jj_la1_0; + static private int[] jj_la1_1; + static private int[] jj_la1_2; + static private int[] jj_la1_3; + static { + jj_la1_init_0(); + jj_la1_init_1(); + jj_la1_init_2(); + jj_la1_init_3(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x94001ffe,0xc,0x2,0xc,0x0,0x94001ffe,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x780,0x0,0x0,0x0,0x4,0x0,0x0,0x40000000,0x0,0x0,0x0,0x0,0x4,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1ffe,0x0,0x0,0x0,0x0,0x0,0x0,0x2000000,0x0,0x2000000,0x2000000,0x2000000,0x0,0x0,0x96001ffe,0x2000000,0x2000000,0x94001ffe,0x2000000,0x2000000,0x2000000,0x2000000,0x2000000,0x2000000,0x0,0x96001ffe,0x94001ffe,0x0,0x0,0x0,0x0,0x0,0x94001ffe,0x94001ffe,0x0,0x2000000,0x2000000,0x0,0x0,0x0,0x0,0x94001ffe,0x0,0x0,0x0,0x0,0x9c001ffe,0x94001ffe,0x0,0x94001ffe,0x0,0x94000000,0x94001ffe,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x94001ffe,0x0,0x0,0x94001ffe,0x1ffe,0x0,0x0,0x0,0x0,0x1ffe,0x0,0x0,0x0,0x94001ffe,0x0,0x0,0x0,0x0,0x0,0x0,0x9c001ffe,0x9c001ffe,0x9c001ffe,0x0,0x0,0x0,0x0,0x94001ffe,0x20000000,0x9c001ffe,0x20000000,0x0,0x94001ffe,0x94001ffe,0x94001ffe,0x94001ffe,0x0,0x1ffe,0x1ffe,0x94001ffe,0x40000000,0x0,}; + } + private static void jj_la1_init_1() { + jj_la1_1 = new int[] {0x20140820,0x40000000,0x0,0x40000000,0x100,0x20140820,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x400,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1000000,0x10000,0x8080201,0x0,0x8080000,0x8000200,0x8000200,0x80,0x8000,0x6e3c0a21,0x4e000200,0x4e000200,0x6e140a20,0x4e200200,0x4e200200,0x8000000,0x8000000,0x4e000200,0x4e000200,0x80,0x6e3c0a21,0x6e140a20,0x4e000200,0x4e000200,0x0,0x0,0x0,0xa0d40920,0xa0d40920,0x0,0x4e200200,0x4e200200,0x0,0x0,0x0,0x0,0x20140a20,0x200,0xe000000,0xe000000,0x0,0xb0dc5b35,0xa0d40920,0x40000000,0x20140820,0x0,0x20140820,0x20140820,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x20000,0x0,0x0,0x0,0x0,0x0,0x0,0xa0d40920,0x0,0x0,0xa0d40920,0x80c00100,0x0,0x0,0x0,0x80c00100,0x0,0x0,0x800100,0x100,0xa0d40920,0x0,0x0,0x0,0x400000,0x0,0x0,0xb0d45934,0xb0dc5b35,0xb0dc5935,0x200,0x0,0x0,0x0,0xa0d40920,0x8,0xb0dc5b35,0x8,0x40,0xa0d40b20,0xa0d40920,0xa0d40920,0xa0d40920,0x0,0x0,0x0,0xa0d40920,0x0,0x400,}; + } + private static void jj_la1_init_2() { + jj_la1_2 = new int[] {0x80100,0x80000,0x0,0x80000,0x40840,0x80100,0x20000000,0x10,0x0,0x20000000,0x10,0x0,0x20000000,0x0,0x0,0x4000000,0x0,0x0,0x1000000,0x0,0x0,0x0,0x0,0x800,0x0,0x0,0xc0000,0x0,0x0,0x5000080,0x400000,0x0,0x80000,0x40000,0x0,0x0,0x4440000,0x0,0x0,0x4440000,0x0,0x20000000,0x40000,0x0,0x80100,0x0,0x400000,0x80000,0x0,0x0,0x0,0x0,0x0,0x0,0x10000000,0x40000000,0x10000000,0x0,0x0,0x0,0x0,0x1080322,0x0,0x0,0x80220,0x2,0x2,0x0,0x0,0x0,0x0,0x0,0x80322,0x80220,0x220,0x220,0x20000000,0x80000000,0x4000000,0x14e8944,0x14e8944,0x20000000,0x2,0x2,0x10,0x11000000,0x4000000,0x20000000,0x80000,0x0,0x0,0x0,0x10,0x114e8dcf,0x4e8944,0x0,0x80000,0x4000000,0x0,0x80100,0x20000000,0x80000000,0x80000000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4e8944,0x0,0x0,0x4e8944,0x4e8844,0x400000,0x0,0x0,0x468844,0x80000,0x44400000,0x68840,0x40,0x4e8944,0x20000000,0x1000000,0x4400000,0x0,0x4000000,0x4000000,0x114e8dcf,0x114e8dcf,0x114e8dcf,0x0,0x20000000,0x80000000,0x80000000,0x4e8944,0x0,0x114e8dcf,0x0,0x0,0x4e8944,0x4e8944,0x4e8944,0x4e8944,0x20000000,0x80000,0x80000,0x4e8944,0x0,0x0,}; + } + private static void jj_la1_init_3() { + jj_la1_3 = new int[] {0x2,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x40000000,0x0,0x0,0x40000000,0x0,0x2,0x2,0x0,0x80000,0x0,0x0,0x20,0x80000,0x0,0x40000000,0x0,0x0,0x0,0x2,0x14010,0x14010,0x0,0x0,0x40000000,0x40000000,0x0,0x2,0x80000,0xa,0x14010,0x14010,0xa,0x8,0x0,0x0,0x8000,0x0,0x1,0x0,0x0,0x1,0x3,0x1,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf00c,0xf00c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3000,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3fc00003,0x3fc00003,0x10,0x400,0x800,0x80000,0x100000,0x40000,0x240,0x240,0x0,0x183,0xc000,0xc000,0x230000,0x230000,0xc000,0xf00c,0xc,0xc,0x0,0xc,0x0,0x3000,0x3000,0x0,0x0,0x0,0x0,0x0,0xf00c,0x0,0x0,0x0,0x0,0x0,0x0,0x3000,0x3000,0x3000,0x0,0x0,0x3fc03003,0x3fc03003,0x3000,0x0,0x3000,0x0,0x0,0x3000,0xf00c,0x3000,0x3000,0x0,0x0,0x0,0xf00c,0x0,0x0,}; + } + private final JJCalls[] jj_2_rtns = new JJCalls[37]; + private boolean jj_rescan = false; + private int jj_gc = 0; + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public JavaCCParser(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new JavaCCParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 160; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 160; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public JavaCCParser(final java.io.Reader stream) { + jj_input_stream = new JavaCharStream(stream, 1, 1); + token_source = new JavaCCParserTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 160; i++) + jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) + jj_2_rtns[i] = new JJCalls(); + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new JavaCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new JavaCCParserTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 160; i++) + jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) + jj_2_rtns[i] = new JJCalls(); + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public JavaCCParser(final JavaCCParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 160; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final JavaCCParserTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 160; i++) jj_la1[i] = -1; + for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + if (++jj_gc > 100) { + jj_gc = 0; + for (int i = 0; i < jj_2_rtns.length; i++) { + JJCalls c = jj_2_rtns[i]; + while (c != null) { + if (c.gen < jj_gen) + c.first = null; + c = c.next; + } + } + } + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + private static final class LookaheadSuccess extends IllegalStateException {} + private final LookaheadSuccess jj_ls = new LookaheadSuccess(); + private boolean jj_scan_token(int kind) { + if (jj_scanpos == jj_lastpos) { + jj_la--; + if (jj_scanpos.next == null) { + jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); + } else { + jj_lastpos = jj_scanpos = jj_scanpos.next; + } + } else { + jj_scanpos = jj_scanpos.next; + } + if (jj_rescan) { + int i = 0; Token tok = token; + while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } + if (tok != null) jj_add_error_token(kind, i); + } + if (jj_scanpos.kind != kind) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; + return false; + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + private int[] jj_lasttokens = new int[100]; + private int jj_endpos; + + private void jj_add_error_token(int kind, int pos) { + if (pos >= 100) { + return; + } + + if (pos == jj_endpos + 1) { + jj_lasttokens[jj_endpos++] = kind; + } else if (jj_endpos != 0) { + jj_expentry = new int[jj_endpos]; + + for (int i = 0; i < jj_endpos; i++) { + jj_expentry[i] = jj_lasttokens[i]; + } + + for (final int[] oldentry : jj_expentries) { + if (oldentry.length == jj_expentry.length) { + boolean isMatched = true; + for (int i = 0; i < jj_expentry.length; i++) { + if (oldentry[i] != jj_expentry[i]) { + isMatched = false; + break; + } + } + if (isMatched) { + jj_expentries.add(jj_expentry); + break; + } + } + } + + if (pos != 0) { + jj_endpos = pos; + jj_lasttokens[jj_endpos - 1] = kind; + } + } +} + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[127]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 160; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + + private void jj_rescan_token() { + jj_rescan = true; + for (int i = 0; i < 37; i++) { + try { + JJCalls p = jj_2_rtns[i]; + do { + if (p.gen > jj_gen) { + jj_la = p.arg; + jj_scanpos = p.first; + jj_lastpos = p.first; + switch (i) { + case 0: jj_3_1(); break; + case 1: jj_3_2(); break; + case 2: jj_3_3(); break; + case 3: jj_3_4(); break; + case 4: jj_3_5(); break; + case 5: jj_3_6(); break; + case 6: jj_3_7(); break; + case 7: jj_3_8(); break; + case 8: jj_3_9(); break; + case 9: jj_3_10(); break; + case 10: jj_3_11(); break; + case 11: jj_3_12(); break; + case 12: jj_3_13(); break; + case 13: jj_3_14(); break; + case 14: jj_3_15(); break; + case 15: jj_3_16(); break; + case 16: jj_3_17(); break; + case 17: jj_3_18(); break; + case 18: jj_3_19(); break; + case 19: jj_3_20(); break; + case 20: jj_3_21(); break; + case 21: jj_3_22(); break; + case 22: jj_3_23(); break; + case 23: jj_3_24(); break; + case 24: jj_3_25(); break; + case 25: jj_3_26(); break; + case 26: jj_3_27(); break; + case 27: jj_3_28(); break; + case 28: jj_3_29(); break; + case 29: jj_3_30(); break; + case 30: jj_3_31(); break; + case 31: jj_3_32(); break; + case 32: jj_3_33(); break; + case 33: jj_3_34(); break; + case 34: jj_3_35(); break; + case 35: jj_3_36(); break; + case 36: jj_3_37(); break; + } + } + p = p.next; + } while (p != null); + } catch(LookaheadSuccess ls) { /* ignore */ } + } + jj_rescan = false; + } + + private void jj_save(int index, int xla) { + JJCalls p = jj_2_rtns[index]; + while (p.gen > jj_gen) { + if (p.next == null) { + p.next = new JJCalls(); + p = p.next; + break; + } + p = p.next; + } + p.gen = jj_gen + xla - jj_la; + p.first = token; + p.arg = xla; + } + + static final class JJCalls { + int gen; + Token first; + int arg; + JJCalls next; + } + +} diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParserConstants.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParserConstants.java new file mode 100644 index 00000000..537901a1 --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCCParserConstants.java @@ -0,0 +1,384 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. JavaCCParserConstants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface JavaCCParserConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int _OPTIONS = 1; + /** RegularExpression Id. */ + int _LOOKAHEAD = 2; + /** RegularExpression Id. */ + int _IGNORE_CASE = 3; + /** RegularExpression Id. */ + int _PARSER_BEGIN = 4; + /** RegularExpression Id. */ + int _PARSER_END = 5; + /** RegularExpression Id. */ + int _JAVACODE = 6; + /** RegularExpression Id. */ + int _TOKEN = 7; + /** RegularExpression Id. */ + int _SPECIAL_TOKEN = 8; + /** RegularExpression Id. */ + int _MORE = 9; + /** RegularExpression Id. */ + int _SKIP = 10; + /** RegularExpression Id. */ + int _TOKEN_MGR_DECLS = 11; + /** RegularExpression Id. */ + int _EOF = 12; + /** RegularExpression Id. */ + int SINGLE_LINE_COMMENT = 21; + /** RegularExpression Id. */ + int FORMAL_COMMENT = 22; + /** RegularExpression Id. */ + int MULTI_LINE_COMMENT = 23; + /** RegularExpression Id. */ + int ABSTRACT = 25; + /** RegularExpression Id. */ + int BOOLEAN = 26; + /** RegularExpression Id. */ + int BREAK = 27; + /** RegularExpression Id. */ + int BYTE = 28; + /** RegularExpression Id. */ + int CASE = 29; + /** RegularExpression Id. */ + int CATCH = 30; + /** RegularExpression Id. */ + int CHAR = 31; + /** RegularExpression Id. */ + int CLASS = 32; + /** RegularExpression Id. */ + int CONST = 33; + /** RegularExpression Id. */ + int CONTINUE = 34; + /** RegularExpression Id. */ + int _DEFAULT = 35; + /** RegularExpression Id. */ + int DO = 36; + /** RegularExpression Id. */ + int DOUBLE = 37; + /** RegularExpression Id. */ + int ELSE = 38; + /** RegularExpression Id. */ + int EXTENDS = 39; + /** RegularExpression Id. */ + int FALSE = 40; + /** RegularExpression Id. */ + int FINAL = 41; + /** RegularExpression Id. */ + int FINALLY = 42; + /** RegularExpression Id. */ + int FLOAT = 43; + /** RegularExpression Id. */ + int FOR = 44; + /** RegularExpression Id. */ + int GOTO = 45; + /** RegularExpression Id. */ + int IF = 46; + /** RegularExpression Id. */ + int IMPLEMENTS = 47; + /** RegularExpression Id. */ + int IMPORT = 48; + /** RegularExpression Id. */ + int INSTANCEOF = 49; + /** RegularExpression Id. */ + int INT = 50; + /** RegularExpression Id. */ + int INTERFACE = 51; + /** RegularExpression Id. */ + int LONG = 52; + /** RegularExpression Id. */ + int NATIVE = 53; + /** RegularExpression Id. */ + int NEW = 54; + /** RegularExpression Id. */ + int NULL = 55; + /** RegularExpression Id. */ + int PACKAGE = 56; + /** RegularExpression Id. */ + int PRIVATE = 57; + /** RegularExpression Id. */ + int PROTECTED = 58; + /** RegularExpression Id. */ + int PUBLIC = 59; + /** RegularExpression Id. */ + int RETURN = 60; + /** RegularExpression Id. */ + int SHORT = 61; + /** RegularExpression Id. */ + int STATIC = 62; + /** RegularExpression Id. */ + int SUPER = 63; + /** RegularExpression Id. */ + int SWITCH = 64; + /** RegularExpression Id. */ + int SYNCHRONIZED = 65; + /** RegularExpression Id. */ + int THIS = 66; + /** RegularExpression Id. */ + int THROW = 67; + /** RegularExpression Id. */ + int THROWS = 68; + /** RegularExpression Id. */ + int TRANSIENT = 69; + /** RegularExpression Id. */ + int TRUE = 70; + /** RegularExpression Id. */ + int TRY = 71; + /** RegularExpression Id. */ + int VOID = 72; + /** RegularExpression Id. */ + int VOLATILE = 73; + /** RegularExpression Id. */ + int WHILE = 74; + /** RegularExpression Id. */ + int INTEGER_LITERAL = 75; + /** RegularExpression Id. */ + int DECIMAL_LITERAL = 76; + /** RegularExpression Id. */ + int HEX_LITERAL = 77; + /** RegularExpression Id. */ + int OCTAL_LITERAL = 78; + /** RegularExpression Id. */ + int FLOATING_POINT_LITERAL = 79; + /** RegularExpression Id. */ + int EXPONENT = 80; + /** RegularExpression Id. */ + int CHARACTER_LITERAL = 81; + /** RegularExpression Id. */ + int STRING_LITERAL = 82; + /** RegularExpression Id. */ + int IDENTIFIER = 83; + /** RegularExpression Id. */ + int LETTER = 84; + /** RegularExpression Id. */ + int DIGIT = 85; + /** RegularExpression Id. */ + int LPAREN = 86; + /** RegularExpression Id. */ + int RPAREN = 87; + /** RegularExpression Id. */ + int LBRACE = 88; + /** RegularExpression Id. */ + int RBRACE = 89; + /** RegularExpression Id. */ + int LBRACKET = 90; + /** RegularExpression Id. */ + int RBRACKET = 91; + /** RegularExpression Id. */ + int SEMICOLON = 92; + /** RegularExpression Id. */ + int COMMA = 93; + /** RegularExpression Id. */ + int DOT = 94; + /** RegularExpression Id. */ + int ASSIGN = 95; + /** RegularExpression Id. */ + int GT = 96; + /** RegularExpression Id. */ + int LT = 97; + /** RegularExpression Id. */ + int BANG = 98; + /** RegularExpression Id. */ + int TILDE = 99; + /** RegularExpression Id. */ + int HOOK = 100; + /** RegularExpression Id. */ + int COLON = 101; + /** RegularExpression Id. */ + int EQ = 102; + /** RegularExpression Id. */ + int LE = 103; + /** RegularExpression Id. */ + int GE = 104; + /** RegularExpression Id. */ + int NE = 105; + /** RegularExpression Id. */ + int SC_OR = 106; + /** RegularExpression Id. */ + int SC_AND = 107; + /** RegularExpression Id. */ + int INCR = 108; + /** RegularExpression Id. */ + int DECR = 109; + /** RegularExpression Id. */ + int PLUS = 110; + /** RegularExpression Id. */ + int MINUS = 111; + /** RegularExpression Id. */ + int STAR = 112; + /** RegularExpression Id. */ + int SLASH = 113; + /** RegularExpression Id. */ + int BIT_AND = 114; + /** RegularExpression Id. */ + int BIT_OR = 115; + /** RegularExpression Id. */ + int XOR = 116; + /** RegularExpression Id. */ + int REM = 117; + /** RegularExpression Id. */ + int PLUSASSIGN = 118; + /** RegularExpression Id. */ + int MINUSASSIGN = 119; + /** RegularExpression Id. */ + int STARASSIGN = 120; + /** RegularExpression Id. */ + int SLASHASSIGN = 121; + /** RegularExpression Id. */ + int ANDASSIGN = 122; + /** RegularExpression Id. */ + int ORASSIGN = 123; + /** RegularExpression Id. */ + int XORASSIGN = 124; + /** RegularExpression Id. */ + int REMASSIGN = 125; + + /** Lexical state. */ + int DEFAULT = 0; + /** Lexical state. */ + int IN_SINGLE_LINE_COMMENT = 1; + /** Lexical state. */ + int IN_FORMAL_COMMENT = 2; + /** Lexical state. */ + int IN_MULTI_LINE_COMMENT = 3; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\"options\"", + "\"LOOKAHEAD\"", + "\"IGNORE_CASE\"", + "\"PARSER_BEGIN\"", + "\"PARSER_END\"", + "\"JAVACODE\"", + "\"TOKEN\"", + "\"SPECIAL_TOKEN\"", + "\"MORE\"", + "\"SKIP\"", + "\"TOKEN_MGR_DECLS\"", + "\"EOF\"", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"\\f\"", + "\"//\"", + "", + "\"/*\"", + "", + "\"*/\"", + "\"*/\"", + "", + "\"abstract\"", + "\"boolean\"", + "\"break\"", + "\"byte\"", + "\"case\"", + "\"catch\"", + "\"char\"", + "\"class\"", + "\"const\"", + "\"continue\"", + "\"default\"", + "\"do\"", + "\"double\"", + "\"else\"", + "\"extends\"", + "\"false\"", + "\"final\"", + "\"finally\"", + "\"float\"", + "\"for\"", + "\"goto\"", + "\"if\"", + "\"implements\"", + "\"import\"", + "\"instanceof\"", + "\"int\"", + "\"interface\"", + "\"long\"", + "\"native\"", + "\"new\"", + "\"null\"", + "\"package\"", + "\"private\"", + "\"protected\"", + "\"public\"", + "\"return\"", + "\"short\"", + "\"static\"", + "\"super\"", + "\"switch\"", + "\"synchronized\"", + "\"this\"", + "\"throw\"", + "\"throws\"", + "\"transient\"", + "\"true\"", + "\"try\"", + "\"void\"", + "\"volatile\"", + "\"while\"", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "\"(\"", + "\")\"", + "\"{\"", + "\"}\"", + "\"[\"", + "\"]\"", + "\";\"", + "\",\"", + "\".\"", + "\"=\"", + "\">\"", + "\"<\"", + "\"!\"", + "\"~\"", + "\"?\"", + "\":\"", + "\"==\"", + "\"<=\"", + "\">=\"", + "\"!=\"", + "\"||\"", + "\"&&\"", + "\"++\"", + "\"--\"", + "\"+\"", + "\"-\"", + "\"*\"", + "\"/\"", + "\"&\"", + "\"|\"", + "\"^\"", + "\"%\"", + "\"+=\"", + "\"-=\"", + "\"*=\"", + "\"/=\"", + "\"&=\"", + "\"|=\"", + "\"^=\"", + "\"%=\"", + "\"#\"", + }; + +} diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCharStream.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCharStream.java new file mode 100644 index 00000000..01a76c7e --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/JavaCharStream.java @@ -0,0 +1,326 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. JavaCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (with java-like unicode escape processing). + */ +public +class JavaCharStream extends AbstractCharStream +{ + /** Predefined buffer size */ + protected static final int NEXTCHAR_BUF_SIZE = 4096; + + private char[] m_aNextCharBuf; + private int nextCharInd = -1; + private java.io.Reader m_aIS; + + @Override + protected int streamRead(final char[] buffer, final int offset, final int len) throws java.io.IOException + { + return m_aIS.read (buffer, offset, len); + } + + @Override + protected void streamClose() throws java.io.IOException + { + m_aIS.close (); + } + + @Override + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == NEXTCHAR_BUF_SIZE) + { + maxNextCharInd = 0; + nextCharInd = 0; + } + + try + { + final int nCharsRead = streamRead (m_aNextCharBuf, maxNextCharInd, NEXTCHAR_BUF_SIZE - maxNextCharInd); + if (nCharsRead == -1) + { + streamClose (); + throw new java.io.IOException (); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + if (bufpos != 0) + { + --bufpos; + backup(0); + } + else + internalSetBufLineColumn (getLine (), getColumn ()); + throw ex; + } + } + + private char readByte() throws java.io.IOException + { + ++nextCharInd; + if (nextCharInd >= maxNextCharInd) + fillBuff(); + + return m_aNextCharBuf[nextCharInd]; + } + + @Override + public char beginToken() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + + if (++bufpos == bufsize) + bufpos = 0; + + tokenBegin = bufpos; + return buffer[bufpos]; + } + + tokenBegin = 0; + bufpos = -1; + + return readChar(); + } + + @Override + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + --inBuf; + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos == available) + internalAdjustBuffSize(); + + char c = readByte(); + buffer[bufpos] = c; + if (c != '\\') + { + // Not a backslash + if (isTrackLineColumn()) + internalUpdateLineColumn(c); + return c; + } + + if (isTrackLineColumn()) + internalUpdateLineColumn(c); + + int backSlashCnt = 1; + + // Read all the backslashes + for (;;) + { + ++bufpos; + if (bufpos == available) + internalAdjustBuffSize(); + + try + { + c = readByte(); + buffer[bufpos] = c; + if (c != '\\') + { + // found a non-backslash char. + if (isTrackLineColumn()) + internalUpdateLineColumn(c); + + if (c == 'u' && (backSlashCnt & 1) == 1) + { + --bufpos; + if (bufpos < 0) + { + // Buffer underflow + bufpos = bufsize - 1; + } + + // Found the start of a Unicode sequence + break; + } + + // Unsupported escape sequence + backup(backSlashCnt); + return '\\'; + } + } + catch (final java.io.IOException e) + { + // We are returning one backslash so we should only backup (count-1) + if (backSlashCnt > 1) + backup (backSlashCnt - 1); + + return '\\'; + } + + // We read another backslash + + if (isTrackLineColumn()) + internalUpdateLineColumn (c); + backSlashCnt++; + } + + // Here, we have seen an odd number of backslash's followed by a 'u' + try + { + // Skip all 'u' as in '\uuuuuu1234' + while ((c = readByte()) == 'u') + { + if (isTrackLineColumn()) + internalUpdateLineColumn(c); + } + + final char c1 = c; + final char c2 = readByte(); + final char c3 = readByte(); + final char c4 = readByte(); + c = (char) (hexval(c1) << 12 | + hexval(c2) << 8 | + hexval(c3) << 4 | + hexval(c4)); + buffer[bufpos] = c; + + if (isTrackLineColumn()) + { + internalUpdateLineColumn(c1); + internalUpdateLineColumn(c2); + internalUpdateLineColumn(c3); + internalUpdateLineColumn(c4); + } + } + catch (final java.io.IOException ex) + { + throw new IllegalStateException("Invalid escape character at line " + getLine () + " column " + getColumn () + "."); + } + + if (backSlashCnt == 1) + return c; + + backup(backSlashCnt - 1); + return '\\'; + } + + /** Constructor. */ + public JavaCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aNextCharBuf = new char[NEXTCHAR_BUF_SIZE]; + m_aIS = dstream; + } + + /** Constructor. */ + public JavaCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public JavaCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aNextCharBuf = new char[NEXTCHAR_BUF_SIZE]; + nextCharInd = -1; + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Constructor. */ + public JavaCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public JavaCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public JavaCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + public void done () + { + m_aNextCharBuf = null; + super.done (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a3e3503fdf48065c8b7b185326a8c00f (do not edit this line) */ diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/ParseException.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/Token.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/JavaCCGrammar/JavaCC/TokenMgrException.java b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/JavaCCGrammar/JavaCC/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/Lookahead/Example1/AbstractCharStream.java b/src/test/resources/outputTest/Lookahead/Example1/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/Lookahead/Example1/CharStream.java b/src/test/resources/outputTest/Lookahead/Example1/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/Lookahead/Example1/Example.java b/src/test/resources/outputTest/Lookahead/Example1/Example.java new file mode 100644 index 00000000..1b6e52b7 --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/Example.java @@ -0,0 +1,252 @@ +/* Example.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Example.java */ +public class Example implements ExampleConstants { + + public static void main(String args[]) throws ParseException { + Example parser = new Example(System.in); + parser.Input(); + } + + final public void Input() throws ParseException { + jj_consume_token(5); + BC(); + jj_consume_token(6); +} + + final public void BC() throws ParseException { + jj_consume_token(7); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 6:{ + jj_consume_token(6); + break; + } + default: + jj_la1[0] = jj_gen; + ; + } +} + + /** Generated Token Manager. */ + public ExampleTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[1]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x40,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public Example(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new ExampleTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public Example(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new ExampleTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new ExampleTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public Example(final ExampleTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final ExampleTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[8]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 1; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/Lookahead/Example1/ExampleConstants.java b/src/test/resources/outputTest/Lookahead/Example1/ExampleConstants.java new file mode 100644 index 00000000..2765e608 --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/ExampleConstants.java @@ -0,0 +1,27 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ExampleConstants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface ExampleConstants { + + /** End of File. */ + int EOF = 0; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"a\"", + "\"c\"", + "\"b\"", + }; + +} diff --git a/src/test/resources/outputTest/Lookahead/Example1/ExampleTokenManager.java b/src/test/resources/outputTest/Lookahead/Example1/ExampleTokenManager.java new file mode 100644 index 00000000..6d8a4509 --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/ExampleTokenManager.java @@ -0,0 +1,261 @@ +/* ExampleTokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. ExampleTokenManager.java */ + +/** Token Manager. */ +public class ExampleTokenManager implements ExampleConstants { +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + case 'a': + return jjStopAtPos(0, 5); + case 'b': + return jjStopAtPos(0, 7); + case 'c': + return jjStopAtPos(0, 6); + default : + return 1; + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, "\141", "\143", "\142", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = {0 +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { + input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0x0L) + curChar = input_stream.beginToken(); + } + catch (final java.io.IOException e1) { + continue EOFLoop; + } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + + /** Constructor. */ + public ExampleTokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public ExampleTokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 0; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 1 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0xe1L, +}; +static final long[] jjtoSkip = { + 0x1eL, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[0]; + private final int[] jjstateSet = new int[2 * 0]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/Lookahead/Example1/ParseException.java b/src/test/resources/outputTest/Lookahead/Example1/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/Lookahead/Example1/SimpleCharStream.java b/src/test/resources/outputTest/Lookahead/Example1/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/Lookahead/Example1/Token.java b/src/test/resources/outputTest/Lookahead/Example1/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/Lookahead/Example1/TokenMgrException.java b/src/test/resources/outputTest/Lookahead/Example1/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/Lookahead/Example1/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Digest/AbstractCharStream.java b/src/test/resources/outputTest/MailProcessing/Digest/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Digest/CharStream.java b/src/test/resources/outputTest/MailProcessing/Digest/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Digest/Digest.java b/src/test/resources/outputTest/MailProcessing/Digest/Digest.java new file mode 100644 index 00000000..8d2317bb --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/Digest.java @@ -0,0 +1,333 @@ +/* Digest.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Digest.java */ +import java.io.*; + +public class Digest implements DigestConstants { + + static int count = 0; + + static String buffer = ""; + + public static void main(String args[]) throws ParseException { + Digest parser = new Digest(System.in); + System.out.println("DIGEST OF RECENT MESSAGES FROM THE JAVACC MAILING LIST"); + System.out.println("----------------------------------------------------------------------"); + System.out.println(""); + System.out.println("MESSAGE SUMMARY:"); + System.out.println(""); + parser.MailFile(); + if (count == 0) { + System.out.println("There have been no messages since the last digest posting."); + System.out.println(""); + System.out.println("----------------------------------------------------------------------"); + } else { + System.out.println(""); + System.out.println("----------------------------------------------------------------------"); + System.out.println(""); + System.out.println(buffer); + } + } + +// PARSER SPECIFICATIONS BEGIN HERE + final public +void MailFile() throws ParseException { + label_1: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SUBJECT: + case FROM: + case DATE:{ + break; + } + default: + jj_la1[0] = jj_gen; + break label_1; + } +count++; + MailMessage(); + } + jj_consume_token(0); +} + + final public void MailMessage() throws ParseException {Token subj=null, from=null, date=null, body; + label_2: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SUBJECT:{ + subj = jj_consume_token(SUBJECT); + break; + } + case FROM:{ + from = jj_consume_token(FROM); + break; + } + case DATE:{ + date = jj_consume_token(DATE); + break; + } + default: + jj_la1[1] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SUBJECT: + case FROM: + case DATE:{ + break; + } + default: + jj_la1[2] = jj_gen; + break label_2; + } + } +System.out.println(count + ". " + ((subj==null) ? "no subject" : subj.image)); + buffer += "\n"; + buffer += "Message " + count + ":\n"; + buffer += "\n"; + buffer += "Subject: " + ((subj==null) ? "no subject" : subj.image) + "\n"; + buffer += "From: " + ((from==null) ? "" : from.image) + "\n"; + buffer += "Date: " + ((date==null) ? "" : date.image) + "\n"; + buffer += "\n"; + label_3: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BODY:{ + break; + } + default: + jj_la1[3] = jj_gen; + break label_3; + } + body = jj_consume_token(BODY); +buffer += body.image; + } + jj_consume_token(END); +buffer += "\n"; + buffer += "----------------------------------------------------------------------\n"; +} + + /** Generated Token Manager. */ + public DigestTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[4]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0xa800,0xa800,0xa800,0x20000,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public Digest(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new DigestTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public Digest(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new DigestTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new DigestTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public Digest(final DigestTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final DigestTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[19]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 4; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/MailProcessing/Digest/DigestConstants.java b/src/test/resources/outputTest/MailProcessing/Digest/DigestConstants.java new file mode 100644 index 00000000..d946f1d7 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/DigestConstants.java @@ -0,0 +1,72 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. DigestConstants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface DigestConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int EOL = 1; + /** RegularExpression Id. */ + int TWOEOLS = 2; + /** RegularExpression Id. */ + int NOT_EOL = 3; + /** RegularExpression Id. */ + int _TWOEOLS = 6; + /** RegularExpression Id. */ + int SUBJECT = 11; + /** RegularExpression Id. */ + int _EOL1 = 12; + /** RegularExpression Id. */ + int FROM = 13; + /** RegularExpression Id. */ + int _EOL2 = 14; + /** RegularExpression Id. */ + int DATE = 15; + /** RegularExpression Id. */ + int _EOL3 = 16; + /** RegularExpression Id. */ + int BODY = 17; + /** RegularExpression Id. */ + int END = 18; + + /** Lexical state. */ + int DEFAULT = 0; + /** Lexical state. */ + int MAILHEADER = 1; + /** Lexical state. */ + int MAILSUBJECT = 2; + /** Lexical state. */ + int MAILFROM = 3; + /** Lexical state. */ + int MAILDATE = 4; + /** Lexical state. */ + int MAILBODY = 5; + + /** Literal token values. */ + String[] tokenImage = { + "", + "", + "", + "", + "", + "", + "<_TWOEOLS>", + "\"Subject: \"", + "\"From: \"", + "\"Date: \"", + "", + "", + "<_EOL1>", + "", + "<_EOL2>", + "", + "<_EOL3>", + "", + "\"\\u001f\"", + }; + +} diff --git a/src/test/resources/outputTest/MailProcessing/Digest/DigestTokenManager.java b/src/test/resources/outputTest/MailProcessing/Digest/DigestTokenManager.java new file mode 100644 index 00000000..288cb951 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/DigestTokenManager.java @@ -0,0 +1,1148 @@ +/* DigestTokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. DigestTokenManager.java */ +import java.io.*; + +/** Token Manager. */ +@SuppressWarnings ("unused") +public class DigestTokenManager implements DigestConstants { +private int jjMoveStringLiteralDfa0_0() +{ + return jjMoveNfa_0(0, 0); +} +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 18; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x2400L & l) != 0x0L) + { jjCheckNAdd(15); } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 1: + if (curChar == 42) + { jjAddStates(0, 1); } + break; + case 2: + if ((0x2400L & l) != 0x0L && kind > 4) + kind = 4; + break; + case 3: + if (curChar == 10 && kind > 4) + kind = 4; + break; + case 4: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 3; + break; + case 5: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 1; + break; + case 6: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 5; + break; + case 7: + if (curChar == 32) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 12: + if (curChar == 32) + jjstateSet[jjnewStateCnt++] = 11; + break; + case 13: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 12; + break; + case 14: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 13; + break; + case 15: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 14; + break; + case 16: + if (curChar == 10) + { jjCheckNAdd(15); } + break; + case 17: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 16; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 8: + if (curChar == 72) + jjstateSet[jjnewStateCnt++] = 7; + break; + case 9: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 8; + break; + case 10: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 9; + break; + case 11: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 10; + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 18 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private final int jjStopStringLiteralDfa_1(int pos, long active0){ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_1(int pos, long active0){ + return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_1(){ + switch(curChar) + { + case 'D': + return jjMoveStringLiteralDfa1_1(0x200L); + case 'F': + return jjMoveStringLiteralDfa1_1(0x100L); + case 'S': + return jjMoveStringLiteralDfa1_1(0x80L); + default : + return jjMoveNfa_1(0, 0); + } +} +private int jjMoveStringLiteralDfa1_1(long active0){ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(0, active0); + return 1; + } + switch(curChar) + { + case 'a': + return jjMoveStringLiteralDfa2_1(active0, 0x200L); + case 'r': + return jjMoveStringLiteralDfa2_1(active0, 0x100L); + case 'u': + return jjMoveStringLiteralDfa2_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(0, active0); +} +private int jjMoveStringLiteralDfa2_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(1, active0); + return 2; + } + switch(curChar) + { + case 'b': + return jjMoveStringLiteralDfa3_1(active0, 0x80L); + case 'o': + return jjMoveStringLiteralDfa3_1(active0, 0x100L); + case 't': + return jjMoveStringLiteralDfa3_1(active0, 0x200L); + default : + break; + } + return jjStartNfa_1(1, active0); +} +private int jjMoveStringLiteralDfa3_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(2, active0); + return 3; + } + switch(curChar) + { + case 'e': + return jjMoveStringLiteralDfa4_1(active0, 0x200L); + case 'j': + return jjMoveStringLiteralDfa4_1(active0, 0x80L); + case 'm': + return jjMoveStringLiteralDfa4_1(active0, 0x100L); + default : + break; + } + return jjStartNfa_1(2, active0); +} +private int jjMoveStringLiteralDfa4_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(2, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(3, active0); + return 4; + } + switch(curChar) + { + case ':': + return jjMoveStringLiteralDfa5_1(active0, 0x300L); + case 'e': + return jjMoveStringLiteralDfa5_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(3, active0); +} +private int jjMoveStringLiteralDfa5_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(3, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(4, active0); + return 5; + } + switch(curChar) + { + case ' ': + if ((active0 & 0x100L) != 0x0L) + return jjStopAtPos(5, 8); + else if ((active0 & 0x200L) != 0x0L) + return jjStopAtPos(5, 9); + break; + case 'c': + return jjMoveStringLiteralDfa6_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(4, active0); +} +private int jjMoveStringLiteralDfa6_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(4, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(5, active0); + return 6; + } + switch(curChar) + { + case 't': + return jjMoveStringLiteralDfa7_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(5, active0); +} +private int jjMoveStringLiteralDfa7_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(5, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(6, active0); + return 7; + } + switch(curChar) + { + case ':': + return jjMoveStringLiteralDfa8_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(6, active0); +} +private int jjMoveStringLiteralDfa8_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(6, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(7, active0); + return 8; + } + switch(curChar) + { + case ' ': + if ((active0 & 0x80L) != 0x0L) + return jjStopAtPos(8, 7); + break; + default : + break; + } + return jjStartNfa_1(7, active0); +} +private int jjMoveNfa_1(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 8; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if (curChar == 13) + { jjAddStates(2, 3); } + else if (curChar == 10) + { jjCheckNAddTwoStates(1, 3); } + break; + case 1: + if ((0x2400L & l) != 0x0L && kind > 6) + kind = 6; + break; + case 2: + case 7: + if (curChar == 10 && kind > 6) + kind = 6; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 4: + if (curChar == 13) + { jjAddStates(2, 3); } + break; + case 5: + if (curChar == 10) + { jjCheckNAddTwoStates(1, 3); } + break; + case 6: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 7; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 8 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private int jjMoveStringLiteralDfa0_2() +{ + return jjMoveNfa_2(1, 0); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_2(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 1: + if ((0xffffffffffffdbffL & l) != 0x0L) + { + if (kind > 11) + kind = 11; + { jjCheckNAdd(0); } + } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 12) + kind = 12; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffffffffdbffL & l) == 0x0L) + break; + kind = 11; + { jjCheckNAdd(0); } + break; + case 2: + if (curChar == 10 && kind > 12) + kind = 12; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + kind = 11; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 11) + kind = 11; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private int jjMoveStringLiteralDfa0_3() +{ + return jjMoveNfa_3(1, 0); +} +private int jjMoveNfa_3(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 1: + if ((0xffffffffffffdbffL & l) != 0x0L) + { + if (kind > 13) + kind = 13; + { jjCheckNAdd(0); } + } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 14) + kind = 14; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffffffffdbffL & l) == 0x0L) + break; + kind = 13; + { jjCheckNAdd(0); } + break; + case 2: + if (curChar == 10 && kind > 14) + kind = 14; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + kind = 13; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 13) + kind = 13; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private int jjMoveStringLiteralDfa0_4() +{ + return jjMoveNfa_4(1, 0); +} +private int jjMoveNfa_4(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 1: + if ((0xffffffffffffdbffL & l) != 0x0L) + { + if (kind > 15) + kind = 15; + { jjCheckNAdd(0); } + } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 16) + kind = 16; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffffffffdbffL & l) == 0x0L) + break; + kind = 15; + { jjCheckNAdd(0); } + break; + case 2: + if (curChar == 10 && kind > 16) + kind = 16; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + kind = 15; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 15) + kind = 15; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private final int jjStopStringLiteralDfa_5(int pos, long active0){ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_5(int pos, long active0){ + return jjMoveNfa_5(jjStopStringLiteralDfa_5(pos, active0), pos + 1); +} +private int jjMoveStringLiteralDfa0_5(){ + switch(curChar) + { + case 31: + return jjStopAtPos(0, 18); + default : + return jjMoveNfa_5(4, 0); + } +} +private int jjMoveNfa_5(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 4: + if ((0xffffffff7fffdbffL & l) != 0x0L) + { jjCheckNAddStates(4, 6); } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 17) + kind = 17; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffff7fffdbffL & l) != 0x0L) + { jjCheckNAddStates(4, 6); } + break; + case 1: + if ((0x2400L & l) != 0x0L && kind > 17) + kind = 17; + break; + case 2: + if (curChar == 10 && kind > 17) + kind = 17; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 4: + case 0: + { jjCheckNAddStates(4, 6); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 4: + case 0: + if ((jjbitVec0[i2] & l2) != 0L) + { jjCheckNAddStates(4, 6); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, null, null, null, null, null, null, +null, null, null, null, null, "\37", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = { + 2, 4, 5, 6, 0, 1, 3, +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + switch(curLexState) + { + case 0: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedPos == 0 && jjmatchedKind > 5) + { + jjmatchedKind = 5; + } + break; + case 1: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_1(); + if (jjmatchedPos == 0 && jjmatchedKind > 10) + { + jjmatchedKind = 10; + } + break; + case 2: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_2(); + break; + case 3: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_3(); + break; + case 4: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_4(); + break; + case 5: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_5(); + break; + } + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + return matchedToken; + } + else + { + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + + /** Constructor. */ + public DigestTokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public DigestTokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 18; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 6 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", + "MAILHEADER", + "MAILSUBJECT", + "MAILFROM", + "MAILDATE", + "MAILBODY", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, 1, -1, 5, 2, 3, 4, -1, -1, 1, -1, 1, -1, 1, -1, 0, +}; +static final long[] jjtoToken = { + 0x6a801L, +}; +static final long[] jjtoSkip = { + 0x157f0L, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[18]; + private final int[] jjstateSet = new int[2 * 18]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/MailProcessing/Digest/ParseException.java b/src/test/resources/outputTest/MailProcessing/Digest/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Digest/SimpleCharStream.java b/src/test/resources/outputTest/MailProcessing/Digest/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Digest/Token.java b/src/test/resources/outputTest/MailProcessing/Digest/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Digest/TokenMgrException.java b/src/test/resources/outputTest/MailProcessing/Digest/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Digest/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Faq/AbstractCharStream.java b/src/test/resources/outputTest/MailProcessing/Faq/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Faq/CharStream.java b/src/test/resources/outputTest/MailProcessing/Faq/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Faq/Faq.java b/src/test/resources/outputTest/MailProcessing/Faq/Faq.java new file mode 100644 index 00000000..66aac9f9 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/Faq.java @@ -0,0 +1,368 @@ +/* Faq.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Faq.java */ +import java.io.*; + +public class Faq implements FaqConstants { + + static int count = 0; + + static int beginAt = 1; + + static PrintWriter indstr; + + static { + try { + indstr = new PrintWriter(new FileWriter("index.html")); + indstr.println("Selected list of emails from the JavaCC mailing list"); + indstr.println("

Selected list of emails from the JavaCC mailing list

"); + } catch (IOException e) { + throw new Error(); + } + } + + static String fix(String s) { + String retval = ""; + for (int i = 0; i < s.length(); i++) { + char c = s.charAt(i); + if (c == '<') { + retval += "<"; + } else if (c == '>') { + retval += ">"; + } else { + retval += c; + } + } + return retval; + } + + public static void main(String args[]) throws ParseException { + if (args.length == 1) { + beginAt = Integer.parseInt(args[0]); + } + Faq parser = new Faq(System.in); + parser.MailFile(); + } + +// PARSER SPECIFICATIONS BEGIN HERE + final public +void MailFile() throws ParseException { + label_1: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SUBJECT: + case FROM: + case DATE:{ + break; + } + default: + jj_la1[0] = jj_gen; + break label_1; + } +count++; + MailMessage(); +System.out.print(count + "."); + System.out.flush(); + } + jj_consume_token(0); +System.out.println(""); + indstr.close(); +} + + final public void MailMessage() throws ParseException {PrintWriter msgstr = null; + Token subj=null, from=null, date=null, body; + if (count >= beginAt) { + try { + msgstr = new PrintWriter(new FileWriter(count + ".html")); + } catch (IOException e) { + throw new Error(); + } + } + label_2: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SUBJECT:{ + subj = jj_consume_token(SUBJECT); + break; + } + case FROM:{ + from = jj_consume_token(FROM); + break; + } + case DATE:{ + date = jj_consume_token(DATE); + break; + } + default: + jj_la1[1] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case SUBJECT: + case FROM: + case DATE:{ + break; + } + default: + jj_la1[2] = jj_gen; + break label_2; + } + } +indstr.print(""); + if (subj == null) { + indstr.println("no subject
"); + } else { + indstr.println(fix(subj.image) + "
"); + } + if (count >= beginAt) { + msgstr.println("" + ((subj==null) ? "no subject" : fix(subj.image)) + ""); + msgstr.println("Subject: " + ((subj==null) ? "no subject" : fix(subj.image)) + "
"); + msgstr.println("From: " + ((from==null) ? "" : fix(from.image)) + "
"); + msgstr.println("Date: " + ((date==null) ? "" : fix(date.image)) + "
"); + msgstr.println("
"); + } + label_3: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case BODY:{ + break; + } + default: + jj_la1[3] = jj_gen; + break label_3; + } + body = jj_consume_token(BODY); +if (count >= beginAt) { + msgstr.print(fix(body.image) + "
"); + } + } + jj_consume_token(END); +if (count >= beginAt) { + msgstr.close(); + } +} + + /** Generated Token Manager. */ + public FaqTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[4]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0xa800,0xa800,0xa800,0x20000,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public Faq(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new FaqTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public Faq(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new FaqTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new FaqTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public Faq(final FaqTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final FaqTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[19]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 4; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/MailProcessing/Faq/FaqConstants.java b/src/test/resources/outputTest/MailProcessing/Faq/FaqConstants.java new file mode 100644 index 00000000..e6ed565e --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/FaqConstants.java @@ -0,0 +1,72 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. FaqConstants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface FaqConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int EOL = 1; + /** RegularExpression Id. */ + int TWOEOLS = 2; + /** RegularExpression Id. */ + int NOT_EOL = 3; + /** RegularExpression Id. */ + int _TWOEOLS = 6; + /** RegularExpression Id. */ + int SUBJECT = 11; + /** RegularExpression Id. */ + int _EOL1 = 12; + /** RegularExpression Id. */ + int FROM = 13; + /** RegularExpression Id. */ + int _EOL2 = 14; + /** RegularExpression Id. */ + int DATE = 15; + /** RegularExpression Id. */ + int _EOL3 = 16; + /** RegularExpression Id. */ + int BODY = 17; + /** RegularExpression Id. */ + int END = 18; + + /** Lexical state. */ + int DEFAULT = 0; + /** Lexical state. */ + int MAILHEADER = 1; + /** Lexical state. */ + int MAILSUBJECT = 2; + /** Lexical state. */ + int MAILFROM = 3; + /** Lexical state. */ + int MAILDATE = 4; + /** Lexical state. */ + int MAILBODY = 5; + + /** Literal token values. */ + String[] tokenImage = { + "", + "", + "", + "", + "", + "", + "<_TWOEOLS>", + "\"Subject: \"", + "\"From: \"", + "\"Date: \"", + "", + "", + "<_EOL1>", + "", + "<_EOL2>", + "", + "<_EOL3>", + "", + "\"\\u001f\"", + }; + +} diff --git a/src/test/resources/outputTest/MailProcessing/Faq/FaqTokenManager.java b/src/test/resources/outputTest/MailProcessing/Faq/FaqTokenManager.java new file mode 100644 index 00000000..2bc6ab16 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/FaqTokenManager.java @@ -0,0 +1,1148 @@ +/* FaqTokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. FaqTokenManager.java */ +import java.io.*; + +/** Token Manager. */ +@SuppressWarnings ("unused") +public class FaqTokenManager implements FaqConstants { +private int jjMoveStringLiteralDfa0_0() +{ + return jjMoveNfa_0(0, 0); +} +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 18; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if ((0x2400L & l) != 0x0L) + { jjCheckNAdd(15); } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 16; + break; + case 1: + if (curChar == 42) + { jjAddStates(0, 1); } + break; + case 2: + if ((0x2400L & l) != 0x0L && kind > 4) + kind = 4; + break; + case 3: + if (curChar == 10 && kind > 4) + kind = 4; + break; + case 4: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 3; + break; + case 5: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 1; + break; + case 6: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 5; + break; + case 7: + if (curChar == 32) + jjstateSet[jjnewStateCnt++] = 6; + break; + case 12: + if (curChar == 32) + jjstateSet[jjnewStateCnt++] = 11; + break; + case 13: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 12; + break; + case 14: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 13; + break; + case 15: + if (curChar == 42) + jjstateSet[jjnewStateCnt++] = 14; + break; + case 16: + if (curChar == 10) + { jjCheckNAdd(15); } + break; + case 17: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 16; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 8: + if (curChar == 72) + jjstateSet[jjnewStateCnt++] = 7; + break; + case 9: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 8; + break; + case 10: + if (curChar == 79) + jjstateSet[jjnewStateCnt++] = 9; + break; + case 11: + if (curChar == 69) + jjstateSet[jjnewStateCnt++] = 10; + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 18 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private final int jjStopStringLiteralDfa_1(int pos, long active0){ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_1(int pos, long active0){ + return jjMoveNfa_1(jjStopStringLiteralDfa_1(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_1(){ + switch(curChar) + { + case 'D': + return jjMoveStringLiteralDfa1_1(0x200L); + case 'F': + return jjMoveStringLiteralDfa1_1(0x100L); + case 'S': + return jjMoveStringLiteralDfa1_1(0x80L); + default : + return jjMoveNfa_1(0, 0); + } +} +private int jjMoveStringLiteralDfa1_1(long active0){ + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(0, active0); + return 1; + } + switch(curChar) + { + case 'a': + return jjMoveStringLiteralDfa2_1(active0, 0x200L); + case 'r': + return jjMoveStringLiteralDfa2_1(active0, 0x100L); + case 'u': + return jjMoveStringLiteralDfa2_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(0, active0); +} +private int jjMoveStringLiteralDfa2_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(0, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(1, active0); + return 2; + } + switch(curChar) + { + case 'b': + return jjMoveStringLiteralDfa3_1(active0, 0x80L); + case 'o': + return jjMoveStringLiteralDfa3_1(active0, 0x100L); + case 't': + return jjMoveStringLiteralDfa3_1(active0, 0x200L); + default : + break; + } + return jjStartNfa_1(1, active0); +} +private int jjMoveStringLiteralDfa3_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(1, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(2, active0); + return 3; + } + switch(curChar) + { + case 'e': + return jjMoveStringLiteralDfa4_1(active0, 0x200L); + case 'j': + return jjMoveStringLiteralDfa4_1(active0, 0x80L); + case 'm': + return jjMoveStringLiteralDfa4_1(active0, 0x100L); + default : + break; + } + return jjStartNfa_1(2, active0); +} +private int jjMoveStringLiteralDfa4_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(2, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(3, active0); + return 4; + } + switch(curChar) + { + case ':': + return jjMoveStringLiteralDfa5_1(active0, 0x300L); + case 'e': + return jjMoveStringLiteralDfa5_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(3, active0); +} +private int jjMoveStringLiteralDfa5_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(3, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(4, active0); + return 5; + } + switch(curChar) + { + case ' ': + if ((active0 & 0x100L) != 0x0L) + return jjStopAtPos(5, 8); + else if ((active0 & 0x200L) != 0x0L) + return jjStopAtPos(5, 9); + break; + case 'c': + return jjMoveStringLiteralDfa6_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(4, active0); +} +private int jjMoveStringLiteralDfa6_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(4, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(5, active0); + return 6; + } + switch(curChar) + { + case 't': + return jjMoveStringLiteralDfa7_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(5, active0); +} +private int jjMoveStringLiteralDfa7_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(5, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(6, active0); + return 7; + } + switch(curChar) + { + case ':': + return jjMoveStringLiteralDfa8_1(active0, 0x80L); + default : + break; + } + return jjStartNfa_1(6, active0); +} +private int jjMoveStringLiteralDfa8_1(long old0, long active0){ + if (((active0 &= old0)) == 0L) + return jjStartNfa_1(6, old0); + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { + jjStopStringLiteralDfa_1(7, active0); + return 8; + } + switch(curChar) + { + case ' ': + if ((active0 & 0x80L) != 0x0L) + return jjStopAtPos(8, 7); + break; + default : + break; + } + return jjStartNfa_1(7, active0); +} +private int jjMoveNfa_1(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 8; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + if (curChar == 13) + { jjAddStates(2, 3); } + else if (curChar == 10) + { jjCheckNAddTwoStates(1, 3); } + break; + case 1: + if ((0x2400L & l) != 0x0L && kind > 6) + kind = 6; + break; + case 2: + case 7: + if (curChar == 10 && kind > 6) + kind = 6; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 4: + if (curChar == 13) + { jjAddStates(2, 3); } + break; + case 5: + if (curChar == 10) + { jjCheckNAddTwoStates(1, 3); } + break; + case 6: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 7; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 8 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private int jjMoveStringLiteralDfa0_2() +{ + return jjMoveNfa_2(1, 0); +} +static final long[] jjbitVec0 = { + 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL +}; +private int jjMoveNfa_2(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 1: + if ((0xffffffffffffdbffL & l) != 0x0L) + { + if (kind > 11) + kind = 11; + { jjCheckNAdd(0); } + } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 12) + kind = 12; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffffffffdbffL & l) == 0x0L) + break; + kind = 11; + { jjCheckNAdd(0); } + break; + case 2: + if (curChar == 10 && kind > 12) + kind = 12; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + kind = 11; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 11) + kind = 11; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private int jjMoveStringLiteralDfa0_3() +{ + return jjMoveNfa_3(1, 0); +} +private int jjMoveNfa_3(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 1: + if ((0xffffffffffffdbffL & l) != 0x0L) + { + if (kind > 13) + kind = 13; + { jjCheckNAdd(0); } + } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 14) + kind = 14; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffffffffdbffL & l) == 0x0L) + break; + kind = 13; + { jjCheckNAdd(0); } + break; + case 2: + if (curChar == 10 && kind > 14) + kind = 14; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + kind = 13; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 13) + kind = 13; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private int jjMoveStringLiteralDfa0_4() +{ + return jjMoveNfa_4(1, 0); +} +private int jjMoveNfa_4(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 1: + if ((0xffffffffffffdbffL & l) != 0x0L) + { + if (kind > 15) + kind = 15; + { jjCheckNAdd(0); } + } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 16) + kind = 16; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffffffffdbffL & l) == 0x0L) + break; + kind = 15; + { jjCheckNAdd(0); } + break; + case 2: + if (curChar == 10 && kind > 16) + kind = 16; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + kind = 15; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 1: + case 0: + if ((jjbitVec0[i2] & l2) == 0L) + break; + if (kind > 15) + kind = 15; + { jjCheckNAdd(0); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} +private final int jjStopStringLiteralDfa_5(int pos, long active0){ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_5(int pos, long active0){ + return jjMoveNfa_5(jjStopStringLiteralDfa_5(pos, active0), pos + 1); +} +private int jjMoveStringLiteralDfa0_5(){ + switch(curChar) + { + case 31: + return jjStopAtPos(0, 18); + default : + return jjMoveNfa_5(4, 0); + } +} +private int jjMoveNfa_5(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 4; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 4: + if ((0xffffffff7fffdbffL & l) != 0x0L) + { jjCheckNAddStates(4, 6); } + else if ((0x2400L & l) != 0x0L) + { + if (kind > 17) + kind = 17; + } + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + case 0: + if ((0xffffffff7fffdbffL & l) != 0x0L) + { jjCheckNAddStates(4, 6); } + break; + case 1: + if ((0x2400L & l) != 0x0L && kind > 17) + kind = 17; + break; + case 2: + if (curChar == 10 && kind > 17) + kind = 17; + break; + case 3: + if (curChar == 13) + jjstateSet[jjnewStateCnt++] = 2; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 4: + case 0: + { jjCheckNAddStates(4, 6); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 4: + case 0: + if ((jjbitVec0[i2] & l2) != 0L) + { jjCheckNAddStates(4, 6); } + break; + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 4 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, null, null, null, null, null, null, +null, null, null, null, null, "\37", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = { + 2, 4, 5, 6, 0, 1, 3, +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + switch(curLexState) + { + case 0: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedPos == 0 && jjmatchedKind > 5) + { + jjmatchedKind = 5; + } + break; + case 1: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_1(); + if (jjmatchedPos == 0 && jjmatchedKind > 10) + { + jjmatchedKind = 10; + } + break; + case 2: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_2(); + break; + case 3: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_3(); + break; + case 4: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_4(); + break; + case 5: + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_5(); + break; + } + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + return matchedToken; + } + else + { + if (jjnewLexState[jjmatchedKind] != -1) + curLexState = jjnewLexState[jjmatchedKind]; + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + + /** Constructor. */ + public FaqTokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public FaqTokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 18; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 6 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", + "MAILHEADER", + "MAILSUBJECT", + "MAILFROM", + "MAILDATE", + "MAILBODY", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, 1, -1, 5, 2, 3, 4, -1, -1, 1, -1, 1, -1, 1, -1, 0, +}; +static final long[] jjtoToken = { + 0x6a801L, +}; +static final long[] jjtoSkip = { + 0x157f0L, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[18]; + private final int[] jjstateSet = new int[2 * 18]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/MailProcessing/Faq/ParseException.java b/src/test/resources/outputTest/MailProcessing/Faq/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Faq/SimpleCharStream.java b/src/test/resources/outputTest/MailProcessing/Faq/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Faq/Token.java b/src/test/resources/outputTest/MailProcessing/Faq/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/MailProcessing/Faq/TokenMgrException.java b/src/test/resources/outputTest/MailProcessing/Faq/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/MailProcessing/Faq/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/AbstractCharStream.java b/src/test/resources/outputTest/SimpleExamples/IdList/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/CharStream.java b/src/test/resources/outputTest/SimpleExamples/IdList/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/IdList.java b/src/test/resources/outputTest/SimpleExamples/IdList/IdList.java new file mode 100644 index 00000000..7f2612fe --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/IdList.java @@ -0,0 +1,252 @@ +/* IdList.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. IdList.java */ +/** ID lister. */ +public class IdList implements IdListConstants { + + /** Main entry point. */ + public static void main(String args[]) throws ParseException { + IdList parser = new IdList(System.in); + parser.Input(); + } + +/** Top level production. */ + final public void Input() throws ParseException { + label_1: + while (true) { + jj_consume_token(Id); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case Id:{ + break; + } + default: + jj_la1[0] = jj_gen; + break label_1; + } + } + jj_consume_token(0); +} + + /** Generated Token Manager. */ + public IdListTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[1]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x20,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public IdList(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new IdListTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public IdList(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new IdListTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new IdListTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public IdList(final IdListTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final IdListTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[6]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 1; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/IdListConstants.java b/src/test/resources/outputTest/SimpleExamples/IdList/IdListConstants.java new file mode 100644 index 00000000..639d8fd0 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/IdListConstants.java @@ -0,0 +1,27 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. IdListConstants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface IdListConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int Id = 5; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "", + }; + +} diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/IdListTokenManager.java b/src/test/resources/outputTest/SimpleExamples/IdList/IdListTokenManager.java new file mode 100644 index 00000000..f77e1d23 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/IdListTokenManager.java @@ -0,0 +1,340 @@ +/* IdListTokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. IdListTokenManager.java */ + +/** Token Manager. */ +public class IdListTokenManager implements IdListConstants { +private final int jjStopStringLiteralDfa_0(int pos, long active0){ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0){ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 2; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 1: + if ((0x3ff000000000000L & l) == 0x0L) + break; + kind = 5; + jjstateSet[jjnewStateCnt++] = 1; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 1: + if ((0x7fffffe07fffffeL & l) == 0x0L) + break; + if (kind > 5) + kind = 5; + { jjCheckNAdd(1); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 2 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = {0 +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { + input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0x0L) + curChar = input_stream.beginToken(); + } + catch (final java.io.IOException e1) { + continue EOFLoop; + } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + + /** Constructor. */ + public IdListTokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public IdListTokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 2; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 1 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0x21L, +}; +static final long[] jjtoSkip = { + 0x1eL, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[2]; + private final int[] jjstateSet = new int[2 * 2]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/ParseException.java b/src/test/resources/outputTest/SimpleExamples/IdList/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/SimpleCharStream.java b/src/test/resources/outputTest/SimpleExamples/IdList/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/Token.java b/src/test/resources/outputTest/SimpleExamples/IdList/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/IdList/TokenMgrException.java b/src/test/resources/outputTest/SimpleExamples/IdList/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/IdList/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/AbstractCharStream.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/CharStream.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_Xlator.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_Xlator.java new file mode 100644 index 00000000..b61405af --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_Xlator.java @@ -0,0 +1,360 @@ +/* NL_Xlator.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. NL_Xlator.java */ +/** New line translator. */ +public class NL_Xlator implements NL_XlatorConstants { + + /** Main entry point. */ + public static void main(String args[]) throws ParseException { + NL_Xlator parser = new NL_Xlator(System.in); + parser.ExpressionList(); + } + +/** Top level production. */ + final public void ExpressionList() throws ParseException {String s; +System.out.println("Please type in an expression followed by a \";\" or ^D to quit:"); + System.out.println(""); + label_1: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ID: + case NUM: + case 10:{ + break; + } + default: + jj_la1[0] = jj_gen; + break label_1; + } + s = Expression(); + jj_consume_token(7); +System.out.println(s); + System.out.println(""); + System.out.println("Please type in another expression followed by a \";\" or ^D to quit:"); + System.out.println(""); + } + jj_consume_token(0); +} + +/** An Expression. */ + final public String Expression() throws ParseException {java.util.Vector termimage = new java.util.Vector(); + String s; + s = Term(); +termimage.addElement(s); + label_2: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 8:{ + break; + } + default: + jj_la1[1] = jj_gen; + break label_2; + } + jj_consume_token(8); + s = Term(); +termimage.addElement(s); + } +if (termimage.size() == 1) { + {if ("" != null) return (String)termimage.elementAt(0);} + } else { + s = "the sum of " + (String)termimage.elementAt(0); + for (int i = 1; i < termimage.size()-1; i++) { + s += ", " + (String)termimage.elementAt(i); + } + if (termimage.size() > 2) { + s += ","; + } + s += " and " + (String)termimage.elementAt(termimage.size()-1); + {if ("" != null) return s;} + } + throw new IllegalStateException ("Missing return statement in function"); +} + +/** A Term. */ + final public String Term() throws ParseException {java.util.Vector factorimage = new java.util.Vector(); + String s; + s = Factor(); +factorimage.addElement(s); + label_3: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 9:{ + break; + } + default: + jj_la1[2] = jj_gen; + break label_3; + } + jj_consume_token(9); + s = Factor(); +factorimage.addElement(s); + } +if (factorimage.size() == 1) { + {if ("" != null) return (String)factorimage.elementAt(0);} + } else { + s = "the product of " + (String)factorimage.elementAt(0); + for (int i = 1; i < factorimage.size()-1; i++) { + s += ", " + (String)factorimage.elementAt(i); + } + if (factorimage.size() > 2) { + s += ","; + } + s += " and " + (String)factorimage.elementAt(factorimage.size()-1); + {if ("" != null) return s;} + } + throw new IllegalStateException ("Missing return statement in function"); +} + +/** A Factor. */ + final public String Factor() throws ParseException {Token t; + String s; + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case ID:{ + t = jj_consume_token(ID); +{if ("" != null) return t.image;} + break; + } + case NUM:{ + t = jj_consume_token(NUM); +{if ("" != null) return t.image;} + break; + } + case 10:{ + jj_consume_token(10); + s = Expression(); + jj_consume_token(11); +{if ("" != null) return s;} + break; + } + default: + jj_la1[3] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + throw new IllegalStateException ("Missing return statement in function"); +} + + /** Generated Token Manager. */ + public NL_XlatorTokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[4]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x460,0x100,0x200,0x460,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public NL_Xlator(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new NL_XlatorTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public NL_Xlator(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new NL_XlatorTokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new NL_XlatorTokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public NL_Xlator(final NL_XlatorTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final NL_XlatorTokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 4; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[12]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 4; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorConstants.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorConstants.java new file mode 100644 index 00000000..92d12e4c --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorConstants.java @@ -0,0 +1,35 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. NL_XlatorConstants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface NL_XlatorConstants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int ID = 5; + /** RegularExpression Id. */ + int NUM = 6; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "", + "", + "\";\"", + "\"+\"", + "\"*\"", + "\"(\"", + "\")\"", + }; + +} diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorTokenManager.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorTokenManager.java new file mode 100644 index 00000000..1ab33228 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/NL_XlatorTokenManager.java @@ -0,0 +1,359 @@ +/* NL_XlatorTokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. NL_XlatorTokenManager.java */ + +/** Token Manager. */ +public class NL_XlatorTokenManager implements NL_XlatorConstants { +private final int jjStopStringLiteralDfa_0(int pos, long active0){ + switch (pos) + { + default : + return -1; + } +} +private final int jjStartNfa_0(int pos, long active0){ + return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); +} +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + case '(': + return jjStopAtPos(0, 10); + case ')': + return jjStopAtPos(0, 11); + case '*': + return jjStopAtPos(0, 9); + case '+': + return jjStopAtPos(0, 8); + case ';': + return jjStopAtPos(0, 7); + default : + return jjMoveNfa_0(0, 0); + } +} +private int jjMoveNfa_0(int startState, int curPos) +{ + int startsAt = 0; + jjnewStateCnt = 3; + int i = 1; + jjstateSet[0] = startState; + int kind = 0x7fffffff; + for (;;) + { + if (++jjround == 0x7fffffff) + ReInitRounds(); + if (curChar < 64) + { + long l = 1L << curChar; + do + { + switch(jjstateSet[--i]) + { + case 0: + case 2: + if ((0x3ff000000000000L & l) == 0x0L) + break; + if (kind > 6) + kind = 6; + { jjCheckNAdd(2); } + break; + case 1: + if ((0x3ff000000000000L & l) == 0x0L) + break; + if (kind > 5) + kind = 5; + jjstateSet[jjnewStateCnt++] = 1; + break; + default : break; + } + } while(i != startsAt); + } + else if (curChar < 128) + { + long l = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + case 0: + case 1: + if ((0x7fffffe87fffffeL & l) == 0x0L) + break; + if (kind > 5) + kind = 5; + { jjCheckNAdd(1); } + break; + default : break; + } + } while(i != startsAt); + } + else + { + int i2 = (curChar & 0xff) >> 6; + long l2 = 1L << (curChar & 077); + do + { + switch(jjstateSet[--i]) + { + default : break; + } + } while(i != startsAt); + } + if (kind != 0x7fffffff) + { + jjmatchedKind = kind; + jjmatchedPos = curPos; + kind = 0x7fffffff; + } + ++curPos; + i = jjnewStateCnt; + jjnewStateCnt = startsAt; + startsAt = 3 - jjnewStateCnt; + if (i == startsAt) + return curPos; + try { curChar = input_stream.readChar(); } + catch(final java.io.IOException e) { return curPos; } + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, null, null, "\73", "\53", "\52", "\50", "\51", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = {0 +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { + input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0x0L) + curChar = input_stream.beginToken(); + } + catch (final java.io.IOException e1) { + continue EOFLoop; + } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + + /** Constructor. */ + public NL_XlatorTokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public NL_XlatorTokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 3; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 1 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0xfe1L, +}; +static final long[] jjtoSkip = { + 0x1eL, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[3]; + private final int[] jjstateSet = new int[2 * 3]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/ParseException.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/SimpleCharStream.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/Token.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/NL_Xlator/TokenMgrException.java b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/NL_Xlator/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/AbstractCharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple1/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/CharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple1/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/ParseException.java b/src/test/resources/outputTest/SimpleExamples/Simple1/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1.java b/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1.java new file mode 100644 index 00000000..9feb0b56 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1.java @@ -0,0 +1,282 @@ +/* Simple1.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple1.java */ +/** Simple brace matcher. */ +public class Simple1 implements Simple1Constants { + + /** Main entry point. */ + public static void main(String args[]) throws ParseException { + Simple1 parser = new Simple1(System.in); + parser.Input(); + } + +/** Root production. */ + final public void Input() throws ParseException { + MatchedBraces(); + label_1: + while (true) { + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 1: + case 2:{ + break; + } + default: + jj_la1[0] = jj_gen; + break label_1; + } + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 1:{ + jj_consume_token(1); + break; + } + case 2:{ + jj_consume_token(2); + break; + } + default: + jj_la1[1] = jj_gen; + jj_consume_token(-1); + throw new ParseException(); + } + } + jj_consume_token(0); +} + +/** Brace matching production. */ + final public void MatchedBraces() throws ParseException { + jj_consume_token(3); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 3:{ + MatchedBraces(); + break; + } + default: + jj_la1[2] = jj_gen; + ; + } + jj_consume_token(4); +} + + /** Generated Token Manager. */ + public Simple1TokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[3]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x6,0x6,0x8,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public Simple1(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new Simple1TokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public Simple1(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new Simple1TokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new Simple1TokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public Simple1(final Simple1TokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final Simple1TokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 3; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[5]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 3; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1Constants.java b/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1Constants.java new file mode 100644 index 00000000..61a62d2d --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1Constants.java @@ -0,0 +1,24 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple1Constants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface Simple1Constants { + + /** End of File. */ + int EOF = 0; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\"\\n\"", + "\"\\r\"", + "\"{\"", + "\"}\"", + }; + +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1TokenManager.java b/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1TokenManager.java new file mode 100644 index 00000000..0cbfe20f --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/Simple1TokenManager.java @@ -0,0 +1,248 @@ +/* Simple1TokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple1TokenManager.java */ + +/** Token Manager. */ +public class Simple1TokenManager implements Simple1Constants { +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + case 10: + return jjStopAtPos(0, 1); + case 13: + return jjStopAtPos(0, 2); + case '{': + return jjStopAtPos(0, 3); + case '}': + return jjStopAtPos(0, 4); + default : + return 1; + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", "\12", "\15", "\173", "\175", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = {0 +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + matchedToken = jjFillToken(); + return matchedToken; + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + + /** Constructor. */ + public Simple1TokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public Simple1TokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 0; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 1 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0x1fL, +}; +static final long[] jjtoSkip = { + 0x0L, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[0]; + private final int[] jjstateSet = new int[2 * 0]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/SimpleCharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple1/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/Token.java b/src/test/resources/outputTest/SimpleExamples/Simple1/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple1/TokenMgrException.java b/src/test/resources/outputTest/SimpleExamples/Simple1/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple1/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/AbstractCharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple2/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/CharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple2/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/ParseException.java b/src/test/resources/outputTest/SimpleExamples/Simple2/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2.java b/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2.java new file mode 100644 index 00000000..e48398c1 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2.java @@ -0,0 +1,256 @@ +/* Simple2.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple2.java */ +/** Simple brace matcher. */ +public class Simple2 implements Simple2Constants { + + /** Main entry point. */ + public static void main(String args[]) throws ParseException { + Simple2 parser = new Simple2(System.in); + parser.Input(); + } + +/** Root production. */ + final public void Input() throws ParseException { + MatchedBraces(); + jj_consume_token(0); +} + +/** Brace matching production. */ + final public void MatchedBraces() throws ParseException { + jj_consume_token(5); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case 5:{ + MatchedBraces(); + break; + } + default: + jj_la1[0] = jj_gen; + ; + } + jj_consume_token(6); +} + + /** Generated Token Manager. */ + public Simple2TokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[1]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x20,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public Simple2(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new Simple2TokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public Simple2(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new Simple2TokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new Simple2TokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public Simple2(final Simple2TokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final Simple2TokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[7]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 1; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2Constants.java b/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2Constants.java new file mode 100644 index 00000000..ab28adab --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2Constants.java @@ -0,0 +1,26 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple2Constants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface Simple2Constants { + + /** End of File. */ + int EOF = 0; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"{\"", + "\"}\"", + }; + +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2TokenManager.java b/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2TokenManager.java new file mode 100644 index 00000000..b3b8dac5 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/Simple2TokenManager.java @@ -0,0 +1,259 @@ +/* Simple2TokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple2TokenManager.java */ + +/** Token Manager. */ +public class Simple2TokenManager implements Simple2Constants { +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + case '{': + return jjStopAtPos(0, 5); + case '}': + return jjStopAtPos(0, 6); + default : + return 1; + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, "\173", "\175", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = {0 +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { + input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0x0L) + curChar = input_stream.beginToken(); + } + catch (final java.io.IOException e1) { + continue EOFLoop; + } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + + /** Constructor. */ + public Simple2TokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public Simple2TokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 0; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 1 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0x61L, +}; +static final long[] jjtoSkip = { + 0x1eL, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[0]; + private final int[] jjstateSet = new int[2 * 0]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/SimpleCharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple2/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/Token.java b/src/test/resources/outputTest/SimpleExamples/Simple2/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple2/TokenMgrException.java b/src/test/resources/outputTest/SimpleExamples/Simple2/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple2/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/AbstractCharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple3/AbstractCharStream.java new file mode 100644 index 00000000..c1c70cd8 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/AbstractCharStream.java @@ -0,0 +1,543 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. AbstractCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ + +public +abstract class AbstractCharStream +implements CharStream +{ + /** Default buffer size if nothing is specified */ + public static final int DEFAULT_BUF_SIZE = 4096; + + static final int hexval (final char c) throws java.io.IOException + { + switch (c) + { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + throw new java.io.IOException ("Invalid hex char '" + c + "' (=" + (int) c + ") provided!"); + } + } + + /** Tab size for formatting. Usually in the range 1 to 8. */ + private int m_nTabSize = 1; + + /** Internal circular buffer */ + protected char[] buffer; + + /** Overall buffer size - same as buffer.length */ + protected int bufsize; + + /** Current read position in buffer. */ + protected int bufpos; + + /** The number of unoccupied buffer array positions */ + protected int available; + + /** The first array index (of `buffer`) that the current token starts */ + protected int tokenBegin; + + /** Characters in the backup/pushBack buffer */ + protected int inBuf; + protected int maxNextCharInd; + + private int[] m_aBufLine; + private int[] m_aBufColumn; + + // Current line number + private int m_nLineNo; + // Current column number + private int m_nColumnNo; + + // Was the previous character a "\r" char? + private boolean m_bPrevCharIsCR; + // Was the previous character a "\n" char? + private boolean m_bPrevCharIsLF; + + // Is line/column tracking enabled? + private boolean m_bTrackLineColumn = true; + + + /** Constructor. */ + public AbstractCharStream(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + reInit (nStartLine, nStartColumn, nBufferSize); + } + + /** Reinitialise. */ + public final void reInit(final int nStartLine, + final int nStartColumn, + final int nBufferSize) + { + m_nLineNo = nStartLine; + m_nColumnNo = nStartColumn - 1; + m_bPrevCharIsCR = false; + m_bPrevCharIsLF = false; + if (buffer == null || nBufferSize != buffer.length) + { + bufsize = nBufferSize; + available = nBufferSize; + buffer = new char[nBufferSize]; + m_aBufLine = new int[nBufferSize]; + m_aBufColumn = new int[nBufferSize]; + } + maxNextCharInd = 0; + inBuf = 0; + tokenBegin = 0; + bufpos = -1; + } + + /** + * Read from the underlying stream. + * @param aBuf the buffer to be filled + * @param nOfs The offset into the buffer. 0-based + * @param nLen Number of chars to read. + * @return Number of effective chars read, or -1 on error. + */ + protected abstract int streamRead (char[] aBuf, int nOfs, int nLen) throws java.io.IOException; + + /** + * Close the underlying stream. + * @throws java.io.IOException If closing fails. + */ + protected abstract void streamClose () throws java.io.IOException; + + // Override this method if you need more aggressive buffer size expansion + protected int getBufSizeAfterExpansion () + { + // Double the size by default + return bufsize * 2; + } + + protected void expandBuff (final boolean bWrapAround) + { + // Get the new buffer size + final int nNewBufSize = getBufSizeAfterExpansion (); + + final char[] newbuffer = new char[nNewBufSize]; + final int[] newbufline = new int[nNewBufSize]; + final int[] newbufcolumn = new int[nNewBufSize]; + + // Number of chars to be preserved + final int nPreservedChars = bufsize - tokenBegin; + + if (bWrapAround) + { + // Move from offset "tokenBegin" to offset 0 + // arraycopy(src, srcPos, dest, destPos, length) + + // copy the "tail end" to the "start" (index 0) of the new buffer array + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + + // copy the remaining "wrap around" content of the buffer from the start of the original buffer (starting at srcPos index 0) + System.arraycopy(buffer, 0, newbuffer, nPreservedChars, bufpos); + + // swap the new buffer in place of the old buffer + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + System.arraycopy(m_aBufLine, 0, newbufline, nPreservedChars, bufpos); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + System.arraycopy(m_aBufColumn, 0, newbufcolumn, nPreservedChars, bufpos); + m_aBufColumn = newbufcolumn; + + bufpos += nPreservedChars; + } + else + { + // Move from offset "tokenBegin" to offset 0 + + System.arraycopy(buffer, tokenBegin, newbuffer, 0, nPreservedChars); + buffer = newbuffer; + + System.arraycopy(m_aBufLine, tokenBegin, newbufline, 0, nPreservedChars); + m_aBufLine = newbufline; + + System.arraycopy(m_aBufColumn, tokenBegin, newbufcolumn, 0, nPreservedChars); + m_aBufColumn = newbufcolumn; + + bufpos -= tokenBegin; + } + + // Increase buffer size + bufsize = nNewBufSize; + available = nNewBufSize; + tokenBegin = 0; + } + + protected final void internalAdjustBuffSize() + { + final int nHalfBufferSize = bufsize / 2; + if (available == bufsize) + { + if (tokenBegin < 0) + { + // If this method is called from "beginToken()" + // Just refill the buffer from the start + bufpos = 0; + maxNextCharInd = 0; + } + else + if (tokenBegin > nHalfBufferSize) + { + // The token started in the second half - fill the front part + bufpos = 0; + maxNextCharInd = 0; + + // Available bytes are > 50% + available = tokenBegin; + } + else + { + // Token starts in the first half + // just append to existing buffer + expandBuff (false); + } + } + else + { + // A token was read across array boundaries + if (available > tokenBegin) + { + available = bufsize; + } + else + if ((tokenBegin - available) < nHalfBufferSize) + { + expandBuff (true); + } + else + { + available = tokenBegin; + } + } + } + + protected void fillBuff() throws java.io.IOException + { + if (maxNextCharInd == available) + internalAdjustBuffSize(); + + try + { + // Read from underlying stream + final int nCharsRead = streamRead (buffer, maxNextCharInd, available - maxNextCharInd); + if (nCharsRead == -1) + { + // We reached the end of the file + streamClose (); + + // Caught down below and re-thrown + throw new java.io.IOException("PGCC end of stream"); + } + maxNextCharInd += nCharsRead; + } + catch (final java.io.IOException ex) + { + --bufpos; + // ?What is the reason of this? Backup of 0 does nothing + backup (0); + if (tokenBegin == -1) + { + // Error occurred in "beginToken()" + tokenBegin = bufpos; + } + throw ex; + } + } + + protected final void internalSetBufLineColumn (final int nLine, final int nColumn) + { + m_aBufLine[bufpos] = nLine; + m_aBufColumn[bufpos] = nColumn; + } + + protected final void internalUpdateLineColumn(final char c) + { + m_nColumnNo++; + + if (m_bPrevCharIsLF) + { + // It's a "\r\n" or "\n" + // Start of a new line + m_bPrevCharIsLF = false; + m_nColumnNo = 1; + m_nLineNo++; + } + else + if (m_bPrevCharIsCR) + { + m_bPrevCharIsCR = false; + if (c == '\n') + { + // It's a "\r\n" + m_bPrevCharIsLF = true; + } + else + { + // It's only a "\r" + m_nColumnNo = 1; + m_nLineNo++; + } + } + + switch (c) + { + case '\r': + m_bPrevCharIsCR = true; + break; + case '\n': + m_bPrevCharIsLF = true; + break; + case '\t': + m_nColumnNo--; + m_nColumnNo += (m_nTabSize - (m_nColumnNo % m_nTabSize)); + break; + } + + internalSetBufLineColumn (m_nLineNo, m_nColumnNo); + } + + public char readChar() throws java.io.IOException + { + if (inBuf > 0) + { + // Something is left from last backup + --inBuf; + + ++bufpos; + if (bufpos == bufsize) + { + // Buffer overflow + bufpos = 0; + } + + return buffer[bufpos]; + } + + ++bufpos; + if (bufpos >= maxNextCharInd) + fillBuff(); + + final char c = buffer[bufpos]; + + if (m_bTrackLineColumn) + internalUpdateLineColumn(c); + return c; + } + + public char beginToken() throws java.io.IOException + { + tokenBegin = -1; + final char c = readChar(); + tokenBegin = bufpos; + return c; + } + + public int getBeginColumn () + { + return m_aBufColumn[tokenBegin]; + } + + public int getBeginLine () + { + return m_aBufLine[tokenBegin]; + } + + public int getEndColumn () + { + return m_aBufColumn[bufpos]; + } + + public int getEndLine () + { + return m_aBufLine[bufpos]; + } + + public void backup (final int nAmount) + { + if (nAmount > bufsize) + throw new IllegalStateException ("Cannot back " + nAmount + " chars which is larger than the internal buffer size (" + bufsize + ")"); + + inBuf += nAmount; + bufpos -= nAmount; + if (bufpos < 0) + { + // Buffer underflow (modulo) + bufpos += bufsize; + } + } + + public String getImage() + { + if (bufpos >= tokenBegin) + { + // from tokenBegin to bufpos + return new String (buffer, tokenBegin, bufpos - tokenBegin + 1); + } + + // from tokenBegin to bufsize, and from 0 to bufpos + return new String (buffer, tokenBegin, bufsize - tokenBegin) + + new String (buffer, 0, bufpos + 1); + } + + public char[] getSuffix (final int len) + { + char[] ret = new char[len]; + if ((bufpos + 1) >= len) + { + // one piece + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + } + else + { + // Wrap around + final int nPart1 = len - bufpos - 1; + System.arraycopy(buffer, bufsize - nPart1, ret, 0, nPart1); + System.arraycopy(buffer, 0, ret, nPart1, bufpos + 1); + } + return ret; + } + + public void done() + { + buffer = null; + m_aBufLine = null; + m_aBufColumn = null; + } + + public final int getTabSize() + { + return m_nTabSize; + } + + public final void setTabSize (final int nTabSize) + { + m_nTabSize = nTabSize; + } + + /** + * Method to adjust line and column numbers for the start of a token. + * This is used internally to + */ + public final void adjustBeginLineColumn(final int nNewLine, final int newCol) + { + int start = tokenBegin; + int newLine = nNewLine; + + int len; + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0; + int j = 0; + int k = 0; + int nextColDiff = 0; + int columnDiff = 0; + + // TODO disassemble meaning and split up + while (i < len && m_aBufLine[j = start % bufsize] == m_aBufLine[k = ++start % bufsize]) + { + m_aBufLine[j] = newLine; + nextColDiff = columnDiff + m_aBufColumn[k] - m_aBufColumn[j]; + m_aBufColumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + m_aBufLine[j] = newLine++; + m_aBufColumn[j] = newCol + columnDiff; + + while (i++ < len) + { + // TODO disassemble meaning and split up + if (m_aBufLine[j = start % bufsize] != m_aBufLine[++start % bufsize]) + m_aBufLine[j] = newLine++; + else + m_aBufLine[j] = newLine; + } + } + + m_nLineNo = m_aBufLine[j]; + m_nColumnNo = m_aBufColumn[j]; + } + + /** + * @return the current line number. 0-based. + */ + protected final int getLine () + { + return m_nLineNo; + } + + /** + * @return the current column number. 0-based. + */ + protected final int getColumn () + { + return m_nColumnNo; + } + + public final boolean isTrackLineColumn () + { + return m_bTrackLineColumn; + } + + public final void setTrackLineColumn (final boolean bTrackLineColumn) + { + m_bTrackLineColumn = bTrackLineColumn; + } +} +/* ParserGeneratorCC - OriginalChecksum=b9bb01f8d4099c0a83f1034f522338df (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/CharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple3/CharStream.java new file mode 100644 index 00000000..d84ee1fd --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/CharStream.java @@ -0,0 +1,123 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * This interface describes a character stream that maintains line and + * column number positions of the characters. It also has the capability + * to backup the stream to some extent. An implementation of this + * interface is used in the TokenManager implementation generated by + * JavaCCParser. + * + * All the methods except backup can be implemented in any fashion. backup + * needs to be implemented correctly for the correct operation of the lexer. + * Rest of the methods are all used to get information like line number, + * column number and the String that constitutes a token and are not used + * by the lexer. Hence their implementation won't affect the generated lexer's + * operation. + */ + +public +interface CharStream { + /** + * Get the next character from the selected input. The method + * of selecting the input is the responsibility of the class + * implementing this interface. + * @return the next character from the selected input + * @throws java.io.IOException on IO error + */ + char readChar() throws java.io.IOException; + + /** + * @return the column number of the first character for current token (being + * matched after the last call to beginToken). + */ + int getBeginColumn(); + + /** + * @return the line number of the first character for current token (being + * matched after the last call to BeginToken). + */ + int getBeginLine(); + + /** + * @return the column number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndColumn(); + + /** + * @return the line number of the last character for current token (being + * matched after the last call to BeginToken). + */ + int getEndLine(); + + /** + * Backs up the input stream by amount steps. Lexer calls this method if it + * had already read some characters, but could not use them to match a + * (longer) token. So, they will be used again as the prefix of the next + * token and it is the implemetation's responsibility to do this right. + * @param amount Number of chars to back up. + */ + void backup(int amount); + + /** + * @return the next character that marks the beginning of the next token. + * All characters must remain in the buffer between two successive calls + * to this method to implement backup correctly. + */ + char beginToken() throws java.io.IOException; + + /** + * @return a string made up of characters from the marked token beginning + * to the current buffer position. Implementations have the choice of returning + * anything that they want to. For example, for efficiency, one might decide + * to just return null, which is a valid implementation. + */ + String getImage(); + + /** + * @return an array of characters that make up the suffix of length 'len' for + * the currently matched token. This is used to build up the matched string + * for use in actions in the case of MORE. A simple and inefficient + * implementation of this is as follows: + *
+   *   {
+   *      String t = getImage();
+   *      return t.substring(t.length() - len, t.length()).toCharArray();
+   *   }
+   * 
+ */ + char[] getSuffix(int len); + + /** + * The lexer calls this function to indicate that it is done with the stream + * and hence implementations can free any resources held by this class. + * Again, the body of this function can be just empty and it will not + * affect the lexer's operation. + */ + void done(); + + // Getters and setters + + /** + * @return Current tab size. + */ + int getTabSize(); + + /** + * Set the tab size to use. + * @param i spaces per tab + */ + void setTabSize(int i); + + /** + * @return true if line number and column numbers should be tracked. + */ + boolean isTrackLineColumn(); + + /** + * Enable or disable line number and column number tracking. + * @param trackLineColumn true to track it, false to not do it. + */ + void setTrackLineColumn(boolean trackLineColumn); +} +/* ParserGeneratorCC - OriginalChecksum=edf9fb0622b9bb50914bbeed0e890440 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/ParseException.java b/src/test/resources/outputTest/SimpleExamples/Simple3/ParseException.java new file mode 100644 index 00000000..bd5208a1 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/ParseException.java @@ -0,0 +1,187 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. ParseException.java Version 2.0 */ +/* ParserGeneratorCCOptions:KEEP_LINE_COLUMN=true */ +/** + * This exception is thrown when parse errors are encountered. + * You can explicitly create objects of this exception type by + * calling the method generateParseException in the generated + * parser. + * + * You can modify this class to customize your error reporting + * mechanisms so long as you retain the public fields. + */ +public class ParseException extends Exception { + /** + * The end of line string for this machine. + */ + protected static final String EOL = System.getProperty("line.separator", "\n"); + + /** + * This constructor is used by the method "generateParseException" + * in the generated parser. Calling this constructor generates + * a new object of this type with the fields "currentToken", + * "expectedTokenSequences", and "tokenImage" set. + */ + public ParseException(final Token currentTokenVal, + final int[][] expectedTokenSequencesVal, + final String[] tokenImageVal) + { + super(_initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); + currentToken = currentTokenVal; + expectedTokenSequences = expectedTokenSequencesVal; + tokenImage = tokenImageVal; + } + + /** + * The following constructors are for use by you for whatever + * purpose you can think of. Constructing the exception in this + * manner makes the exception behave in the normal way - i.e., as + * documented in the class "Throwable". The fields "errorToken", + * "expectedTokenSequences", and "tokenImage" do not contain + * relevant information. The JavaCC generated code does not use + * these constructors. + */ + + public ParseException() { + super(); + } + + /** Constructor with message. */ + public ParseException(String message) { + super(message); + } + + + /** + * This is the last token that has been consumed successfully. If + * this object has been created due to a parse error, the token + * followng this token will (therefore) be the first error token. + */ + public Token currentToken; + + /** + * Each entry in this array is an array of integers. Each array + * of integers represents a sequence of tokens (by their ordinal + * values) that is expected at this point of the parse. + */ + public int[][] expectedTokenSequences; + + /** + * This is a reference to the "tokenImage" array of the generated + * parser within which the parse error occurred. This array is + * defined in the generated ...Constants interface. + */ + public String[] tokenImage; + + /** + * It uses "currentToken" and "expectedTokenSequences" to generate a parse + * error message and returns it. If this object has been created + * due to a parse error, and you do not catch it (it gets thrown + * from the parser) the correct error message + * gets displayed. + */ + private static String _initialise(final Token currentToken, + final int[][] expectedTokenSequences, + final String[] tokenImage) + { + StringBuilder expected = new StringBuilder(); + int maxSize = 0; + for (int i = 0; i < expectedTokenSequences.length; i++) { + if (maxSize < expectedTokenSequences[i].length) + maxSize = expectedTokenSequences[i].length; + for (int j = 0; j < expectedTokenSequences[i].length; j++) + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); + + if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) + expected.append("..."); + expected.append(EOL).append(" "); + } + + StringBuilder sb = new StringBuilder(); + sb.append ("Encountered \""); + + Token tok = currentToken.next; + for (int i = 0; i < maxSize; i++) { + String tokenText = tok.image; + String escapedTokenText = add_escapes(tokenText); + if (i != 0) + sb.append (' '); + if (tok.kind == 0) { + sb.append(tokenImage[0]); + break; + } + sb.append(" " + tokenImage[tok.kind]); + sb.append(" \""); + sb.append(escapedTokenText); + sb.append("\""); + tok = tok.next; + } + sb.append ("\" at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); + sb.append(".").append(EOL); + + if (expectedTokenSequences.length == 0) { + // Nothing to add here + } else { + sb.append (EOL) + .append ("Was expecting") + .append (expectedTokenSequences.length == 1 ? ":" : " one of:") + .append (EOL) + .append (EOL) + .append (expected); + } + + return sb.toString (); + } + + + /** + * Used to convert raw characters to their escaped version + * when these raw version cannot be used as part of an ASCII + * string literal. + */ + static String add_escapes(String str) { + final StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } +} +/* ParserGeneratorCC - OriginalChecksum=412306ec454d485099b4efadcb89707d (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3.java b/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3.java new file mode 100644 index 00000000..08fdcace --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3.java @@ -0,0 +1,259 @@ +/* Simple3.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple3.java */ +/** Simple brace matcher. */ +public class Simple3 implements Simple3Constants { + + /** Main entry point. */ + public static void main(String args[]) throws ParseException { + Simple3 parser = new Simple3(System.in); + parser.Input(); + } + +/** Root production. */ + final public void Input() throws ParseException {int count; + count = MatchedBraces(); + jj_consume_token(0); +System.out.println("The levels of nesting is " + count); +} + +/** Brace counting production. */ + final public int MatchedBraces() throws ParseException {int nested_count=0; + jj_consume_token(LBRACE); + switch (jj_ntk == -1 ? jj_ntk_f() : jj_ntk) { + case LBRACE:{ + nested_count = MatchedBraces(); + break; + } + default: + jj_la1[0] = jj_gen; + ; + } + jj_consume_token(RBRACE); +{if ("" != null) return ++nested_count;} + throw new IllegalStateException ("Missing return statement in function"); +} + + /** Generated Token Manager. */ + public Simple3TokenManager token_source; + SimpleCharStream jj_input_stream; + /** Current token. */ + public Token token; + /** Next token. */ + public Token jj_nt; + private int jj_ntk; + private int jj_gen; + final private int[] jj_la1 = new int[1]; + static private int[] jj_la1_0; + static { + jj_la1_init_0(); + } + private static void jj_la1_init_0() { + jj_la1_0 = new int[] {0x20,}; + } + + /** + * Constructor with InputStream and supplied encoding + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public Simple3(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source = new Simple3TokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream input stream + * @param encoding charset to be used. May not be null. + */ + public void ReInit(final java.io.InputStream stream, final String encoding) { + try { + jj_input_stream.reInit(stream, encoding, 1, 1); + } catch(final java.io.UnsupportedEncodingException e) { + throw new IllegalStateException(e); + } + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Constructor with InputStream. + * @param stream char stream + */ + public Simple3(final java.io.Reader stream) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + token_source = new Simple3TokenManager(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param stream char stream + */ + public void ReInit(final java.io.Reader stream) { + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } else { + jj_input_stream.reInit(stream, 1, 1); + } + if (token_source == null) { + token_source = new Simple3TokenManager(jj_input_stream); + } + + token_source.ReInit(jj_input_stream); + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) + jj_la1[i] = -1; + } + + /** + * Constructor with generated Token Manager. + * @param tm Token manager to use + */ + public Simple3(final Simple3TokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + /** + * Reinitialise + * @param tm Token manager to use + */ + public void ReInit(final Simple3TokenManager tm) { + token_source = tm; + token = new Token(); + jj_ntk = -1; + jj_gen = 0; + for (int i = 0; i < 1; i++) jj_la1[i] = -1; + } + + private Token jj_consume_token(final int kind) throws ParseException { + final Token oldToken = token; + if (token.next != null) + token = token.next; + else { + token.next = token_source.getNextToken(); + token = token.next; + } + jj_ntk = -1; + if (token.kind == kind) { + jj_gen++; + return token; + } + token = oldToken; + jj_kind = kind; + throw generateParseException(); + } + + + /** + * @return the next Token. + */ + public final Token getNextToken() { + if (token.next != null) + token = token.next; + else + token = token.next = token_source.getNextToken(); + jj_ntk = -1; + jj_gen++; + return token; + } + + /** + * @param index index to be retrieved + * @return the specific Token. + */ + public final Token getToken(final int index) { + Token t = token; + for (int i = 0; i < index; i++) { + if (t.next == null) + t.next = token_source.getNextToken(); + t = t.next; + } + return t; + } + + private int jj_ntk_f() { + final Token nt = jj_nt = token.next; + final int ret; + if (nt == null) { + token.next = token_source.getNextToken(); + ret = jj_ntk = token.next.kind; + } + else + ret = jj_ntk = nt.kind; + return ret; + } + + private java.util.List jj_expentries = new java.util.ArrayList(); + private int[] jj_expentry; + private int jj_kind = -1; + + /** + * Generate ParseException. + * @return new Exception object. Never null + */ + public ParseException generateParseException() { + jj_expentries.clear(); + boolean[] la1tokens = new boolean[7]; + if (jj_kind >= 0) { + la1tokens[jj_kind] = true; + jj_kind = -1; + } + for (int i = 0; i < 1; i++) { + if (jj_la1[i] == jj_gen) { + for (int j = 0; j < 32; j++) { + if ((jj_la1_0[i] & (1<false. + */ + public final boolean trace_enabled() { + return false; + } + + /** Enable tracing. */ + public final void enable_tracing() {} + + /** Disable tracing. */ + public final void disable_tracing() {} + +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3Constants.java b/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3Constants.java new file mode 100644 index 00000000..f567bd81 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3Constants.java @@ -0,0 +1,30 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple3Constants.java */ + +/** + * Token literal values and constants. + * Generated by com.helger.pgcc.output.java.OtherFilesGenJava#start() + */ +public interface Simple3Constants { + + /** End of File. */ + int EOF = 0; + /** RegularExpression Id. */ + int LBRACE = 5; + /** RegularExpression Id. */ + int RBRACE = 6; + + /** Lexical state. */ + int DEFAULT = 0; + + /** Literal token values. */ + String[] tokenImage = { + "", + "\" \"", + "\"\\t\"", + "\"\\n\"", + "\"\\r\"", + "\"{\"", + "\"}\"", + }; + +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3TokenManager.java b/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3TokenManager.java new file mode 100644 index 00000000..59b94dd9 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/Simple3TokenManager.java @@ -0,0 +1,259 @@ +/* Simple3TokenManager.java */ +/* Generated by: ParserGeneratorCC: Do not edit this line. Simple3TokenManager.java */ + +/** Token Manager. */ +public class Simple3TokenManager implements Simple3Constants { +private int jjStopAtPos(int pos, int kind) +{ + jjmatchedKind = kind; + jjmatchedPos = pos; + return pos + 1; +} +private int jjMoveStringLiteralDfa0_0(){ + switch(curChar) + { + case '{': + return jjStopAtPos(0, 5); + case '}': + return jjStopAtPos(0, 6); + default : + return 1; + } +} + +/** Token literal values. */ +public static final String[] jjstrLiteralImages = { +"", null, null, null, null, "\173", "\175", }; +protected Token jjFillToken() +{ + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; + String im = jjstrLiteralImages[jjmatchedKind]; + curTokenImage = im == null ? input_stream.getImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind); + t.kind = jjmatchedKind; + t.image = curTokenImage; + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + + return t; +} +static final int[] jjnextStates = {0 +}; + +int curLexState = 0; +int defaultLexState = 0; +int jjnewStateCnt; +int jjround; +int jjmatchedPos; +int jjmatchedKind; + +/** Get the next Token. */ +public Token getNextToken() +{ + Token matchedToken; + int curPos = 0; + + EOFLoop: + for (;;) + { + try + { + curChar = input_stream.beginToken(); + } + catch(final Exception e) + { + jjmatchedKind = 0; + jjmatchedPos = -1; + matchedToken = jjFillToken(); + return matchedToken; + } + + try { + input_stream.backup(0); + while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0x0L) + curChar = input_stream.beginToken(); + } + catch (final java.io.IOException e1) { + continue EOFLoop; + } + jjmatchedKind = 0x7fffffff; + jjmatchedPos = 0; + curPos = jjMoveStringLiteralDfa0_0(); + if (jjmatchedKind != 0x7fffffff) + { + if (jjmatchedPos + 1 < curPos) + input_stream.backup(curPos - jjmatchedPos - 1); + if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) + { + matchedToken = jjFillToken(); + return matchedToken; + } + else + { + continue EOFLoop; + } + } + int error_line = input_stream.getEndLine(); + int error_column = input_stream.getEndColumn(); + String error_after = null; + boolean EOFSeen = false; + try { + input_stream.readChar(); + input_stream.backup(1); + } + catch (final java.io.IOException e1) { + EOFSeen = true; + error_after = curPos <= 1 ? "" : input_stream.getImage(); + if (curChar == '\n' || curChar == '\r') { + error_line++; + error_column = 0; + } + else + error_column++; + } + if (!EOFSeen) { + input_stream.backup(1); + error_after = curPos <= 1 ? "" : input_stream.getImage(); + } + throw new TokenMgrException(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrException.LEXICAL_ERROR); + } +} + +void SkipLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +void MoreLexicalActions() +{ + jjimageLen += (lengthOfMatch = jjmatchedPos + 1); + switch(jjmatchedKind) + { + default : + break; + } +} +void TokenLexicalActions(Token matchedToken) +{ + switch(jjmatchedKind) + { + default : + break; + } +} +private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + + /** Constructor. */ + public Simple3TokenManager(SimpleCharStream stream){ + input_stream = stream; + } + + /** Constructor. */ + public Simple3TokenManager (SimpleCharStream stream, int lexState){ + ReInit(stream); + SwitchTo(lexState); + } + + /** Reinitialise parser. */ + + public void ReInit(SimpleCharStream stream) + { + + + jjmatchedPos = + jjnewStateCnt = + 0; + curLexState = defaultLexState; + input_stream = stream; + ReInitRounds(); + } + + private void ReInitRounds() + { + int i; + jjround = 0x80000001; + for (i = 0; i-- > 0;) + jjrounds[i] = 0x80000000; + } + + /** Reinitialise parser. */ + public void ReInit(SimpleCharStream stream, int lexState) + { + ReInit(stream); + SwitchTo(lexState); + } + + /** Switch to specified lex state. */ + public void SwitchTo(int lexState) + { + if (lexState >= 1 || lexState < 0) + throw new TokenMgrException("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrException.INVALID_LEXICAL_STATE); + else + curLexState = lexState; + } + + +/** Lexer state names. */ +public static final String[] lexStateNames = { + "DEFAULT", +}; + +/** Lex State array. */ +public static final int[] jjnewLexState = { + -1, -1, -1, -1, -1, -1, -1, +}; +static final long[] jjtoToken = { + 0x61L, +}; +static final long[] jjtoSkip = { + 0x1eL, +}; +static final long[] jjtoSpecial = { + 0x0L, +}; +static final long[] jjtoMore = { + 0x0L, +}; + protected SimpleCharStream input_stream; + + private final int[] jjrounds = new int[0]; + private final int[] jjstateSet = new int[2 * 0]; + private final StringBuilder jjimage = new StringBuilder(); + private StringBuilder image = jjimage; + private int jjimageLen; + private int lengthOfMatch; + protected int curChar; +} diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/SimpleCharStream.java b/src/test/resources/outputTest/SimpleExamples/Simple3/SimpleCharStream.java new file mode 100644 index 00000000..524f573d --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/SimpleCharStream.java @@ -0,0 +1,125 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. SimpleCharStream.java Version 2.0 */ +/* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * An implementation of interface CharStream, where the stream is assumed to + * contain only ASCII characters (without unicode processing). + */ +public +class SimpleCharStream extends AbstractCharStream +{ + private java.io.Reader m_aIS; + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + super (startline, startcolumn, buffersize); + m_aIS = dstream; + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + this(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.Reader dstream) + { + this(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn, + final int buffersize) + { + m_aIS = dstream; + super.reInit (startline, startcolumn, buffersize); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream, + final int startline, + final int startcolumn) + { + reInit(dstream, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.Reader dstream) + { + reInit(dstream, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + this(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Constructor. */ + public SimpleCharStream(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + this(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, 1, 1, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn) throws java.io.UnsupportedEncodingException + { + reInit(dstream, encoding, startline, startcolumn, DEFAULT_BUF_SIZE); + } + + /** Reinitialise. */ + public void reInit(final java.io.InputStream dstream, + final String encoding, + final int startline, + final int startcolumn, + final int buffersize) throws java.io.UnsupportedEncodingException + { + reInit(new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + } + + @Override + protected int streamRead (final char[] aBuf, final int nOfs, final int nLen) throws java.io.IOException + { + return m_aIS.read (aBuf, nOfs, nLen); + } + + @Override + protected void streamClose () throws java.io.IOException + { + if (m_aIS != null) + m_aIS.close (); + } +} +/* ParserGeneratorCC - OriginalChecksum=a636d4e6c01360f1f8ff44ccc038e096 (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/Token.java b/src/test/resources/outputTest/SimpleExamples/Simple3/Token.java new file mode 100644 index 00000000..6f9479e6 --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/Token.java @@ -0,0 +1,130 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. Token.java Version 2.0 */ +/* ParserGeneratorCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COLUMN=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ +/** + * Describes the input token stream. + */ + +public class Token +implements java.io.Serializable { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /** + * An integer that describes the kind of this token. This numbering + * system is determined by JavaCCParser, and a table of these numbers is + * stored in the file ...Constants.java. + */ + public int kind; + + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; + + /** + * The string image of the token. + */ + public String image; + + /** + * A reference to the next regular (non-special) token from the input + * stream. If this is the last token from the input stream, or if the + * token manager has not read tokens beyond this one, this field is + * set to null. This is true only if this token is also a regular + * token. Otherwise, see below for a description of the contents of + * this field. + */ + public Token next; + + /** + * This field is used to access special tokens that occur prior to this + * token, but after the immediately preceding regular (non-special) token. + * If there are no such special tokens, this field is set to null. + * When there are more than one such special token, this field refers + * to the last of these special tokens, which in turn refers to the next + * previous special token through its specialToken field, and so on + * until the first special token (whose specialToken field is null). + * The next fields of special tokens refer to other special tokens that + * immediately follow it (without an intervening regular token). If there + * is no such token, this field is null. + */ + public Token specialToken; + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(final int nKind) + { + this(nKind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(final int nKind, final String sImage) + { + this.kind = nKind; + this.image = sImage; + } + + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * Returns the image. + */ + @Override + public String toString() + { + return image; + } + + /** + * Returns a new Token object, by default. However, if you want, you + * can create and return subclass objects based on the value of ofKind. + * Simply add the cases to the switch for all those special cases. + * For example, if you have a subclass of Token called IDToken that + * you want to create if ofKind is ID, simply add something like : + * + * case MyParserConstants.ID : return new IDToken(ofKind, image); + * + * to the following switch statement. Then you can cast matchedToken + * variable to the appropriate type and use sit in your lexical actions. + */ + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) + { + return newToken(ofKind, null); + } + +} +/* ParserGeneratorCC - OriginalChecksum=ae381de5b4a0009742124c858504b0ac (do not edit this line) */ diff --git a/src/test/resources/outputTest/SimpleExamples/Simple3/TokenMgrException.java b/src/test/resources/outputTest/SimpleExamples/Simple3/TokenMgrException.java new file mode 100644 index 00000000..06ff8d8c --- /dev/null +++ b/src/test/resources/outputTest/SimpleExamples/Simple3/TokenMgrException.java @@ -0,0 +1,144 @@ +/* Generated by: ParserGeneratorCC: Do not edit this line. TokenMgrException.java Version 2.0 */ +/* ParserGeneratorCCOptions: */ +/** Token Manager Error. */ +public class TokenMgrException extends RuntimeException +{ + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ + + /** + * Lexical error occurred. + */ + public static final int LEXICAL_ERROR = 0; + + /** + * An attempt was made to create a second instance of a static token manager. + */ + public static final int STATIC_LEXER_ERROR = 1; + + /** + * Tried to change to an invalid lexical state. + */ + public static final int INVALID_LEXICAL_STATE = 2; + + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + public static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuilder retval = new StringBuilder(); + for (int i = 0; i < str.length(); i++) { + final char ch = str.charAt(i); + switch (ch) + { + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if (ch < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u").append (s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; + } + } + return retval.toString(); + } + + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalErr(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar) { + char curChar1 = (char)curChar; + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar1)) + "\"") + " (" + curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } + + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + @Override + public String getMessage() { + return super.getMessage(); + } + + /* + * Constructors of various flavors follow. + */ + /** No arg constructor. */ + public TokenMgrException() { + } + + /** Constructor with message and reason. */ + public TokenMgrException(String message, int reason) { + super(message); + errorCode = reason; + } + + /** Full Constructor. */ + public TokenMgrException(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, int curChar, int reason) { + this(LexicalErr(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } +} +/* ParserGeneratorCC - OriginalChecksum=8f0915774fd1c862b3a66559d540b089 (do not edit this line) */ From 508b07fcbe3353932f321c08663b318fcba6b1da Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Sun, 8 Oct 2023 10:53:14 +0200 Subject: [PATCH 2/2] normalize line endings --- src/test/java/com/helger/pgcc/parser/output/OutputTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/helger/pgcc/parser/output/OutputTest.java b/src/test/java/com/helger/pgcc/parser/output/OutputTest.java index 64b5ebf8..565da84d 100644 --- a/src/test/java/com/helger/pgcc/parser/output/OutputTest.java +++ b/src/test/java/com/helger/pgcc/parser/output/OutputTest.java @@ -124,9 +124,11 @@ private void test (String inputFile) throws Exception FileSystemIterator generatedFiles = new FileSystemIterator(outputDirectory); for (File generatedFile : generatedFiles) { String generated = SimpleFileIO.getFileAsString(generatedFile, StandardCharsets.UTF_8); + generated = generated.replaceAll("\\r\\n?", "\n"); File expectedFile = new File(expectationDir, generatedFile.getName()); String expected = SimpleFileIO.getFileAsString(expectedFile, StandardCharsets.UTF_8); + expected = expected.replaceAll("\\r\\n?", "\n"); assertEquals("The generated file '" + generatedFile.getName() + "' differs from the expected one.", expected, generated); }