diff --git a/examples/JavaGrammars/Java1.1-cpp.jj b/examples/JavaGrammars/Java1.1-cpp.jj deleted file mode 100644 index a44cb8311..000000000 --- a/examples/JavaGrammars/Java1.1-cpp.jj +++ /dev/null @@ -1,1673 +0,0 @@ -/* - * 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. - */ -options { - JAVA_UNICODE_ESCAPE = true; - output_language = "c++"; -} - -PARSER_BEGIN(JavaParser) - -PARSER_END(JavaParser) - -TOKEN_MGR_DECLS: -{ -} - - -/* WHITE SPACE */ - -SKIP : -{ - " " -| "\t" -| "\n" -| "\r" -| "\f" -} - -/* COMMENTS */ - -MORE : -{ - "//" : IN_SINGLE_LINE_COMMENT -| - <"/**" ~["/"]> { input_stream->backup(1); } : IN_FORMAL_COMMENT -| - "/*" : IN_MULTI_LINE_COMMENT -} - - -SPECIAL_TOKEN : -{ - : DEFAULT -} - - -SPECIAL_TOKEN : -{ - : DEFAULT -} - - -SPECIAL_TOKEN : -{ - : DEFAULT -} - - -MORE : -{ - < ~[] > -} - -/* RESERVED WORDS AND LITERALS */ - -TOKEN : -{ - < ABSTRACT: "abstract" > -| < BOOLEAN: "boolean" > -| < BREAK: "break" > -| < BYTE: "byte" > -| < CASE: "case" > -| < CATCH: "catch" > -| < CHAR: "char" > -| < CLASS: "class" > -| < CONST: "const" > -| < CONTINUE: "continue" > -| < _DEFAULT: "default" > -| < DO: "do" > -| < DOUBLE: "double" > -| < ELSE: "else" > -| < EXTENDS: "extends" > -| < FALSE: "false" > -| < FINAL: "final" > -| < FINALLY: "finally" > -| < FLOAT: "float" > -| < FOR: "for" > -| < GOTO: "goto" > -| < IF: "if" > -| < IMPLEMENTS: "implements" > -| < IMPORT: "import" > -| < INSTANCEOF: "instanceof" > -| < INT: "int" > -| < INTERFACE: "interface" > -| < LONG: "long" > -| < NATIVE: "native" > -| < NEW: "new" > -| < _NULL: "null" > -| < PACKAGE: "package"> -| < PRIVATE: "private" > -| < PROTECTED: "protected" > -| < PUBLIC: "public" > -| < RETURN: "return" > -| < SHORT: "short" > -| < STATIC: "static" > -| < SUPER: "super" > -| < SWITCH: "switch" > -| < SYNCHRONIZED: "synchronized" > -| < THIS: "this" > -| < THROW: "throw" > -| < THROWS: "throws" > -| < TRANSIENT: "transient" > -| < TRUE: "true" > -| < TRY: "try" > -| < VOID: "void" > -| < VOLATILE: "volatile" > -| < WHILE: "while" > -} - -/* LITERALS */ - -TOKEN : -{ - < INTEGER_LITERAL: - (["l","L"])? - | (["l","L"])? - | (["l","L"])? - > -| - < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > -| - < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > -| - < #OCTAL_LITERAL: "0" (["0"-"7"])* > -| - < FLOATING_POINT_LITERAL: - (["0"-"9"])+ "." (["0"-"9"])* ()? (["f","F","d","D"])? - | "." (["0"-"9"])+ ()? (["f","F","d","D"])? - | (["0"-"9"])+ (["f","F","d","D"])? - | (["0"-"9"])+ ()? ["f","F","d","D"] - > -| - < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > -| - < CHARACTER_LITERAL: - "'" - ( (~["'","\\","\n","\r"]) - | ("\\" - ( ["n","t","b","r","f","\\","'","\""] - | ["0"-"7"] ( ["0"-"7"] )? - | ["0"-"3"] ["0"-"7"] ["0"-"7"] - ) - ) - ) - "'" - > -| - < STRING_LITERAL: - "\"" - ( (~["\"","\\","\n","\r"]) - | ("\\" - ( ["n","t","b","r","f","\\","'","\""] - | ["0"-"7"] ( ["0"-"7"] )? - | ["0"-"3"] ["0"-"7"] ["0"-"7"] - ) - ) - )* - "\"" - > -} - -/* IDENTIFIERS */ - -TOKEN : -{ - < IDENTIFIER: ()* > -| - < #LETTER: - [ // all chars for which Character.isIdentifierStart is true - "$", - "A"-"Z", - "_", - "a"-"z", - "\u00a2"-"\u00a5", - "\u00aa", - "\u00b5", - "\u00ba", - "\u00c0"-"\u00d6", - "\u00d8"-"\u00f6", - "\u00f8"-"\u021f", - "\u0222"-"\u0233", - "\u0250"-"\u02ad", - "\u02b0"-"\u02b8", - "\u02bb"-"\u02c1", - "\u02d0"-"\u02d1", - "\u02e0"-"\u02e4", - "\u02ee", - "\u037a", - "\u0386", - "\u0388"-"\u038a", - "\u038c", - "\u038e"-"\u03a1", - "\u03a3"-"\u03ce", - "\u03d0"-"\u03d7", - "\u03da"-"\u03f3", - "\u0400"-"\u0481", - "\u048c"-"\u04c4", - "\u04c7"-"\u04c8", - "\u04cb"-"\u04cc", - "\u04d0"-"\u04f5", - "\u04f8"-"\u04f9", - "\u0531"-"\u0556", - "\u0559", - "\u0561"-"\u0587", - "\u05d0"-"\u05ea", - "\u05f0"-"\u05f2", - "\u0621"-"\u063a", - "\u0640"-"\u064a", - "\u0671"-"\u06d3", - "\u06d5", - "\u06e5"-"\u06e6", - "\u06fa"-"\u06fc", - "\u0710", - "\u0712"-"\u072c", - "\u0780"-"\u07a5", - "\u0905"-"\u0939", - "\u093d", - "\u0950", - "\u0958"-"\u0961", - "\u0985"-"\u098c", - "\u098f"-"\u0990", - "\u0993"-"\u09a8", - "\u09aa"-"\u09b0", - "\u09b2", - "\u09b6"-"\u09b9", - "\u09dc"-"\u09dd", - "\u09df"-"\u09e1", - "\u09f0"-"\u09f3", - "\u0a05"-"\u0a0a", - "\u0a0f"-"\u0a10", - "\u0a13"-"\u0a28", - "\u0a2a"-"\u0a30", - "\u0a32"-"\u0a33", - "\u0a35"-"\u0a36", - "\u0a38"-"\u0a39", - "\u0a59"-"\u0a5c", - "\u0a5e", - "\u0a72"-"\u0a74", - "\u0a85"-"\u0a8b", - "\u0a8d", - "\u0a8f"-"\u0a91", - "\u0a93"-"\u0aa8", - "\u0aaa"-"\u0ab0", - "\u0ab2"-"\u0ab3", - "\u0ab5"-"\u0ab9", - "\u0abd", - "\u0ad0", - "\u0ae0", - "\u0b05"-"\u0b0c", - "\u0b0f"-"\u0b10", - "\u0b13"-"\u0b28", - "\u0b2a"-"\u0b30", - "\u0b32"-"\u0b33", - "\u0b36"-"\u0b39", - "\u0b3d", - "\u0b5c"-"\u0b5d", - "\u0b5f"-"\u0b61", - "\u0b85"-"\u0b8a", - "\u0b8e"-"\u0b90", - "\u0b92"-"\u0b95", - "\u0b99"-"\u0b9a", - "\u0b9c", - "\u0b9e"-"\u0b9f", - "\u0ba3"-"\u0ba4", - "\u0ba8"-"\u0baa", - "\u0bae"-"\u0bb5", - "\u0bb7"-"\u0bb9", - "\u0c05"-"\u0c0c", - "\u0c0e"-"\u0c10", - "\u0c12"-"\u0c28", - "\u0c2a"-"\u0c33", - "\u0c35"-"\u0c39", - "\u0c60"-"\u0c61", - "\u0c85"-"\u0c8c", - "\u0c8e"-"\u0c90", - "\u0c92"-"\u0ca8", - "\u0caa"-"\u0cb3", - "\u0cb5"-"\u0cb9", - "\u0cde", - "\u0ce0"-"\u0ce1", - "\u0d05"-"\u0d0c", - "\u0d0e"-"\u0d10", - "\u0d12"-"\u0d28", - "\u0d2a"-"\u0d39", - "\u0d60"-"\u0d61", - "\u0d85"-"\u0d96", - "\u0d9a"-"\u0db1", - "\u0db3"-"\u0dbb", - "\u0dbd", - "\u0dc0"-"\u0dc6", - "\u0e01"-"\u0e30", - "\u0e32"-"\u0e33", - "\u0e3f"-"\u0e46", - "\u0e81"-"\u0e82", - "\u0e84", - "\u0e87"-"\u0e88", - "\u0e8a", - "\u0e8d", - "\u0e94"-"\u0e97", - "\u0e99"-"\u0e9f", - "\u0ea1"-"\u0ea3", - "\u0ea5", - "\u0ea7", - "\u0eaa"-"\u0eab", - "\u0ead"-"\u0eb0", - "\u0eb2"-"\u0eb3", - "\u0ebd", - "\u0ec0"-"\u0ec4", - "\u0ec6", - "\u0edc"-"\u0edd", - "\u0f00", - "\u0f40"-"\u0f47", - "\u0f49"-"\u0f6a", - "\u0f88"-"\u0f8b", - "\u1000"-"\u1021", - "\u1023"-"\u1027", - "\u1029"-"\u102a", - "\u1050"-"\u1055", - "\u10a0"-"\u10c5", - "\u10d0"-"\u10f6", - "\u1100"-"\u1159", - "\u115f"-"\u11a2", - "\u11a8"-"\u11f9", - "\u1200"-"\u1206", - "\u1208"-"\u1246", - "\u1248", - "\u124a"-"\u124d", - "\u1250"-"\u1256", - "\u1258", - "\u125a"-"\u125d", - "\u1260"-"\u1286", - "\u1288", - "\u128a"-"\u128d", - "\u1290"-"\u12ae", - "\u12b0", - "\u12b2"-"\u12b5", - "\u12b8"-"\u12be", - "\u12c0", - "\u12c2"-"\u12c5", - "\u12c8"-"\u12ce", - "\u12d0"-"\u12d6", - "\u12d8"-"\u12ee", - "\u12f0"-"\u130e", - "\u1310", - "\u1312"-"\u1315", - "\u1318"-"\u131e", - "\u1320"-"\u1346", - "\u1348"-"\u135a", - "\u13a0"-"\u13f4", - "\u1401"-"\u166c", - "\u166f"-"\u1676", - "\u1681"-"\u169a", - "\u16a0"-"\u16ea", - "\u1780"-"\u17b3", - "\u17db", - "\u1820"-"\u1877", - "\u1880"-"\u18a8", - "\u1e00"-"\u1e9b", - "\u1ea0"-"\u1ef9", - "\u1f00"-"\u1f15", - "\u1f18"-"\u1f1d", - "\u1f20"-"\u1f45", - "\u1f48"-"\u1f4d", - "\u1f50"-"\u1f57", - "\u1f59", - "\u1f5b", - "\u1f5d", - "\u1f5f"-"\u1f7d", - "\u1f80"-"\u1fb4", - "\u1fb6"-"\u1fbc", - "\u1fbe", - "\u1fc2"-"\u1fc4", - "\u1fc6"-"\u1fcc", - "\u1fd0"-"\u1fd3", - "\u1fd6"-"\u1fdb", - "\u1fe0"-"\u1fec", - "\u1ff2"-"\u1ff4", - "\u1ff6"-"\u1ffc", - "\u203f"-"\u2040", - "\u207f", - "\u20a0"-"\u20af", - "\u2102", - "\u2107", - "\u210a"-"\u2113", - "\u2115", - "\u2119"-"\u211d", - "\u2124", - "\u2126", - "\u2128", - "\u212a"-"\u212d", - "\u212f"-"\u2131", - "\u2133"-"\u2139", - "\u2160"-"\u2183", - "\u3005"-"\u3007", - "\u3021"-"\u3029", - "\u3031"-"\u3035", - "\u3038"-"\u303a", - "\u3041"-"\u3094", - "\u309d"-"\u309e", - "\u30a1"-"\u30fe", - "\u3105"-"\u312c", - "\u3131"-"\u318e", - "\u31a0"-"\u31b7", - "\u3400"-"\u4db5", - "\u4e00"-"\u9fa5", - "\ua000"-"\ua48c", - "\uac00"-"\ud7a3", - "\uf900"-"\ufa2d", - "\ufb00"-"\ufb06", - "\ufb13"-"\ufb17", - "\ufb1d", - "\ufb1f"-"\ufb28", - "\ufb2a"-"\ufb36", - "\ufb38"-"\ufb3c", - "\ufb3e", - "\ufb40"-"\ufb41", - "\ufb43"-"\ufb44", - "\ufb46"-"\ufbb1", - "\ufbd3"-"\ufd3d", - "\ufd50"-"\ufd8f", - "\ufd92"-"\ufdc7", - "\ufdf0"-"\ufdfb", - "\ufe33"-"\ufe34", - "\ufe4d"-"\ufe4f", - "\ufe69", - "\ufe70"-"\ufe72", - "\ufe74", - "\ufe76"-"\ufefc", - "\uff04", - "\uff21"-"\uff3a", - "\uff3f", - "\uff41"-"\uff5a", - "\uff65"-"\uffbe", - "\uffc2"-"\uffc7", - "\uffca"-"\uffcf", - "\uffd2"-"\uffd7", - "\uffda"-"\uffdc", - "\uffe0"-"\uffe1", - "\uffe5"-"\uffe6" - ] - > -| - < #PART_LETTER: - [ // all chars for which Character.isIdentifierPart is true - "\u0000"-"\u0008", - "\u000e"-"\u001b", - "$", - "0"-"9", - "A"-"Z", - "_", - "a"-"z", - "\u007f"-"\u009f", - "\u00a2"-"\u00a5", - "\u00aa", - "\u00b5", - "\u00ba", - "\u00c0"-"\u00d6", - "\u00d8"-"\u00f6", - "\u00f8"-"\u021f", - "\u0222"-"\u0233", - "\u0250"-"\u02ad", - "\u02b0"-"\u02b8", - "\u02bb"-"\u02c1", - "\u02d0"-"\u02d1", - "\u02e0"-"\u02e4", - "\u02ee", - "\u0300"-"\u034e", - "\u0360"-"\u0362", - "\u037a", - "\u0386", - "\u0388"-"\u038a", - "\u038c", - "\u038e"-"\u03a1", - "\u03a3"-"\u03ce", - "\u03d0"-"\u03d7", - "\u03da"-"\u03f3", - "\u0400"-"\u0481", - "\u0483"-"\u0486", - "\u048c"-"\u04c4", - "\u04c7"-"\u04c8", - "\u04cb"-"\u04cc", - "\u04d0"-"\u04f5", - "\u04f8"-"\u04f9", - "\u0531"-"\u0556", - "\u0559", - "\u0561"-"\u0587", - "\u0591"-"\u05a1", - "\u05a3"-"\u05b9", - "\u05bb"-"\u05bd", - "\u05bf", - "\u05c1"-"\u05c2", - "\u05c4", - "\u05d0"-"\u05ea", - "\u05f0"-"\u05f2", - "\u0621"-"\u063a", - "\u0640"-"\u0655", - "\u0660"-"\u0669", - "\u0670"-"\u06d3", - "\u06d5"-"\u06dc", - "\u06df"-"\u06e8", - "\u06ea"-"\u06ed", - "\u06f0"-"\u06fc", - "\u070f"-"\u072c", - "\u0730"-"\u074a", - "\u0780"-"\u07b0", - "\u0901"-"\u0903", - "\u0905"-"\u0939", - "\u093c"-"\u094d", - "\u0950"-"\u0954", - "\u0958"-"\u0963", - "\u0966"-"\u096f", - "\u0981"-"\u0983", - "\u0985"-"\u098c", - "\u098f"-"\u0990", - "\u0993"-"\u09a8", - "\u09aa"-"\u09b0", - "\u09b2", - "\u09b6"-"\u09b9", - "\u09bc", - "\u09be"-"\u09c4", - "\u09c7"-"\u09c8", - "\u09cb"-"\u09cd", - "\u09d7", - "\u09dc"-"\u09dd", - "\u09df"-"\u09e3", - "\u09e6"-"\u09f3", - "\u0a02", - "\u0a05"-"\u0a0a", - "\u0a0f"-"\u0a10", - "\u0a13"-"\u0a28", - "\u0a2a"-"\u0a30", - "\u0a32"-"\u0a33", - "\u0a35"-"\u0a36", - "\u0a38"-"\u0a39", - "\u0a3c", - "\u0a3e"-"\u0a42", - "\u0a47"-"\u0a48", - "\u0a4b"-"\u0a4d", - "\u0a59"-"\u0a5c", - "\u0a5e", - "\u0a66"-"\u0a74", - "\u0a81"-"\u0a83", - "\u0a85"-"\u0a8b", - "\u0a8d", - "\u0a8f"-"\u0a91", - "\u0a93"-"\u0aa8", - "\u0aaa"-"\u0ab0", - "\u0ab2"-"\u0ab3", - "\u0ab5"-"\u0ab9", - "\u0abc"-"\u0ac5", - "\u0ac7"-"\u0ac9", - "\u0acb"-"\u0acd", - "\u0ad0", - "\u0ae0", - "\u0ae6"-"\u0aef", - "\u0b01"-"\u0b03", - "\u0b05"-"\u0b0c", - "\u0b0f"-"\u0b10", - "\u0b13"-"\u0b28", - "\u0b2a"-"\u0b30", - "\u0b32"-"\u0b33", - "\u0b36"-"\u0b39", - "\u0b3c"-"\u0b43", - "\u0b47"-"\u0b48", - "\u0b4b"-"\u0b4d", - "\u0b56"-"\u0b57", - "\u0b5c"-"\u0b5d", - "\u0b5f"-"\u0b61", - "\u0b66"-"\u0b6f", - "\u0b82"-"\u0b83", - "\u0b85"-"\u0b8a", - "\u0b8e"-"\u0b90", - "\u0b92"-"\u0b95", - "\u0b99"-"\u0b9a", - "\u0b9c", - "\u0b9e"-"\u0b9f", - "\u0ba3"-"\u0ba4", - "\u0ba8"-"\u0baa", - "\u0bae"-"\u0bb5", - "\u0bb7"-"\u0bb9", - "\u0bbe"-"\u0bc2", - "\u0bc6"-"\u0bc8", - "\u0bca"-"\u0bcd", - "\u0bd7", - "\u0be7"-"\u0bef", - "\u0c01"-"\u0c03", - "\u0c05"-"\u0c0c", - "\u0c0e"-"\u0c10", - "\u0c12"-"\u0c28", - "\u0c2a"-"\u0c33", - "\u0c35"-"\u0c39", - "\u0c3e"-"\u0c44", - "\u0c46"-"\u0c48", - "\u0c4a"-"\u0c4d", - "\u0c55"-"\u0c56", - "\u0c60"-"\u0c61", - "\u0c66"-"\u0c6f", - "\u0c82"-"\u0c83", - "\u0c85"-"\u0c8c", - "\u0c8e"-"\u0c90", - "\u0c92"-"\u0ca8", - "\u0caa"-"\u0cb3", - "\u0cb5"-"\u0cb9", - "\u0cbe"-"\u0cc4", - "\u0cc6"-"\u0cc8", - "\u0cca"-"\u0ccd", - "\u0cd5"-"\u0cd6", - "\u0cde", - "\u0ce0"-"\u0ce1", - "\u0ce6"-"\u0cef", - "\u0d02"-"\u0d03", - "\u0d05"-"\u0d0c", - "\u0d0e"-"\u0d10", - "\u0d12"-"\u0d28", - "\u0d2a"-"\u0d39", - "\u0d3e"-"\u0d43", - "\u0d46"-"\u0d48", - "\u0d4a"-"\u0d4d", - "\u0d57", - "\u0d60"-"\u0d61", - "\u0d66"-"\u0d6f", - "\u0d82"-"\u0d83", - "\u0d85"-"\u0d96", - "\u0d9a"-"\u0db1", - "\u0db3"-"\u0dbb", - "\u0dbd", - "\u0dc0"-"\u0dc6", - "\u0dca", - "\u0dcf"-"\u0dd4", - "\u0dd6", - "\u0dd8"-"\u0ddf", - "\u0df2"-"\u0df3", - "\u0e01"-"\u0e3a", - "\u0e3f"-"\u0e4e", - "\u0e50"-"\u0e59", - "\u0e81"-"\u0e82", - "\u0e84", - "\u0e87"-"\u0e88", - "\u0e8a", - "\u0e8d", - "\u0e94"-"\u0e97", - "\u0e99"-"\u0e9f", - "\u0ea1"-"\u0ea3", - "\u0ea5", - "\u0ea7", - "\u0eaa"-"\u0eab", - "\u0ead"-"\u0eb9", - "\u0ebb"-"\u0ebd", - "\u0ec0"-"\u0ec4", - "\u0ec6", - "\u0ec8"-"\u0ecd", - "\u0ed0"-"\u0ed9", - "\u0edc"-"\u0edd", - "\u0f00", - "\u0f18"-"\u0f19", - "\u0f20"-"\u0f29", - "\u0f35", - "\u0f37", - "\u0f39", - "\u0f3e"-"\u0f47", - "\u0f49"-"\u0f6a", - "\u0f71"-"\u0f84", - "\u0f86"-"\u0f8b", - "\u0f90"-"\u0f97", - "\u0f99"-"\u0fbc", - "\u0fc6", - "\u1000"-"\u1021", - "\u1023"-"\u1027", - "\u1029"-"\u102a", - "\u102c"-"\u1032", - "\u1036"-"\u1039", - "\u1040"-"\u1049", - "\u1050"-"\u1059", - "\u10a0"-"\u10c5", - "\u10d0"-"\u10f6", - "\u1100"-"\u1159", - "\u115f"-"\u11a2", - "\u11a8"-"\u11f9", - "\u1200"-"\u1206", - "\u1208"-"\u1246", - "\u1248", - "\u124a"-"\u124d", - "\u1250"-"\u1256", - "\u1258", - "\u125a"-"\u125d", - "\u1260"-"\u1286", - "\u1288", - "\u128a"-"\u128d", - "\u1290"-"\u12ae", - "\u12b0", - "\u12b2"-"\u12b5", - "\u12b8"-"\u12be", - "\u12c0", - "\u12c2"-"\u12c5", - "\u12c8"-"\u12ce", - "\u12d0"-"\u12d6", - "\u12d8"-"\u12ee", - "\u12f0"-"\u130e", - "\u1310", - "\u1312"-"\u1315", - "\u1318"-"\u131e", - "\u1320"-"\u1346", - "\u1348"-"\u135a", - "\u1369"-"\u1371", - "\u13a0"-"\u13f4", - "\u1401"-"\u166c", - "\u166f"-"\u1676", - "\u1681"-"\u169a", - "\u16a0"-"\u16ea", - "\u1780"-"\u17d3", - "\u17db", - "\u17e0"-"\u17e9", - "\u180b"-"\u180e", - "\u1810"-"\u1819", - "\u1820"-"\u1877", - "\u1880"-"\u18a9", - "\u1e00"-"\u1e9b", - "\u1ea0"-"\u1ef9", - "\u1f00"-"\u1f15", - "\u1f18"-"\u1f1d", - "\u1f20"-"\u1f45", - "\u1f48"-"\u1f4d", - "\u1f50"-"\u1f57", - "\u1f59", - "\u1f5b", - "\u1f5d", - "\u1f5f"-"\u1f7d", - "\u1f80"-"\u1fb4", - "\u1fb6"-"\u1fbc", - "\u1fbe", - "\u1fc2"-"\u1fc4", - "\u1fc6"-"\u1fcc", - "\u1fd0"-"\u1fd3", - "\u1fd6"-"\u1fdb", - "\u1fe0"-"\u1fec", - "\u1ff2"-"\u1ff4", - "\u1ff6"-"\u1ffc", - "\u200c"-"\u200f", - "\u202a"-"\u202e", - "\u203f"-"\u2040", - "\u206a"-"\u206f", - "\u207f", - "\u20a0"-"\u20af", - "\u20d0"-"\u20dc", - "\u20e1", - "\u2102", - "\u2107", - "\u210a"-"\u2113", - "\u2115", - "\u2119"-"\u211d", - "\u2124", - "\u2126", - "\u2128", - "\u212a"-"\u212d", - "\u212f"-"\u2131", - "\u2133"-"\u2139", - "\u2160"-"\u2183", - "\u3005"-"\u3007", - "\u3021"-"\u302f", - "\u3031"-"\u3035", - "\u3038"-"\u303a", - "\u3041"-"\u3094", - "\u3099"-"\u309a", - "\u309d"-"\u309e", - "\u30a1"-"\u30fe", - "\u3105"-"\u312c", - "\u3131"-"\u318e", - "\u31a0"-"\u31b7", - "\u3400"-"\u4db5", - "\u4e00"-"\u9fa5", - "\ua000"-"\ua48c", - "\uac00"-"\ud7a3", - "\uf900"-"\ufa2d", - "\ufb00"-"\ufb06", - "\ufb13"-"\ufb17", - "\ufb1d"-"\ufb28", - "\ufb2a"-"\ufb36", - "\ufb38"-"\ufb3c", - "\ufb3e", - "\ufb40"-"\ufb41", - "\ufb43"-"\ufb44", - "\ufb46"-"\ufbb1", - "\ufbd3"-"\ufd3d", - "\ufd50"-"\ufd8f", - "\ufd92"-"\ufdc7", - "\ufdf0"-"\ufdfb", - "\ufe20"-"\ufe23", - "\ufe33"-"\ufe34", - "\ufe4d"-"\ufe4f", - "\ufe69", - "\ufe70"-"\ufe72", - "\ufe74", - "\ufe76"-"\ufefc", - "\ufeff", - "\uff04", - "\uff10"-"\uff19", - "\uff21"-"\uff3a", - "\uff3f", - "\uff41"-"\uff5a", - "\uff65"-"\uffbe", - "\uffc2"-"\uffc7", - "\uffca"-"\uffcf", - "\uffd2"-"\uffd7", - "\uffda"-"\uffdc", - "\uffe0"-"\uffe1", - "\uffe5"-"\uffe6", - "\ufff9"-"\ufffb" - ] - > -} - -/* SEPARATORS */ - -TOKEN : -{ - < LPAREN: "(" > -| < RPAREN: ")" > -| < LBRACE: "{" > -| < RBRACE: "}" > -| < LBRACKET: "[" > -| < RBRACKET: "]" > -| < SEMICOLON: ";" > -| < COMMA: "," > -| < DOT: "." > -} - -/* OPERATORS */ - -TOKEN : -{ - < ASSIGN: "=" > -| < GT: ">" > -| < LT: "<" > -| < BANG: "!" > -| < TILDE: "~" > -| < HOOK: "?" > -| < COLON: ":" > -| < EQ: "==" > -| < LE: "<=" > -| < GE: ">=" > -| < NE: "!=" > -| < SC_OR: "||" > -| < SC_AND: "&&" > -| < INCR: "++" > -| < DECR: "--" > -| < PLUS: "+" > -| < MINUS: "-" > -| < STAR: "*" > -| < SLASH: "/" > -| < BIT_AND: "&" > -| < BIT_OR: "|" > -| < XOR: "^" > -| < REM: "%" > -| < LSHIFT: "<<" > -| < RSIGNEDSHIFT: ">>" > -| < RUNSIGNEDSHIFT: ">>>" > -| < PLUSASSIGN: "+=" > -| < MINUSASSIGN: "-=" > -| < STARASSIGN: "*=" > -| < SLASHASSIGN: "/=" > -| < ANDASSIGN: "&=" > -| < ORASSIGN: "|=" > -| < XORASSIGN: "^=" > -| < REMASSIGN: "%=" > -| < LSHIFTASSIGN: "<<=" > -| < RSIGNEDSHIFTASSIGN: ">>=" > -| < RUNSIGNEDSHIFTASSIGN: ">>>=" > -} - - -/***************************************** - * THE JAVA LANGUAGE GRAMMAR STARTS HERE * - *****************************************/ - -/* - * Program structuring syntax follows. - */ - -void CompilationUnit() : -{} -{ - [ PackageDeclaration() ] - ( ImportDeclaration() )* - ( TypeDeclaration() )* - -} - -void PackageDeclaration() : -{} -{ - "package" Name() ";" -} - -void ImportDeclaration() : -{} -{ - "import" Name() [ "." "*" ] ";" -} - -void TypeDeclaration() : -{} -{ - LOOKAHEAD( ( "abstract" | "final" | "public" )* "class" ) - ClassDeclaration() -| - InterfaceDeclaration() -| - ";" -} - - -/* - * Declaration syntax follows. - */ - -void ClassDeclaration() : -{} -{ - ( "abstract" | "final" | "public" )* - UnmodifiedClassDeclaration() -} - -void UnmodifiedClassDeclaration() : -{} -{ - "class" [ "extends" Name() ] [ "implements" NameList() ] - ClassBody() -} - -void ClassBody() : -{} -{ - "{" ( ClassBodyDeclaration() )* "}" -} - -void NestedClassDeclaration() : -{} -{ - ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* - UnmodifiedClassDeclaration() -} - -void ClassBodyDeclaration() : -{} -{ - LOOKAHEAD(2) - Initializer() -| - LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "class" ) - NestedClassDeclaration() -| - LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "interface" ) - NestedInterfaceDeclaration() -| - LOOKAHEAD( [ "public" | "protected" | "private" ] Name() "(" ) - ConstructorDeclaration() -| - LOOKAHEAD( MethodDeclarationLookahead() ) - MethodDeclaration() -| - FieldDeclaration() -} - -// This production is to determine lookahead only. -void MethodDeclarationLookahead() : -{} -{ - ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )* - ResultType() "(" -} - -void InterfaceDeclaration() : -{} -{ - ( "abstract" | "public" )* - UnmodifiedInterfaceDeclaration() -} - -void NestedInterfaceDeclaration() : -{} -{ - ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* - UnmodifiedInterfaceDeclaration() -} - -void UnmodifiedInterfaceDeclaration() : -{} -{ - "interface" [ "extends" NameList() ] - "{" ( InterfaceMemberDeclaration() )* "}" -} - -void InterfaceMemberDeclaration() : -{} -{ - LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "class" ) - NestedClassDeclaration() -| - LOOKAHEAD( ( "static" | "abstract" | "final" | "public" | "protected" | "private" )* "interface" ) - NestedInterfaceDeclaration() -| - LOOKAHEAD( MethodDeclarationLookahead() ) - MethodDeclaration() -| - FieldDeclaration() -} - -void FieldDeclaration() : -{} -{ - ( "public" | "protected" | "private" | "static" | "final" | "transient" | "volatile" )* - Type() VariableDeclarator() ( "," VariableDeclarator() )* ";" -} - -void VariableDeclarator() : -{} -{ - VariableDeclaratorId() [ "=" VariableInitializer() ] -} - -void VariableDeclaratorId() : -{} -{ - ( "[" "]" )* -} - -void VariableInitializer() : -{} -{ - ArrayInitializer() -| - Expression() -} - -void ArrayInitializer() : -{} -{ - "{" [ VariableInitializer() ( LOOKAHEAD(2) "," VariableInitializer() )* ] [ "," ] "}" -} - -void MethodDeclaration() : -{} -{ - ( "public" | "protected" | "private" | "static" | "abstract" | "final" | "native" | "synchronized" )* - ResultType() MethodDeclarator() [ "throws" NameList() ] - ( Block() | ";" ) -} - -void MethodDeclarator() : -{} -{ - FormalParameters() ( "[" "]" )* -} - -void FormalParameters() : -{} -{ - "(" [ FormalParameter() ( "," FormalParameter() )* ] ")" -} - -void FormalParameter() : -{} -{ - [ "final" ] Type() VariableDeclaratorId() -} - -void ConstructorDeclaration() : -{} -{ - [ "public" | "protected" | "private" ] - FormalParameters() [ "throws" NameList() ] - "{" - [ LOOKAHEAD(ExplicitConstructorInvocation()) ExplicitConstructorInvocation() ] - ( BlockStatement() )* - "}" -} - -void ExplicitConstructorInvocation() : -{} -{ - LOOKAHEAD("this" Arguments() ";") - "this" Arguments() ";" -| - [ LOOKAHEAD(2) PrimaryExpression() "." ] "super" Arguments() ";" -} - -void Initializer() : -{} -{ - [ "static" ] Block() -} - - -/* - * Type, name and expression syntax follows. - */ - -void Type() : -{} -{ - ( PrimitiveType() | Name() ) ( "[" "]" )* -} - -void PrimitiveType() : -{} -{ - "boolean" -| - "char" -| - "byte" -| - "short" -| - "int" -| - "long" -| - "float" -| - "double" -} - -void ResultType() : -{} -{ - "void" -| - Type() -} - -void Name() : -/* - * A lookahead of 2 is required below since "Name" can be followed - * by a ".*" when used in the context of an "ImportDeclaration". - */ -{} -{ - - ( LOOKAHEAD(2) "." - )* -} - -void NameList() : -{} -{ - Name() - ( "," Name() - )* -} - - -/* - * Expression syntax follows. - */ - -void Expression() : -/* - * This expansion has been written this way instead of: - * Assignment() | ConditionalExpression() - * for performance reasons. - * However, it is a weakening of the grammar for it allows the LHS of - * assignments to be any conditional expression whereas it can only be - * a primary expression. Consider adding a semantic predicate to work - * around this. - */ -{} -{ - ConditionalExpression() - [ - AssignmentOperator() Expression() - ] -} - -void AssignmentOperator() : -{} -{ - "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>=" | "&=" | "^=" | "|=" -} - -void ConditionalExpression() : -{} -{ - ConditionalOrExpression() [ "?" Expression() ":" ConditionalExpression() ] -} - -void ConditionalOrExpression() : -{} -{ - ConditionalAndExpression() ( "||" ConditionalAndExpression() )* -} - -void ConditionalAndExpression() : -{} -{ - InclusiveOrExpression() ( "&&" InclusiveOrExpression() )* -} - -void InclusiveOrExpression() : -{} -{ - ExclusiveOrExpression() ( "|" ExclusiveOrExpression() )* -} - -void ExclusiveOrExpression() : -{} -{ - AndExpression() ( "^" AndExpression() )* -} - -void AndExpression() : -{} -{ - EqualityExpression() ( "&" EqualityExpression() )* -} - -void EqualityExpression() : -{} -{ - InstanceOfExpression() ( ( "==" | "!=" ) InstanceOfExpression() )* -} - -void InstanceOfExpression() : -{} -{ - RelationalExpression() [ "instanceof" Type() ] -} - -void RelationalExpression() : -{} -{ - ShiftExpression() ( ( "<" | ">" | "<=" | ">=" ) ShiftExpression() )* -} - -void ShiftExpression() : -{} -{ - AdditiveExpression() ( ( "<<" | ">>" | ">>>" ) AdditiveExpression() )* -} - -void AdditiveExpression() : -{} -{ - MultiplicativeExpression() ( ( "+" | "-" ) MultiplicativeExpression() )* -} - -void MultiplicativeExpression() : -{} -{ - UnaryExpression() ( ( "*" | "/" | "%" ) UnaryExpression() )* -} - -void UnaryExpression() : -{} -{ - ( "+" | "-" ) UnaryExpression() -| - PreIncrementExpression() -| - PreDecrementExpression() -| - UnaryExpressionNotPlusMinus() -} - -void PreIncrementExpression() : -{} -{ - "++" PrimaryExpression() -} - -void PreDecrementExpression() : -{} -{ - "--" PrimaryExpression() -} - -void UnaryExpressionNotPlusMinus() : -{} -{ - ( "~" | "!" ) UnaryExpression() -| - LOOKAHEAD( CastLookahead() ) - CastExpression() -| - PostfixExpression() -} - -// 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. -void CastLookahead() : -{} -{ - LOOKAHEAD(2) - "(" PrimitiveType() -| - LOOKAHEAD("(" Name() "[") - "(" Name() "[" "]" -| - "(" Name() ")" ( "~" | "!" | "(" | | "this" | "super" | "new" | Literal() ) -} - -void PostfixExpression() : -{} -{ - PrimaryExpression() [ "++" | "--" ] -} - -void CastExpression() : -{} -{ - LOOKAHEAD("(" PrimitiveType()) - "(" Type() ")" UnaryExpression() -| - "(" Type() ")" UnaryExpressionNotPlusMinus() -} - -void PrimaryExpression() : -{} -{ - PrimaryPrefix() ( LOOKAHEAD(2) PrimarySuffix() )* -} - -void PrimaryPrefix() : -{} -{ - Literal() -| - "this" -| - "super" "." -| - "(" Expression() ")" -| - AllocationExpression() -| - LOOKAHEAD( ResultType() "." "class" ) - ResultType() "." "class" -| - Name() -} - -void PrimarySuffix() : -{} -{ - LOOKAHEAD(2) - "." "this" -| - LOOKAHEAD(2) - "." AllocationExpression() -| - "[" Expression() "]" -| - "." -| - Arguments() -} - -void Literal() : -{} -{ - -| - -| - -| - -| - BooleanLiteral() -| - NullLiteral() -} - -void BooleanLiteral() : -{} -{ - "true" -| - "false" -} - -void NullLiteral() : -{} -{ - "null" -} - -void Arguments() : -{} -{ - "(" [ ArgumentList() ] ")" -} - -void ArgumentList() : -{} -{ - Expression() ( "," Expression() )* -} - -void AllocationExpression() : -{} -{ - LOOKAHEAD(2) - "new" PrimitiveType() ArrayDimsAndInits() -| - "new" Name() - ( - ArrayDimsAndInits() - | - Arguments() [ ClassBody() ] - ) -} - -/* - * The third LOOKAHEAD specification below is to parse to PrimarySuffix - * if there is an expression between the "[...]". - */ -void ArrayDimsAndInits() : -{} -{ - LOOKAHEAD(2) - ( LOOKAHEAD(2) "[" Expression() "]" )+ ( LOOKAHEAD(2) "[" "]" )* -| - ( "[" "]" )+ ArrayInitializer() -} - - -/* - * Statement syntax follows. - */ - -void Statement() : -{} -{ - LOOKAHEAD(2) - LabeledStatement() -| - Block() -| - EmptyStatement() -| - StatementExpression() ";" -| - SwitchStatement() -| - IfStatement() -| - WhileStatement() -| - DoStatement() -| - ForStatement() -| - BreakStatement() -| - ContinueStatement() -| - ReturnStatement() -| - ThrowStatement() -| - SynchronizedStatement() -| - TryStatement() -} - -void LabeledStatement() : -{} -{ - ":" Statement() -} - -void Block() : -{} -{ - "{" ( BlockStatement() )* "}" -} - -void BlockStatement() : -{} -{ - LOOKAHEAD([ "final" ] Type() ) - LocalVariableDeclaration() ";" -| - Statement() -| - UnmodifiedClassDeclaration() -| - UnmodifiedInterfaceDeclaration() -} - -void LocalVariableDeclaration() : -{} -{ - [ "final" ] Type() VariableDeclarator() ( "," VariableDeclarator() )* -} - -void EmptyStatement() : -{} -{ - ";" -} - -void StatementExpression() : -/* - * The last expansion of this production accepts more than the legal - * Java expansions for StatementExpression. This expansion does not - * use PostfixExpression for performance reasons. - */ -{} -{ - PreIncrementExpression() -| - PreDecrementExpression() -| - PrimaryExpression() - [ - "++" - | - "--" - | - AssignmentOperator() Expression() - ] -} - -void SwitchStatement() : -{} -{ - "switch" "(" Expression() ")" "{" - ( SwitchLabel() ( BlockStatement() )* )* - "}" -} - -void SwitchLabel() : -{} -{ - "case" Expression() ":" -| - "default" ":" -} - -void IfStatement() : -/* - * The disambiguating algorithm of JavaCC automatically binds dangling - * else's to the innermost if statement. The LOOKAHEAD specification - * is to tell JavaCC that we know what we are doing. - */ -{} -{ - "if" "(" Expression() ")" Statement() [ LOOKAHEAD(1) "else" Statement() ] -} - -void WhileStatement() : -{} -{ - "while" "(" Expression() ")" Statement() -} - -void DoStatement() : -{} -{ - "do" Statement() "while" "(" Expression() ")" ";" -} - -void ForStatement() : -{} -{ - "for" "(" [ ForInit() ] ";" [ Expression() ] ";" [ ForUpdate() ] ")" Statement() -} - -void ForInit() : -{} -{ - LOOKAHEAD( [ "final" ] Type() ) - LocalVariableDeclaration() -| - StatementExpressionList() -} - -void StatementExpressionList() : -{} -{ - StatementExpression() ( "," StatementExpression() )* -} - -void ForUpdate() : -{} -{ - StatementExpressionList() -} - -void BreakStatement() : -{} -{ - "break" [ ] ";" -} - -void ContinueStatement() : -{} -{ - "continue" [ ] ";" -} - -void ReturnStatement() : -{} -{ - "return" [ Expression() ] ";" -} - -void ThrowStatement() : -{} -{ - "throw" Expression() ";" -} - -void SynchronizedStatement() : -{} -{ - "synchronized" "(" Expression() ")" Block() -} - -void TryStatement() : -/* - * Semantic check required here to make sure that at least one - * finally/catch is present. - */ -{} -{ - "try" Block() - ( "catch" "(" FormalParameter() ")" Block() )* - [ "finally" Block() ] -} diff --git a/src/main/java/com/helger/pgcc/jjdoc/BNFGenerator.java b/src/main/java/com/helger/pgcc/jjdoc/BNFGenerator.java index eaa992faf..2d1fb11ce 100644 --- a/src/main/java/com/helger/pgcc/jjdoc/BNFGenerator.java +++ b/src/main/java/com/helger/pgcc/jjdoc/BNFGenerator.java @@ -38,7 +38,6 @@ import java.util.HashMap; import java.util.Map; -import com.helger.pgcc.parser.CodeProductionCpp; import com.helger.pgcc.parser.CodeProductionJava; import com.helger.pgcc.parser.NormalProduction; import com.helger.pgcc.parser.TokenProduction; @@ -108,9 +107,6 @@ public void tokensEnd () public void javacode (final CodeProductionJava jp) {} - public void cppcode (final CodeProductionCpp cp) - {} - public void expansionEnd (final Expansion e, final boolean first) {} diff --git a/src/main/java/com/helger/pgcc/jjdoc/HTMLGenerator.java b/src/main/java/com/helger/pgcc/jjdoc/HTMLGenerator.java index 62fd70802..5d1052a97 100644 --- a/src/main/java/com/helger/pgcc/jjdoc/HTMLGenerator.java +++ b/src/main/java/com/helger/pgcc/jjdoc/HTMLGenerator.java @@ -40,7 +40,6 @@ import javax.annotation.Nonnull; import com.helger.commons.string.StringHelper; -import com.helger.pgcc.parser.CodeProductionCpp; import com.helger.pgcc.parser.CodeProductionJava; import com.helger.pgcc.parser.NormalProduction; import com.helger.pgcc.parser.TokenProduction; @@ -192,14 +191,6 @@ public void javacode (final CodeProductionJava jp) throws IOException productionEnd (jp); } - @Override - public void cppcode (final CodeProductionCpp cp) throws IOException - { - productionStart (cp); - _println ("cpp code"); - productionEnd (cp); - } - @Override public void productionStart (final NormalProduction np) throws IOException { diff --git a/src/main/java/com/helger/pgcc/jjdoc/IDocGenerator.java b/src/main/java/com/helger/pgcc/jjdoc/IDocGenerator.java index 12bd4ce6e..36062778e 100644 --- a/src/main/java/com/helger/pgcc/jjdoc/IDocGenerator.java +++ b/src/main/java/com/helger/pgcc/jjdoc/IDocGenerator.java @@ -37,7 +37,6 @@ import java.io.Serializable; import com.helger.commons.ValueEnforcer; -import com.helger.pgcc.parser.CodeProductionCpp; import com.helger.pgcc.parser.CodeProductionJava; import com.helger.pgcc.parser.NormalProduction; import com.helger.pgcc.parser.TokenProduction; @@ -75,7 +74,7 @@ public interface IDocGenerator extends Serializable /** * Output document header. - * + * * @throws IOException * on IO error */ @@ -83,7 +82,7 @@ public interface IDocGenerator extends Serializable /** * Output document footer. - * + * * @throws IOException * on IO error */ @@ -115,7 +114,7 @@ public interface IDocGenerator extends Serializable /** * Output start of non-terminal. - * + * * @throws IOException * on IO error */ @@ -123,7 +122,7 @@ public interface IDocGenerator extends Serializable /** * Output end of non-terminal. - * + * * @throws IOException * on IO error */ @@ -131,7 +130,7 @@ public interface IDocGenerator extends Serializable /** * Output start of tokens. - * + * * @throws IOException * on IO error */ @@ -139,7 +138,7 @@ public interface IDocGenerator extends Serializable /** * Output end of tokens. - * + * * @throws IOException * on IO error */ @@ -155,16 +154,6 @@ public interface IDocGenerator extends Serializable */ void javacode (CodeProductionJava jp) throws IOException; - /** - * Output comment from a production. - * - * @param cp - * the CppCodeProduction to output - * @throws IOException - * on IO error - */ - void cppcode (CodeProductionCpp cp) throws IOException; - /** * Output start of a normal production. * diff --git a/src/main/java/com/helger/pgcc/jjdoc/JJDoc.java b/src/main/java/com/helger/pgcc/jjdoc/JJDoc.java index 739766f64..830f3f161 100644 --- a/src/main/java/com/helger/pgcc/jjdoc/JJDoc.java +++ b/src/main/java/com/helger/pgcc/jjdoc/JJDoc.java @@ -40,7 +40,6 @@ import com.helger.commons.string.StringHelper; import com.helger.pgcc.PGPrinter; import com.helger.pgcc.parser.BNFProduction; -import com.helger.pgcc.parser.CodeProductionCpp; import com.helger.pgcc.parser.CodeProductionJava; import com.helger.pgcc.parser.JavaCCGlobals; import com.helger.pgcc.parser.NormalProduction; @@ -203,15 +202,10 @@ private static void _emitNormalProductions (final IDocGenerator gen, final List gen.productionEnd (np); } else - if (np instanceof CodeProductionCpp) + if (np instanceof CodeProductionJava) { - gen.cppcode ((CodeProductionCpp) np); + gen.javacode ((CodeProductionJava) np); } - else - if (np instanceof CodeProductionJava) - { - gen.javacode ((CodeProductionJava) np); - } } gen.nonterminalsEnd (); } diff --git a/src/main/java/com/helger/pgcc/jjdoc/TextGenerator.java b/src/main/java/com/helger/pgcc/jjdoc/TextGenerator.java index 32ff877ac..7d0f0dcda 100644 --- a/src/main/java/com/helger/pgcc/jjdoc/TextGenerator.java +++ b/src/main/java/com/helger/pgcc/jjdoc/TextGenerator.java @@ -43,7 +43,6 @@ import com.helger.commons.io.file.FileHelper; import com.helger.commons.string.StringHelper; import com.helger.pgcc.PGPrinter; -import com.helger.pgcc.parser.CodeProductionCpp; import com.helger.pgcc.parser.CodeProductionJava; import com.helger.pgcc.parser.NormalProduction; import com.helger.pgcc.parser.Options; @@ -118,13 +117,6 @@ public void javacode (final CodeProductionJava jp) throws IOException productionEnd (jp); } - public void cppcode (final CodeProductionCpp cp) throws IOException - { - productionStart (cp); - text ("c++ code"); - productionEnd (cp); - } - public void productionStart (final NormalProduction np) throws IOException { m_aPW.write ("\t" + np.getLhs () + "\t:=\t"); diff --git a/src/main/java/com/helger/pgcc/jjdoc/XTextGenerator.java b/src/main/java/com/helger/pgcc/jjdoc/XTextGenerator.java index 3d68fe370..55910421b 100644 --- a/src/main/java/com/helger/pgcc/jjdoc/XTextGenerator.java +++ b/src/main/java/com/helger/pgcc/jjdoc/XTextGenerator.java @@ -36,7 +36,6 @@ import java.io.IOException; import java.io.Writer; -import com.helger.pgcc.parser.CodeProductionCpp; import com.helger.pgcc.parser.CodeProductionJava; import com.helger.pgcc.parser.NormalProduction; import com.helger.pgcc.parser.RegExprSpec; @@ -125,9 +124,6 @@ public void tokensEnd () public void javacode (final CodeProductionJava jp) {} - public void cppcode (final CodeProductionCpp cp) - {} - public void productionStart (final NormalProduction np) {} diff --git a/src/main/java/com/helger/pgcc/jjtree/ASTGrammar.java b/src/main/java/com/helger/pgcc/jjtree/ASTGrammar.java index 97b3ba212..b4c2a8813 100644 --- a/src/main/java/com/helger/pgcc/jjtree/ASTGrammar.java +++ b/src/main/java/com/helger/pgcc/jjtree/ASTGrammar.java @@ -64,11 +64,6 @@ package com.helger.pgcc.jjtree; -import com.helger.pgcc.PGPrinter; -import com.helger.pgcc.jjtree.output.NodeFilesCpp; -import com.helger.pgcc.output.UnsupportedOutputLanguageException; -import com.helger.pgcc.parser.Options; - public class ASTGrammar extends JJTreeNode { ASTGrammar (final int nID) @@ -78,22 +73,9 @@ public class ASTGrammar extends JJTreeNode void generate (final JJTreeIO io) { - PGPrinter.info ("opt:" + Options.getOutputLanguage ().getID ()); // TODO :: CBA -- Require Unification of output language specific processing // into a single Enum class - switch (Options.getOutputLanguage ()) - { - case JAVA: - new CodeGeneratorJava ().visit (this, io); - break; - case CPP: - new CodeGeneratorCpp ().visit (this, io); - NodeFilesCpp.generateTreeClasses (); - break; - default: - // Catch all to ensure we don't accidently do nothing - throw new UnsupportedOutputLanguageException (Options.getOutputLanguage ()); - } + new CodeGeneratorJava ().visit (this, io); } /** Accept the visitor. **/ diff --git a/src/main/java/com/helger/pgcc/jjtree/CodeGeneratorCpp.java b/src/main/java/com/helger/pgcc/jjtree/CodeGeneratorCpp.java deleted file mode 100644 index 033b68d59..000000000 --- a/src/main/java/com/helger/pgcc/jjtree/CodeGeneratorCpp.java +++ /dev/null @@ -1,512 +0,0 @@ -/* - * 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. - */ -// Copyright 2011 Google Inc. All Rights Reserved. -// Author: sreeni@google.com (Sreeni Viswanadha) - -package com.helger.pgcc.jjtree; - -import java.io.File; -import java.util.LinkedHashMap; -import java.util.Map; - -import com.helger.pgcc.jjtree.output.NodeFilesCpp; -import com.helger.pgcc.parser.JavaCCGlobals; -import com.helger.pgcc.parser.Options; - -public class CodeGeneratorCpp extends DefaultJJTreeVisitor -{ - @Override - public Object defaultVisit (final SimpleNode node, final Object data) - { - visit ((JJTreeNode) node, data); - return null; - } - - @Override - public Object visit (final ASTGrammar node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - io.println ("/*@bgen(jjtree) " + - JavaCCGlobals.getIdString (JJTreeGlobals.toolList, new File (io.getOutputFilename ()).getName ()) + - (Options.booleanValue (Options.USEROPTION__CPP_IGNORE_ACTIONS) ? "" : " */")); - io.print ((Options.booleanValue (Options.USEROPTION__CPP_IGNORE_ACTIONS) ? "" : "/*") + "@egen*/"); - - return node.childrenAccept (this, io); - } - - @Override - public Object visit (final ASTBNFAction node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - /* - * Assume that this action requires an early node close, and then try to - * decide whether this assumption is false. Do this by looking outwards - * through the enclosing expansion units. If we ever find that we are - * enclosed in a unit which is not the final unit in a sequence we know that - * an early close is not required. - */ - - final NodeScope ns = NodeScope.getEnclosingNodeScope (node); - if (ns != null && !ns.isVoid ()) - { - boolean needClose = true; - final Node sp = node.getScopingParent (ns); - - JJTreeNode n = node; - while (true) - { - final Node p = n.jjtGetParent (); - if (p instanceof ASTBNFSequence || p instanceof ASTBNFTryBlock) - { - if (n.getOrdinal () != p.jjtGetNumChildren () - 1) - { - /* We're not the final unit in the sequence. */ - needClose = false; - break; - } - } - else - if (p instanceof ASTBNFZeroOrOne || p instanceof ASTBNFZeroOrMore || p instanceof ASTBNFOneOrMore) - { - needClose = false; - break; - } - if (p == sp) - { - /* No more parents to look at. */ - break; - } - n = (JJTreeNode) p; - } - if (needClose) - { - openJJTreeComment (io, null); - io.println (); - insertCloseNodeAction (ns, io, getIndentation (node)); - closeJJTreeComment (io); - } - } - - return visit ((JJTreeNode) node, io); - } - - @Override - public Object visit (final ASTBNFDeclaration node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - if (!node.m_node_scope.isVoid ()) - { - String indent = ""; - if (TokenUtils.hasTokens (node)) - { - for (int i = 1; i < node.getFirstToken ().beginColumn; ++i) - { - indent += " "; - } - } - else - { - indent = " "; - } - - openJJTreeComment (io, node.m_node_scope.getNodeDescriptorText ()); - io.println (); - insertOpenNodeCode (node.m_node_scope, io, indent); - closeJJTreeComment (io); - } - - return visit ((JJTreeNode) node, io); - } - - @Override - public Object visit (final ASTBNFNodeScope node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - if (node.m_node_scope.isVoid ()) - { - return visit ((JJTreeNode) node, io); - } - - final String indent = getIndentation (node.m_expansion_unit); - - openJJTreeComment (io, node.m_node_scope.getNodeDescriptor ().getDescriptor ()); - io.println (); - tryExpansionUnit (node.m_node_scope, io, indent, node.m_expansion_unit); - return null; - } - - @Override - public Object visit (final ASTCompilationUnit node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - Token t = node.getFirstToken (); - while (true) - { - node.print (t, io); - if (t == node.getLastToken ()) - break; - if (t.kind == JJTreeParserConstants._PARSER_BEGIN) - { - // eat PARSER_BEGIN "(" ")" - node.print (t.next, io); - node.print (t.next.next, io); - node.print (t = t.next.next.next, io); - } - - t = t.next; - } - return null; - } - - @Override - public Object visit (final ASTExpansionNodeScope node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - final String indent = getIndentation (node.m_expansion_unit); - openJJTreeComment (io, node.m_node_scope.getNodeDescriptor ().getDescriptor ()); - io.println (); - insertOpenNodeAction (node.m_node_scope, io, indent); - tryExpansionUnit (node.m_node_scope, io, indent, node.m_expansion_unit); - - // Print the "whiteOut" equivalent of the Node descriptor to preserve - // line numbers in the generated file. - ((ASTNodeDescriptor) node.jjtGetChild (1)).jjtAccept (this, io); - return null; - } - - @Override - public Object visit (final ASTJavacodeBody node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - if (node.m_node_scope.isVoid ()) - { - return visit ((JJTreeNode) node, io); - } - - final Token first = node.getFirstToken (); - - String indent = ""; - for (int i = 4; i < first.beginColumn; ++i) - { - indent += " "; - } - - openJJTreeComment (io, node.m_node_scope.getNodeDescriptorText ()); - io.println (); - insertOpenNodeCode (node.m_node_scope, io, indent); - tryTokenSequence (node.m_node_scope, io, indent, first, node.getLastToken ()); - return null; - } - - public Object visit (final ASTLHS node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - final NodeScope ns = NodeScope.getEnclosingNodeScope (node); - - /* - * Print out all the tokens, converting all references to `jjtThis' into the - * current node variable. - */ - final Token first = node.getFirstToken (); - final Token last = node.getLastToken (); - for (Token t = first; t != last.next; t = t.next) - { - TokenUtils.print (t, io, "jjtThis", ns.getNodeVariable ()); - } - - return null; - } - - /* - * This method prints the tokens corresponding to this node recursively - * calling the print methods of its children. Overriding this print method in - * appropriate nodes gives the output the added stuff not in the input. - */ - - public Object visit (final JJTreeNode node, final Object data) - { - final JJTreeIO io = (JJTreeIO) data; - /* - * Some productions do not consume any tokens. In that case their first and - * last tokens are a bit strange. - */ - if (node.getLastToken ().next == node.getFirstToken ()) - { - return null; - } - - final Token t1 = node.getFirstToken (); - Token t = new Token (); - t.next = t1; - JJTreeNode n; - for (int ord = 0; ord < node.jjtGetNumChildren (); ord++) - { - n = (JJTreeNode) node.jjtGetChild (ord); - while (true) - { - t = t.next; - if (t == n.getFirstToken ()) - break; - node.print (t, io); - } - n.jjtAccept (this, io); - t = n.getLastToken (); - } - while (t != node.getLastToken ()) - { - t = t.next; - node.print (t, io); - } - - return null; - } - - static void openJJTreeComment (final JJTreeIO io, final String arg) - { - if (arg != null) - { - io.print ("/*@bgen(jjtree) " + arg + (Options.booleanValue (Options.USEROPTION__CPP_IGNORE_ACTIONS) ? "" : " */")); - } - else - { - io.print ("/*@bgen(jjtree)" + (Options.booleanValue (Options.USEROPTION__CPP_IGNORE_ACTIONS) ? "" : "*/")); - } - } - - static void closeJJTreeComment (final JJTreeIO io) - { - io.print ((Options.booleanValue (Options.USEROPTION__CPP_IGNORE_ACTIONS) ? "" : "/*") + "@egen*/"); - } - - String getIndentation (final JJTreeNode n) - { - return getIndentation (n, 0); - } - - String getIndentation (final JJTreeNode n, final int offset) - { - String s = ""; - for (int i = offset + 1; i < n.getFirstToken ().beginColumn; ++i) - { - s += " "; - } - return s; - } - - void insertOpenNodeDeclaration (final NodeScope ns, final JJTreeIO io, final String indent) - { - insertOpenNodeCode (ns, io, indent); - } - - void insertOpenNodeCode (final NodeScope ns, final JJTreeIO io, final String indent) - { - final String type = ns.m_node_descriptor.getNodeType (); - final String nodeClass; - if (JJTreeOptions.getNodeClass ().length () > 0 && !JJTreeOptions.isMulti ()) - { - nodeClass = JJTreeOptions.getNodeClass (); - } - else - { - nodeClass = type; - } - - NodeFilesCpp.addType (type); - - io.print (indent + nodeClass + " *" + ns.m_nodeVar + " = "); - final String parserArg = JJTreeOptions.isNodeUsesParser () ? ("this, ") : ""; - - if (JJTreeOptions.getNodeFactory ().equals ("*")) - { - // Old-style multiple-implementations. - io.println ("(" + nodeClass + "*)" + nodeClass + "::jjtCreate(" + parserArg + ns.m_node_descriptor.getNodeId () + ");"); - } - else - if (JJTreeOptions.getNodeFactory ().length () > 0) - { - io.println ("(" + nodeClass + "*)nodeFactory->jjtCreate(" + parserArg + ns.m_node_descriptor.getNodeId () + ");"); - } - else - { - io.println ("new " + nodeClass + "(" + parserArg + ns.m_node_descriptor.getNodeId () + ");"); - } - - if (ns.usesCloseNodeVar ()) - { - io.println (indent + "bool " + ns.m_closedVar + " = true;"); - } - io.println (indent + ns.m_node_descriptor.openNode (ns.m_nodeVar)); - if (JJTreeOptions.isNodeScopeHook ()) - { - io.println (indent + "jjtreeOpenNodeScope(" + ns.m_nodeVar + ");"); - } - - if (JJTreeOptions.isTrackTokens ()) - { - io.println (indent + ns.m_nodeVar + "->jjtSetFirstToken(getToken(1));"); - } - } - - void insertCloseNodeCode (final NodeScope ns, final JJTreeIO io, final String indent, final boolean isFinal) - { - final String closeNode = ns.m_node_descriptor.closeNode (ns.m_nodeVar); - io.println (indent + closeNode); - if (ns.usesCloseNodeVar () && !isFinal) - { - io.println (indent + ns.m_closedVar + " = false;"); - } - if (JJTreeOptions.isNodeScopeHook ()) - { - io.println (indent + "if (jjtree.nodeCreated()) {"); - io.println (indent + " jjtreeCloseNodeScope(" + ns.m_nodeVar + ");"); - io.println (indent + "}"); - } - - if (JJTreeOptions.isTrackTokens ()) - { - io.println (indent + ns.m_nodeVar + "->jjtSetLastToken(getToken(0));"); - } - } - - void insertOpenNodeAction (final NodeScope ns, final JJTreeIO io, final String indent) - { - io.println (indent + "{"); - insertOpenNodeCode (ns, io, indent + " "); - io.println (indent + "}"); - } - - void insertCloseNodeAction (final NodeScope ns, final JJTreeIO io, final String indent) - { - io.println (indent + "{"); - insertCloseNodeCode (ns, io, indent + " ", false); - io.println (indent + "}"); - } - - private void insertCatchBlocks (final NodeScope ns, final JJTreeIO io, final String indent) - { - // if (thrown_names.hasMoreElements()) { - io.println (indent + "} catch (...) {"); // " + ns.exceptionVar + ") {"); - - if (ns.usesCloseNodeVar ()) - { - io.println (indent + " if (" + ns.m_closedVar + ") {"); - io.println (indent + " jjtree.clearNodeScope(" + ns.m_nodeVar + ");"); - io.println (indent + " " + ns.m_closedVar + " = false;"); - io.println (indent + " } else {"); - io.println (indent + " jjtree.popNode();"); - io.println (indent + " }"); - } - // } - - } - - void tryTokenSequence (final NodeScope ns, final JJTreeIO io, final String indent, final Token first, final Token last) - { - io.println (indent + "try {"); - closeJJTreeComment (io); - - /* - * Print out all the tokens, converting all references to `jjtThis' into the - * current node variable. - */ - for (Token t = first; t != last.next; t = t.next) - { - TokenUtils.print (t, io, "jjtThis", ns.m_nodeVar); - } - - openJJTreeComment (io, null); - io.println (); - - insertCatchBlocks (ns, io, indent); - - io.println (indent + "} {"); - if (ns.usesCloseNodeVar ()) - { - io.println (indent + " if (" + ns.m_closedVar + ") {"); - insertCloseNodeCode (ns, io, indent + " ", true); - io.println (indent + " }"); - } - io.println (indent + "}"); - closeJJTreeComment (io); - } - - private static void findThrown (final NodeScope ns, final Map thrown_set, final JJTreeNode expansion_unit) - { - if (expansion_unit instanceof ASTBNFNonTerminal) - { - /* - * Should really make the nonterminal explicitly maintain its name. - */ - final String nt = expansion_unit.getFirstToken ().image; - final ASTProduction prod = JJTreeGlobals.s_productions.get (nt); - if (prod != null) - { - for (final String t : prod.m_throws_list) - thrown_set.put (t, t); - } - } - for (int i = 0; i < expansion_unit.jjtGetNumChildren (); ++i) - { - final JJTreeNode n = (JJTreeNode) expansion_unit.jjtGetChild (i); - findThrown (ns, thrown_set, n); - } - } - - void tryExpansionUnit (final NodeScope ns, final JJTreeIO io, final String indent, final JJTreeNode expansion_unit) - { - io.println (indent + "try {"); - closeJJTreeComment (io); - - expansion_unit.jjtAccept (this, io); - - openJJTreeComment (io, null); - io.println (); - - // Maintain order - final Map thrown_set = new LinkedHashMap <> (); - findThrown (ns, thrown_set, expansion_unit); - insertCatchBlocks (ns, io, indent); - - io.println (indent + "} {"); - if (ns.usesCloseNodeVar ()) - { - io.println (indent + " if (" + ns.m_closedVar + ") {"); - insertCloseNodeCode (ns, io, indent + " ", true); - io.println (indent + " }"); - } - io.println (indent + "}"); - closeJJTreeComment (io); - } - -} diff --git a/src/main/java/com/helger/pgcc/jjtree/JJTree.java b/src/main/java/com/helger/pgcc/jjtree/JJTree.java index 14908cae4..7b1a58752 100644 --- a/src/main/java/com/helger/pgcc/jjtree/JJTree.java +++ b/src/main/java/com/helger/pgcc/jjtree/JJTree.java @@ -70,9 +70,7 @@ import com.helger.commons.state.ESuccess; import com.helger.pgcc.PGPrinter; -import com.helger.pgcc.jjtree.output.JJTreeStateCpp; import com.helger.pgcc.jjtree.output.JJTreeStateJava; -import com.helger.pgcc.jjtree.output.NodeFilesCpp; import com.helger.pgcc.jjtree.output.NodeFilesJava; import com.helger.pgcc.parser.JavaCCGlobals; import com.helger.pgcc.parser.Options; @@ -225,23 +223,10 @@ public ESuccess main (final String [] args) // TODO :: Not yet tested this in GWT/Modern mode (disabled by default // in 6.1) - switch (Options.getOutputLanguage ()) - { - case JAVA: - NodeFilesJava.generateTreeConstants_java (); - NodeFilesJava.generateVisitor_java (); - NodeFilesJava.generateDefaultVisitor_java (); - JJTreeStateJava.generateTreeState_java (); - break; - case CPP: - NodeFilesCpp.generateTreeConstants (); - NodeFilesCpp.generateVisitors (); - JJTreeStateCpp.generateTreeState (); - break; - default: - PGPrinter.info ("Unsupported JJTree output language : " + Options.getOutputLanguage ()); - return ESuccess.FAILURE; - } + NodeFilesJava.generateTreeConstants_java (); + NodeFilesJava.generateVisitor_java (); + NodeFilesJava.generateDefaultVisitor_java (); + JJTreeStateJava.generateTreeState_java (); PGPrinter.info ("Annotated grammar generated successfully in " + io.getOutputFilename ()); return ESuccess.SUCCESS; diff --git a/src/main/java/com/helger/pgcc/jjtree/JJTreeOptions.java b/src/main/java/com/helger/pgcc/jjtree/JJTreeOptions.java index ac5815ec4..1a2057aed 100644 --- a/src/main/java/com/helger/pgcc/jjtree/JJTreeOptions.java +++ b/src/main/java/com/helger/pgcc/jjtree/JJTreeOptions.java @@ -116,12 +116,6 @@ public static void init () // TODO :: 2013/07/23 -- This appears to be a duplicate from the parent // class Options.s_optionValues.put (Options.USEROPTION__JDK_VERSION, EJDKVersion.DEFAULT); - - // Also appears to be a duplicate - Options.s_optionValues.put (Options.USEROPTION__CPP_NAMESPACE, ""); - - // Also appears to be a duplicate - Options.s_optionValues.put (Options.USEROPTION__CPP_IGNORE_ACTIONS, Boolean.FALSE); } /** diff --git a/src/main/java/com/helger/pgcc/jjtree/output/JJTreeStateCpp.java b/src/main/java/com/helger/pgcc/jjtree/output/JJTreeStateCpp.java deleted file mode 100644 index 453f2a5d0..000000000 --- a/src/main/java/com/helger/pgcc/jjtree/output/JJTreeStateCpp.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - */ -// Copyright 2011 Google Inc. All Rights Reserved. -// Author: sreeni@google.com (Sreeni Viswanadha) - -package com.helger.pgcc.jjtree.output; - -import java.io.File; -import java.io.IOException; -import java.util.Map; - -import javax.annotation.concurrent.Immutable; - -import com.helger.commons.collection.ArrayHelper; -import com.helger.pgcc.PGVersion; -import com.helger.pgcc.jjtree.JJTreeGlobals; -import com.helger.pgcc.jjtree.JJTreeOptions; -import com.helger.pgcc.output.OutputFile; -import com.helger.pgcc.parser.Options; - -/** - * Generate the State of a tree. - */ -@Immutable -public final class JJTreeStateCpp -{ - private static final String JJTStateVersion = PGVersion.MAJOR_DOT_MINOR; - - private JJTreeStateCpp () - {} - - public static void generateTreeState () throws IOException - { - final Map aOptions = Options.getAllOptions (); - aOptions.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - - final String sFilePrefix = new File (JJTreeOptions.getJJTreeOutputDirectory (), - "JJT" + JJTreeGlobals.s_parserName + "State").getAbsolutePath (); - - OutputFile aOutputFile = new OutputFile (new File (sFilePrefix + ".h"), JJTStateVersion, ArrayHelper.EMPTY_STRING_ARRAY); - NodeFilesCpp.generateFile (aOutputFile, "/templates/jjtree/cpp/JJTTreeState.h.template", aOptions, true); - - aOutputFile = new OutputFile (new File (sFilePrefix + ".cc"), JJTStateVersion, ArrayHelper.EMPTY_STRING_ARRAY); - NodeFilesCpp.generateFile (aOutputFile, "/templates/jjtree/cpp/JJTTreeState.cc.template", aOptions, true); - } -} diff --git a/src/main/java/com/helger/pgcc/jjtree/output/NodeFilesCpp.java b/src/main/java/com/helger/pgcc/jjtree/output/NodeFilesCpp.java deleted file mode 100644 index cac5c8796..000000000 --- a/src/main/java/com/helger/pgcc/jjtree/output/NodeFilesCpp.java +++ /dev/null @@ -1,708 +0,0 @@ -/* - * 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. - */ -// 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.jjtree.output; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.UncheckedIOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.concurrent.Immutable; - -import com.helger.commons.string.StringHelper; -import com.helger.pgcc.PGVersion; -import com.helger.pgcc.jjtree.ASTNodeDescriptor; -import com.helger.pgcc.jjtree.JJTreeGlobals; -import com.helger.pgcc.jjtree.JJTreeOptions; -import com.helger.pgcc.output.OutputFile; -import com.helger.pgcc.output.cpp.OtherFilesGenCPP; -import com.helger.pgcc.parser.Options; -import com.helger.pgcc.utils.OutputFileGenerator; - -@Immutable -public final class NodeFilesCpp -{ - private NodeFilesCpp () - {} - - private static final List s_headersForJJTreeH = new ArrayList <> (); - /** - * ID of the latest version (of JJTree) in which one of the Node classes was - * modified. - */ - private static final String s_nodeVersion = PGVersion.MAJOR_DOT_MINOR; - - private static final Set s_nodesToGenerate = new HashSet <> (); - - public static void addType (@Nonnull final String type) - { - if (!type.equals ("Node") && !type.equals ("SimpleNode")) - { - s_nodesToGenerate.add (type); - } - } - - public static String nodeIncludeFile () - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), "Node.h").getAbsolutePath (); - } - - public static String simpleNodeIncludeFile () - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), "SimpleNode.h").getAbsolutePath (); - } - - public static String simpleNodeCodeFile () - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), "SimpleNode.cc").getAbsolutePath (); - } - - public static String jjtreeIncludeFile () - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), JJTreeGlobals.s_parserName + "Tree.h").getAbsolutePath (); - } - - public static String jjtreeImplFile () - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), JJTreeGlobals.s_parserName + "Tree.cc").getAbsolutePath (); - } - - public static String jjtreeIncludeFile (final String s) - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), s + ".h").getAbsolutePath (); - } - - public static String jjtreeImplFile (final String s) - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), s + ".cc").getAbsolutePath (); - } - - public static String jjtreeASTIncludeFile (final String ASTNode) - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), ASTNode + ".h").getAbsolutePath (); - } - - public static String jjtreeASTCodeFile (final String ASTNode) - { - return new File (JJTreeOptions.getJJTreeOutputDirectory (), ASTNode + ".cc").getAbsolutePath (); - } - - private static String _getVisitorIncludeFile () - { - final String name = getVisitorClass (); - return new File (JJTreeOptions.getJJTreeOutputDirectory (), name + ".h").getAbsolutePath (); - } - - public static void generateTreeClasses () - { - _generateNodeHeader (); - _generateSimpleNodeHeader (); - _generateSimpleNodeCode (); - _generateMultiTreeInterface (); - _generateMultiTreeImpl (); - _generateOneTreeInterface (); - if (false) - _generateOneTreeImpl (); - } - - private static void _generateNodeHeader () - { - final File aFile = new File (nodeIncludeFile ()); - - final String [] aOptions = new String [] { "MULTI", - "NODE_USES_PARSER", - "VISITOR", - "TRACK_TOKENS", - "NODE_PREFIX", - "NODE_EXTENDS", - "NODE_FACTORY", - Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - - try (final OutputFile aOutputFile = new OutputFile (aFile, s_nodeVersion, aOptions)) - { - aOutputFile.setToolName ("JJTree"); - - if (aFile.exists () && !aOutputFile.needToWrite ()) - return; - - final Map aOptionMap = Options.getAllOptions (); - aOptionMap.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - aOptionMap.put ("VISITOR_RETURN_TYPE", _getVisitorReturnType ()); - aOptionMap.put ("VISITOR_DATA_TYPE", _getVisitorArgumentType ()); - aOptionMap.put ("VISITOR_RETURN_TYPE_VOID", Boolean.valueOf (_getVisitorReturnType ().equals ("void"))); - - generateFile (aOutputFile, "/templates/jjtree/cpp/Node.h.template", aOptionMap, false); - } - catch (final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - private static void _generateSimpleNodeHeader () - { - final File aFile = new File (simpleNodeIncludeFile ()); - - final String [] aOptions = new String [] { "MULTI", - "NODE_USES_PARSER", - "VISITOR", - "TRACK_TOKENS", - "NODE_PREFIX", - "NODE_EXTENDS", - "NODE_FACTORY", - Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - - try (final OutputFile aOutputFile = new OutputFile (aFile, s_nodeVersion, aOptions)) - { - aOutputFile.setToolName ("JJTree"); - - if (aFile.exists () && !aOutputFile.needToWrite ()) - return; - - final Map aOptionMap = Options.getAllOptions (); - aOptionMap.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - aOptionMap.put ("VISITOR_RETURN_TYPE", _getVisitorReturnType ()); - aOptionMap.put ("VISITOR_DATA_TYPE", _getVisitorArgumentType ()); - aOptionMap.put ("VISITOR_RETURN_TYPE_VOID", Boolean.valueOf (_getVisitorReturnType ().equals ("void"))); - - generateFile (aOutputFile, "/templates/jjtree/cpp/SimpleNode.h.template", aOptionMap, false); - } - catch (final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - private static void _generateSimpleNodeCode () - { - final File aFile = new File (simpleNodeCodeFile ()); - - final String [] aOptions = new String [] { "MULTI", - "NODE_USES_PARSER", - "VISITOR", - "TRACK_TOKENS", - "NODE_PREFIX", - "NODE_EXTENDS", - "NODE_FACTORY", - Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - - try (final OutputFile aOutputFile = new OutputFile (aFile, s_nodeVersion, aOptions)) - { - aOutputFile.setToolName ("JJTree"); - - if (aFile.exists () && !aOutputFile.needToWrite ()) - return; - - final Map aOptionMap = Options.getAllOptions (); - aOptionMap.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - aOptionMap.put ("VISITOR_RETURN_TYPE", _getVisitorReturnType ()); - aOptionMap.put ("VISITOR_DATA_TYPE", _getVisitorArgumentType ()); - aOptionMap.put ("VISITOR_RETURN_TYPE_VOID", Boolean.valueOf (_getVisitorReturnType ().equals ("void"))); - - generateFile (aOutputFile, "/templates/jjtree/cpp/SimpleNode.cc.template", aOptionMap, false); - } - catch (final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - private static void _generateMultiTreeInterface () - { - final String [] aOptions = new String [] { "MULTI", - "NODE_USES_PARSER", - "VISITOR", - "TRACK_TOKENS", - "NODE_PREFIX", - "NODE_EXTENDS", - "NODE_FACTORY", - Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - try - { - for (final String sNode : s_nodesToGenerate) - { - final File aFile = new File (jjtreeIncludeFile (sNode)); - try (final OutputFile aOutputFile = new OutputFile (aFile, s_nodeVersion, aOptions)) - { - aOutputFile.setToolName ("JJTree"); - - if (aFile.exists () && !aOutputFile.needToWrite ()) - return; - - final Map optionMap = Options.getAllOptions (); - optionMap.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - optionMap.put ("VISITOR_RETURN_TYPE", _getVisitorReturnType ()); - optionMap.put ("VISITOR_DATA_TYPE", _getVisitorArgumentType ()); - optionMap.put ("VISITOR_RETURN_TYPE_VOID", Boolean.valueOf (_getVisitorReturnType ().equals ("void"))); - optionMap.put ("NODE_TYPE", sNode); - - generateFile (aOutputFile, "/templates/jjtree/cpp/MultiNodeInterface.template", optionMap, false); - } - } - } - catch (final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - private static void _generateMultiTreeImpl () - { - final String [] aOptions = new String [] { "MULTI", - "NODE_USES_PARSER", - "VISITOR", - "TRACK_TOKENS", - "NODE_PREFIX", - "NODE_EXTENDS", - "NODE_FACTORY", - Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - - try - { - for (final String aString : s_nodesToGenerate) - { - final String node = aString; - final File file = new File (jjtreeImplFile (node)); - try (final OutputFile outputFile = new OutputFile (file, s_nodeVersion, aOptions)) - { - outputFile.setToolName ("JJTree"); - - if (file.exists () && !outputFile.needToWrite ()) - return; - - final Map optionMap = Options.getAllOptions (); - optionMap.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - optionMap.put ("VISITOR_RETURN_TYPE", _getVisitorReturnType ()); - optionMap.put ("VISITOR_DATA_TYPE", _getVisitorArgumentType ()); - optionMap.put ("VISITOR_RETURN_TYPE_VOID", Boolean.valueOf (_getVisitorReturnType ().equals ("void"))); - optionMap.put ("NODE_TYPE", node); - - generateFile (outputFile, "/templates/jjtree/cpp/MultiNodeImpl.template", optionMap, false); - } - } - } - catch (final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - private static void _generateOneTreeInterface () - { - final File file = new File (jjtreeIncludeFile ()); - - try - { - final String [] aOptions = new String [] { "MULTI", - "NODE_USES_PARSER", - "VISITOR", - "TRACK_TOKENS", - "NODE_PREFIX", - "NODE_EXTENDS", - "NODE_FACTORY", - Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - try (OutputFile outputFile = new OutputFile (file, s_nodeVersion, aOptions)) - { - outputFile.setToolName ("JJTree"); - - if (file.exists () && !outputFile.needToWrite ()) - return; - - final Map optionMap = Options.getAllOptions (); - optionMap.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - optionMap.put ("VISITOR_RETURN_TYPE", _getVisitorReturnType ()); - optionMap.put ("VISITOR_DATA_TYPE", _getVisitorArgumentType ()); - optionMap.put ("VISITOR_RETURN_TYPE_VOID", Boolean.valueOf (_getVisitorReturnType ().equals ("void"))); - - try (final PrintWriter ostr = outputFile.getPrintWriter ()) - { - final String includeName = file.getName ().replace ('.', '_').toUpperCase (Locale.US); - ostr.println ("#ifndef " + includeName); - ostr.println ("#define " + includeName); - ostr.println ("#include \"SimpleNode.h\""); - for (final String aString : s_nodesToGenerate) - { - final String s = aString; - ostr.println ("#include \"" + s + ".h\""); - } - ostr.println ("#endif"); - } - } - } - catch (final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - private static void _generateOneTreeImpl () - { - final File file = new File (jjtreeImplFile ()); - - final String [] aOptions = new String [] { "MULTI", - "NODE_USES_PARSER", - "VISITOR", - "TRACK_TOKENS", - "NODE_PREFIX", - "NODE_EXTENDS", - "NODE_FACTORY", - Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - - try (final OutputFile outputFile = new OutputFile (file, s_nodeVersion, aOptions)) - { - outputFile.setToolName ("JJTree"); - - if (file.exists () && !outputFile.needToWrite ()) - return; - - final Map optionMap = Options.getAllOptions (); - optionMap.put (Options.NONUSER_OPTION__PARSER_NAME, JJTreeGlobals.s_parserName); - optionMap.put ("VISITOR_RETURN_TYPE", _getVisitorReturnType ()); - optionMap.put ("VISITOR_DATA_TYPE", _getVisitorArgumentType ()); - optionMap.put ("VISITOR_RETURN_TYPE_VOID", Boolean.valueOf (_getVisitorReturnType ().equals ("void"))); - generateFile (outputFile, "/templates/jjtree/cpp/_unused_TreeImplHeader.template", optionMap, false); - - final boolean hasNamespace = Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0; - if (hasNamespace) - { - outputFile.getPrintWriter ().println ("namespace " + Options.stringValue ("NAMESPACE_OPEN")); - } - - for (final String aString : s_nodesToGenerate) - { - final String s = aString; - optionMap.put ("NODE_TYPE", s); - generateFile (outputFile, "/templates/jjtree/cpp/MultiNodeImpl.template", optionMap, false); - } - - if (hasNamespace) - { - outputFile.getPrintWriter ().println (Options.stringValue ("NAMESPACE_CLOSE")); - } - } - catch ( - - final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - static void generatePrologue () - { - // Output the node's namespace name? - } - - static String nodeConstants () - { - return JJTreeGlobals.s_parserName + "TreeConstants"; - } - - public static void generateTreeConstants () - { - final String name = nodeConstants (); - final File file = new File (JJTreeOptions.getJJTreeOutputDirectory (), name + ".h"); - s_headersForJJTreeH.add (file.getName ()); - - try (final OutputFile outputFile = new OutputFile (file)) - { - final PrintWriter ostr = outputFile.getPrintWriter (); - - final List nodeIds = ASTNodeDescriptor.getNodeIds (); - final List nodeNames = ASTNodeDescriptor.getNodeNames (); - - generatePrologue (); - ostr.println ("#ifndef " + file.getName ().replace ('.', '_').toUpperCase (Locale.US)); - ostr.println ("#define " + file.getName ().replace ('.', '_').toUpperCase (Locale.US)); - - ostr.println ("\n#include \"JavaCC.h\""); - final boolean hasNamespace = Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0; - if (hasNamespace) - { - ostr.println ("namespace " + Options.stringValue ("NAMESPACE_OPEN")); - } - ostr.println ("enum {"); - for (int i = 0; i < nodeIds.size (); ++i) - { - final String n = nodeIds.get (i); - ostr.println (" " + n + " = " + i + ","); - } - - ostr.println ("};"); - ostr.println (); - - for (int i = 0; i < nodeNames.size (); ++i) - { - ostr.println (" static JJChar jjtNodeName_arr_" + i + "[] = "); - final String n = nodeNames.get (i); - // ostr.println(" (JJChar*)\"" + n + "\","); - OtherFilesGenCPP.printCharArray (ostr, n); - ostr.println (";"); - } - ostr.println (" static JJString jjtNodeName[] = {"); - for (int i = 0; i < nodeNames.size (); i++) - { - ostr.println ("jjtNodeName_arr_" + i + ", "); - } - ostr.println (" };"); - - if (hasNamespace) - { - ostr.println (Options.stringValue ("NAMESPACE_CLOSE")); - } - - ostr.println ("#endif"); - } - catch (final IOException ex) - { - throw new UncheckedIOException (ex); - } - } - - static String getVisitorClass () - { - return JJTreeGlobals.s_parserName + "Visitor"; - } - - private static String _getVisitMethodName (final String className) - { - final StringBuilder sb = new StringBuilder ("visit"); - if (Options.booleanValue ("VISITOR_METHOD_NAME_INCLUDES_TYPE_NAME")) - { - sb.append (Character.toUpperCase (className.charAt (0))); - for (int i = 1; i < className.length (); i++) - { - sb.append (className.charAt (i)); - } - } - - return sb.toString (); - } - - private static String _getVisitorArgumentType () - { - final String ret = Options.stringValue ("VISITOR_DATA_TYPE"); - return ret == null || ret.length () == 0 || ret.equals ("Object") ? "void *" : ret; - } - - private static String _getVisitorReturnType () - { - final String ret = Options.stringValue ("VISITOR_RETURN_TYPE"); - return ret == null || ret.length () == 0 || ret.equals ("Object") ? "void " : ret; - } - - public static void generateVisitors () - { - if (!JJTreeOptions.isVisitor ()) - return; - - final File file = new File (_getVisitorIncludeFile ()); - try (final OutputFile outputFile = new OutputFile (file); final PrintWriter ostr = outputFile.getPrintWriter ()) - { - generatePrologue (); - ostr.println ("#ifndef " + file.getName ().replace ('.', '_').toUpperCase (Locale.US)); - ostr.println ("#define " + file.getName ().replace ('.', '_').toUpperCase (Locale.US)); - ostr.println ("\n#include \"JavaCC.h\""); - ostr.println ("#include \"" + JJTreeGlobals.s_parserName + "Tree.h" + "\""); - - final boolean hasNamespace = Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0; - if (hasNamespace) - { - ostr.println ("namespace " + Options.stringValue ("NAMESPACE_OPEN")); - } - - _generateVisitorInterface (ostr); - _generateDefaultVisitor (ostr); - - if (hasNamespace) - { - ostr.println (Options.stringValue ("NAMESPACE_CLOSE")); - } - - ostr.println ("#endif"); - } - catch (final IOException ioe) - { - throw new UncheckedIOException (ioe); - } - } - - private static void _generateVisitorInterface (final PrintWriter ostr) - { - final String sName = getVisitorClass (); - final List aNodeNames = ASTNodeDescriptor.getNodeNames (); - - ostr.println ("class " + sName); - ostr.println ("{"); - - String argumentType = _getVisitorArgumentType (); - final String returnType = _getVisitorReturnType (); - if (StringHelper.hasText (JJTreeOptions.getVisitorDataType ())) - argumentType = JJTreeOptions.getVisitorDataType (); - - ostr.println (" public:"); - - ostr.println (" virtual " + returnType + " visit(const SimpleNode *node, " + argumentType + " data) = 0;"); - if (JJTreeOptions.isMulti ()) - { - for (int i = 0; i < aNodeNames.size (); ++i) - { - final String n = aNodeNames.get (i); - if (n.equals ("void")) - { - continue; - } - final String nodeType = JJTreeOptions.getNodePrefix () + n; - ostr.println (" virtual " + - returnType + - " " + - _getVisitMethodName (nodeType) + - "(const " + - nodeType + - " *node, " + - argumentType + - " data) = 0;"); - } - } - - ostr.println (" virtual ~" + sName + "() { }"); - ostr.println ("};"); - } - - static String defaultVisitorClass () - { - return JJTreeGlobals.s_parserName + "DefaultVisitor"; - } - - private static void _generateDefaultVisitor (final PrintWriter ostr) - { - final String sClassName = defaultVisitorClass (); - final List aNodeNames = ASTNodeDescriptor.getNodeNames (); - - ostr.println ("class " + sClassName + " : public " + getVisitorClass () + " {"); - - final String argumentType = _getVisitorArgumentType (); - final String ret = _getVisitorReturnType (); - - ostr.println ("public:"); - ostr.println (" virtual " + ret + " defaultVisit(const SimpleNode *node, " + argumentType + " data) = 0;"); - // ostr.println(" node->childrenAccept(this, data);"); - // ostr.println(" return" + (ret.trim().equals("void") ? "" : " data") + - // ";"); - // ostr.println(" }"); - - ostr.println (" virtual " + ret + " visit(const SimpleNode *node, " + argumentType + " data) {"); - ostr.println (" " + (ret.trim ().equals ("void") ? "" : "return ") + "defaultVisit(node, data);"); - ostr.println ("}"); - - if (JJTreeOptions.isMulti ()) - { - for (int i = 0; i < aNodeNames.size (); ++i) - { - final String n = aNodeNames.get (i); - if (n.equals ("void")) - { - continue; - } - final String nodeType = JJTreeOptions.getNodePrefix () + n; - ostr.println (" virtual " + - ret + - " " + - _getVisitMethodName (nodeType) + - "(const " + - nodeType + - " *node, " + - argumentType + - " data) {"); - ostr.println (" " + (ret.trim ().equals ("void") ? "" : "return ") + "defaultVisit(node, data);"); - ostr.println (" }"); - } - } - ostr.println (" ~" + sClassName + "() { }"); - ostr.println ("};"); - } - - public static void generateFile (final OutputFile outputFile, - final String template, - final Map aOptions, - final boolean close) throws IOException - { - @SuppressWarnings ("resource") - final PrintWriter ostr = outputFile.getPrintWriter (); - generatePrologue (); - - final OutputFileGenerator aGenerator = new OutputFileGenerator (template, aOptions); - aGenerator.generate (ostr); - if (close) - ostr.close (); - } -} diff --git a/src/main/java/com/helger/pgcc/output/EOutputLanguage.java b/src/main/java/com/helger/pgcc/output/EOutputLanguage.java deleted file mode 100644 index d61a540c6..000000000 --- a/src/main/java/com/helger/pgcc/output/EOutputLanguage.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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.output; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.helger.commons.annotation.Nonempty; -import com.helger.commons.id.IHasID; -import com.helger.commons.lang.EnumHelper; - -/** - * Various constants relating to possible values for certain options - */ - -public enum EOutputLanguage implements IHasID -{ - JAVA ("java") - { - @Override - public String getTypeLong () - { - return "long"; - } - - @Override - public String getLongValueSuffix () - { - return "L"; - } - - @Override - public String getTypeBoolean () - { - return "boolean"; - } - }, - CPP ("c++") - { - @Override - public String getTypeLong () - { - return "unsigned long long"; - } - - @Override - public String getLongValueSuffix () - { - return "ULL"; - } - - @Override - public String getTypeBoolean () - { - return "bool"; - } - }; - - private final String m_sID; - - private EOutputLanguage (@Nonnull @Nonempty final String sID) - { - m_sID = sID; - } - - @Nonnull - @Nonempty - public String getID () - { - return m_sID; - } - - /** - * @return The native data type for "long" values. - */ - @Nonnull - @Nonempty - public abstract String getTypeLong (); - - /** - * @return The value suffix to be used for long values. - * @see #getTypeLong() - */ - @Nonnull - @Nonempty - protected abstract String getLongValueSuffix (); - - @Nonnull - public String getLongHex (final long n) - { - return "0x" + Long.toHexString (n) + getLongValueSuffix (); - } - - @Nonnull - public String getLongPlain (final long n) - { - return "0x" + Long.toString (n) + getLongValueSuffix (); - } - - /** - * @return The native data type for "boolean" values. - */ - @Nonnull - @Nonempty - public abstract String getTypeBoolean (); - - public boolean isJava () - { - return this == JAVA; - } - - public boolean hasStaticsFile () - { - return this == CPP; - } - - public boolean hasIncludeFile () - { - return this == CPP; - } - - @Nullable - public static EOutputLanguage getFromIDCaseInsensitiveOrNull (@Nullable final String sID) - { - return EnumHelper.getFromIDCaseInsensitiveOrNull (EOutputLanguage.class, sID); - } -} diff --git a/src/main/java/com/helger/pgcc/output/OutputHelper.java b/src/main/java/com/helger/pgcc/output/OutputHelper.java index 6d17f8a6f..a208d562b 100644 --- a/src/main/java/com/helger/pgcc/output/OutputHelper.java +++ b/src/main/java/com/helger/pgcc/output/OutputHelper.java @@ -53,8 +53,7 @@ private OutputHelper () /** * Read the version from the comment in the specified file. This method does * not try to recover from invalid comment syntax, but rather returns version - * 0.0 (which will always be taken to mean the file is out of date). Works for - * Java and CPP. + * 0.0 (which will always be taken to mean the file is out of date).. * * @param fileName * eg Token.java diff --git a/src/main/java/com/helger/pgcc/output/UnsupportedOutputLanguageException.java b/src/main/java/com/helger/pgcc/output/UnsupportedOutputLanguageException.java deleted file mode 100644 index 6c8dd2a12..000000000 --- a/src/main/java/com/helger/pgcc/output/UnsupportedOutputLanguageException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.output; - -import javax.annotation.Nonnull; - -public class UnsupportedOutputLanguageException extends RuntimeException -{ - public UnsupportedOutputLanguageException (@Nonnull final EOutputLanguage eOutputLanguage) - { - super ("Unsupported output language: " + eOutputLanguage); - } -} diff --git a/src/main/java/com/helger/pgcc/output/cpp/FilesCpp.java b/src/main/java/com/helger/pgcc/output/cpp/FilesCpp.java deleted file mode 100644 index e797470da..000000000 --- a/src/main/java/com/helger/pgcc/output/cpp/FilesCpp.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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.output.cpp; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.UncheckedIOException; - -import com.helger.pgcc.PGPrinter; -import com.helger.pgcc.PGVersion; -import com.helger.pgcc.output.OutputFile; -import com.helger.pgcc.parser.JavaCCErrors; -import com.helger.pgcc.parser.Options; -import com.helger.pgcc.utils.OutputFileGenerator; - -/** - * Generate CharStream, TokenManager and Exceptions. - */ -public class FilesCpp -{ - private FilesCpp () - {} - - private static void genFile (final String dir, final String name, final String version, final String [] parameters) - { - final File file = new File (Options.getOutputDirectory (), name); - try (final OutputFile outputFile = new OutputFile (file, version, parameters)) - { - if (!outputFile.needToWrite ()) - return; - - try (final PrintWriter ostr = outputFile.getPrintWriter ()) - { - final OutputFileGenerator generator = new OutputFileGenerator ("/templates/" + dir + "/" + name + ".template", - Options.getAllOptions ()); - generator.generate (ostr); - } - } - catch (final IOException e) - { - PGPrinter.error ("Failed to create file: " + file, e); - JavaCCErrors.semantic_error ("Could not open file: " + file + " for writing."); - throw new UncheckedIOException (e); - } - } - - public static void gen_CharStream () - { - final String [] parameters = new String [] { Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - genFile ("stream/cpp", "CharStream.h", PGVersion.MAJOR_DOT_MINOR, parameters); - genFile ("stream/cpp", "CharStream.cc", PGVersion.MAJOR_DOT_MINOR, parameters); - } - - public static void gen_ParseException () - { - final String [] parameters = new String [] { Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - genFile ("cpp", "ParseException.h", PGVersion.MAJOR_DOT_MINOR, parameters); - genFile ("cpp", "ParseException.cc", PGVersion.MAJOR_DOT_MINOR, parameters); - } - - public static void gen_TokenMgrError () - { - final String [] parameters = new String [] { Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - genFile ("cpp", "TokenMgrError.h", PGVersion.MAJOR_DOT_MINOR, parameters); - genFile ("cpp", "TokenMgrError.cc", PGVersion.MAJOR_DOT_MINOR, parameters); - } - - public static void gen_Token () - { - final String [] parameters = new String [] { Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC, - Options.USEROPTION__CPP_TOKEN_INCLUDES, - Options.USEROPTION__TOKEN_EXTENDS }; - genFile ("cpp", "Token.h", PGVersion.MAJOR_DOT_MINOR, parameters); - genFile ("cpp", "Token.cc", PGVersion.MAJOR_DOT_MINOR, parameters); - } - - public static void gen_TokenManager () - { - final String [] parameters = new String [] { Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - genFile ("cpp", "TokenManager.h", PGVersion.MAJOR_DOT_MINOR, parameters); - } - - public static void gen_JavaCCDefs () - { - final String [] parameters = new String [] { Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC }; - genFile ("cpp", "JavaCC.h", PGVersion.MAJOR_DOT_MINOR, parameters); - } - - public static void gen_ErrorHandler () - { - final String [] parameters = new String [] { Options.USEROPTION__SUPPORT_CLASS_VISIBILITY_PUBLIC, - Options.USEROPTION__BUILD_PARSER, - Options.USEROPTION__BUILD_TOKEN_MANAGER }; - genFile ("cpp", "ErrorHandler.h", PGVersion.MAJOR_DOT_MINOR, parameters); - } - - public static void reInit () - { - // empty - } -} diff --git a/src/main/java/com/helger/pgcc/output/cpp/OtherFilesGenCPP.java b/src/main/java/com/helger/pgcc/output/cpp/OtherFilesGenCPP.java deleted file mode 100644 index ea299a053..000000000 --- a/src/main/java/com/helger/pgcc/output/cpp/OtherFilesGenCPP.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * 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. - */ -// Copyright 2012 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.output.cpp; - -import static com.helger.pgcc.parser.JavaCCGlobals.getIdString; -import static com.helger.pgcc.parser.JavaCCGlobals.printToken; -import static com.helger.pgcc.parser.JavaCCGlobals.printTokenSetup; -import static com.helger.pgcc.parser.JavaCCGlobals.printTrailingComments; -import static com.helger.pgcc.parser.JavaCCGlobals.s_cu_name; -import static com.helger.pgcc.parser.JavaCCGlobals.CU_TO_INSERTION_POINT_1; -import static com.helger.pgcc.parser.JavaCCGlobals.ORDERED_NAME_TOKENS; -import static com.helger.pgcc.parser.JavaCCGlobals.REXPR_LIST; -import static com.helger.pgcc.parser.JavaCCGlobals.s_toolNames; - -import java.io.File; -import java.io.PrintWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -import com.helger.commons.io.file.FileHelper; -import com.helger.pgcc.CPG; -import com.helger.pgcc.parser.ETokenKind; -import com.helger.pgcc.parser.JavaCCErrors; -import com.helger.pgcc.parser.JavaCCParserConstants; -import com.helger.pgcc.parser.LexGenJava; -import com.helger.pgcc.parser.MetaParseException; -import com.helger.pgcc.parser.Options; -import com.helger.pgcc.parser.RegExprSpec; -import com.helger.pgcc.parser.Token; -import com.helger.pgcc.parser.TokenProduction; -import com.helger.pgcc.parser.exp.AbstractExpRegularExpression; -import com.helger.pgcc.parser.exp.ExpRStringLiteral; - -/** - * Generates the Constants file. - */ -public class OtherFilesGenCPP -{ - - // Used by the CPP code generatror - public static void printCharArray (final PrintWriter ostr, final String s) - { - ostr.print ("{ "); - for (int i = 0; i < s.length (); i++) - { - ostr.print ("0x" + Integer.toHexString (s.charAt (i)) + ", "); - } - ostr.print ("0 }"); - } - - static public void start () throws MetaParseException - { - if (JavaCCErrors.getErrorCount () != 0) - throw new MetaParseException ("Error count is already present!"); - - FilesCpp.gen_JavaCCDefs (); - FilesCpp.gen_CharStream (); - FilesCpp.gen_Token (); // TODO(theov): issued twice?? - FilesCpp.gen_TokenManager (); - FilesCpp.gen_TokenMgrError (); - FilesCpp.gen_ParseException (); - FilesCpp.gen_ErrorHandler (); - - final Writer w = FileHelper.getBufferedWriter (new File (Options.getOutputDirectory (), s_cu_name + "Constants.h"), - Options.getOutputEncoding ()); - if (w == null) - { - JavaCCErrors.semantic_error ("Could not open file " + s_cu_name + "Constants.h for writing."); - return; - } - - try (PrintWriter s_ostr = new PrintWriter (w)) - { - final List tn = new ArrayList <> (s_toolNames); - tn.add (CPG.APP_NAME); - s_ostr.println ("/* " + getIdString (tn, s_cu_name + "Constants.java") + " */"); - - if (CU_TO_INSERTION_POINT_1.size () != 0 && CU_TO_INSERTION_POINT_1.get (0).kind == JavaCCParserConstants.PACKAGE) - { - for (int i = 1; i < CU_TO_INSERTION_POINT_1.size (); i++) - { - if (CU_TO_INSERTION_POINT_1.get (i).kind == JavaCCParserConstants.SEMICOLON) - { - Token t = CU_TO_INSERTION_POINT_1.get (0); - printTokenSetup (t); - for (int j = 0; j <= i; j++) - { - t = CU_TO_INSERTION_POINT_1.get (j); - printToken (t, s_ostr); - } - printTrailingComments (t); - s_ostr.println (); - s_ostr.println (); - break; - } - } - } - s_ostr.println (""); - s_ostr.println ("/**"); - s_ostr.println (" * Token literal values and constants."); - s_ostr.println (" * Generated by " + OtherFilesGenCPP.class.getName () + "#start()"); - s_ostr.println (" */"); - - final String define = (s_cu_name + "Constants_h").toUpperCase (Locale.US); - s_ostr.println ("#ifndef " + define); - s_ostr.println ("#define " + define); - s_ostr.println ("#include \"JavaCC.h\""); - s_ostr.println (""); - if (Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0) - { - s_ostr.println ("namespace " + Options.stringValue ("NAMESPACE_OPEN")); - } - - AbstractExpRegularExpression re; - final String constPrefix = "const"; - s_ostr.println (" /** End of File. */"); - s_ostr.println (constPrefix + " int _EOF = 0;"); - for (final java.util.Iterator it = ORDERED_NAME_TOKENS.iterator (); it.hasNext ();) - { - re = it.next (); - s_ostr.println (" /** RegularExpression Id. */"); - s_ostr.println (constPrefix + " int " + re.getLabel () + " = " + re.getOrdinal () + ";"); - } - s_ostr.println (""); - - if (!Options.isUserTokenManager () && Options.isBuildTokenManager ()) - { - for (int i = 0; i < LexGenJava.s_lexStateName.length; i++) - { - s_ostr.println (" /** Lexical state. */"); - s_ostr.println (constPrefix + " int " + LexGenJava.s_lexStateName[i] + " = " + i + ";"); - } - s_ostr.println (""); - } - s_ostr.println (" /** Literal token values. */"); - int cnt = 0; - s_ostr.println (" static const JJChar tokenImage_arr_" + cnt + "[] = "); - printCharArray (s_ostr, ""); - s_ostr.println (";"); - - for (final TokenProduction tp : REXPR_LIST) - { - final List respecs = tp.m_respecs; - for (final RegExprSpec res : respecs) - { - re = res.rexp; - s_ostr.println (" static const JJChar tokenImage_arr_" + ++cnt + "[] = "); - if (re instanceof ExpRStringLiteral) - { - printCharArray (s_ostr, "\"" + ((ExpRStringLiteral) re).m_image + "\""); - } - else - if (re.hasLabel ()) - { - printCharArray (s_ostr, "\"<" + re.getLabel () + ">\""); - } - else - { - if (re.m_tpContext.m_kind == ETokenKind.TOKEN) - { - JavaCCErrors.warning (re, "Consider giving this non-string token a label for better error reporting."); - } - printCharArray (s_ostr, "\"\""); - } - s_ostr.println (";"); - } - } - - s_ostr.println (" static const JJChar* const tokenImage[] = {"); - for (int i = 0; i <= cnt; i++) - { - s_ostr.println ("tokenImage_arr_" + i + ", "); - } - s_ostr.println (" };"); - s_ostr.println (""); - if (Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0) - { - s_ostr.println (Options.stringValue ("NAMESPACE_CLOSE")); - } - s_ostr.println ("#endif"); - } - } - - public static void reInit () - { - // empty - } -} diff --git a/src/main/java/com/helger/pgcc/parser/AbstractCodeProduction.java b/src/main/java/com/helger/pgcc/parser/AbstractCodeProduction.java index cd290ca57..04317035b 100644 --- a/src/main/java/com/helger/pgcc/parser/AbstractCodeProduction.java +++ b/src/main/java/com/helger/pgcc/parser/AbstractCodeProduction.java @@ -46,7 +46,7 @@ public abstract class AbstractCodeProduction extends NormalProduction { /** - * The tokens that implement this JAVACODE/CPPCODE production. + * The tokens that implement this JAVACODE production. */ private final ICommonsList m_aCodeTokens = new CommonsArrayList <> (); diff --git a/src/main/java/com/helger/pgcc/parser/CodeGenerator.java b/src/main/java/com/helger/pgcc/parser/CodeGenerator.java index d9c0bf478..496422e13 100644 --- a/src/main/java/com/helger/pgcc/parser/CodeGenerator.java +++ b/src/main/java/com/helger/pgcc/parser/CodeGenerator.java @@ -37,13 +37,10 @@ package com.helger.pgcc.parser; import static com.helger.pgcc.parser.JavaCCGlobals.addUnicodeEscapes; -import static com.helger.pgcc.parser.JavaCCGlobals.s_cu_name; -import static com.helger.pgcc.parser.JavaCCGlobals.s_jjtreeGenerated; import java.io.File; import java.io.IOException; import java.util.List; -import java.util.Locale; import java.util.Map; import javax.annotation.Nonnull; @@ -51,15 +48,11 @@ import com.helger.commons.io.file.FileHelper; import com.helger.commons.io.stream.NonBlockingBufferedWriter; import com.helger.commons.io.stream.NonBlockingStringWriter; -import com.helger.pgcc.output.EOutputLanguage; -import com.helger.pgcc.output.UnsupportedOutputLanguageException; import com.helger.pgcc.utils.OutputFileGenerator; public class CodeGenerator { private final StringBuilder m_aMainBuffer = new StringBuilder (); - private final StringBuilder m_aIncludeBuffer = new StringBuilder (); - private final StringBuilder m_aStaticsBuffer = new StringBuilder (); private StringBuilder m_aOutputBuffer = m_aMainBuffer; private int m_nLine; @@ -68,33 +61,11 @@ public class CodeGenerator public CodeGenerator () {} - @Nonnull - public final EOutputLanguage getOutputLanguage () - { - return Options.getOutputLanguage (); - } - public final void switchToMainFile () { m_aOutputBuffer = m_aMainBuffer; } - public final void switchToStaticsFile () - { - if (getOutputLanguage ().hasStaticsFile ()) - { - m_aOutputBuffer = m_aStaticsBuffer; - } - } - - public final void switchToIncludeFile () - { - if (getOutputLanguage ().hasIncludeFile ()) - { - m_aOutputBuffer = m_aIncludeBuffer; - } - } - protected final int getCol () { return m_nCol; @@ -116,35 +87,6 @@ protected final void setLineAndCol (final int nLine, final int nCol) m_nCol = nCol; } - public final void genStringLiteralArrayCPP (final String varName, final String [] arr) - { - // First generate char array vars - for (int i = 0; i < arr.length; i++) - { - genCodeLine ("static const JJChar " + varName + "_arr_" + i + "[] = "); - genStringLiteralInCPP (arr[i]); - genCodeLine (";"); - } - - genCodeLine ("static const JJString " + varName + "[] = {"); - for (int i = 0; i < arr.length; i++) - { - genCodeLine (varName + "_arr_" + i + ", "); - } - genCodeLine ("};"); - } - - public final void genStringLiteralInCPP (final String s) - { - // String literals in CPP become char arrays - m_aOutputBuffer.append ("{"); - for (final char c : s.toCharArray ()) - { - m_aOutputBuffer.append ("0x").append (Integer.toHexString (c)).append (", "); - } - m_aOutputBuffer.append ("0}"); - } - public final void genCode (final char c) { m_aOutputBuffer.append (c); @@ -168,38 +110,6 @@ public final void genCodeLine (final String s) public final void saveOutput (final String fileName) { - if (getOutputLanguage ().hasIncludeFile ()) - { - final String incfilePath = fileName.replace (".cc", ".h"); - final String incfileName = new File (incfilePath).getName (); - - final String sDefine = incfileName.replace ('.', '_').toUpperCase (Locale.US); - m_aIncludeBuffer.insert (0, "#define " + sDefine + "\n"); - m_aIncludeBuffer.insert (0, "#ifndef " + sDefine + "\n"); - - // dump the statics into the main file with the code. - m_aMainBuffer.insert (0, m_aStaticsBuffer); - - // Finally enclose the whole thing in the namespace, if specified. - if (Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0) - { - m_aMainBuffer.insert (0, "namespace " + Options.stringValue ("NAMESPACE_OPEN") + "\n"); - m_aMainBuffer.append (Options.stringValue ("NAMESPACE_CLOSE") + "\n"); - m_aIncludeBuffer.append (Options.stringValue ("NAMESPACE_CLOSE") + "\n"); - } - - if (s_jjtreeGenerated) - { - m_aMainBuffer.insert (0, "#include \"SimpleNode.h\"\n"); - } - if (Options.isTokenManagerUsesParser ()) - m_aMainBuffer.insert (0, "#include \"" + s_cu_name + ".h\"\n"); - m_aMainBuffer.insert (0, "#include \"TokenMgrError.h\"\n"); - m_aMainBuffer.insert (0, "#include \"" + incfileName + "\"\n"); - m_aIncludeBuffer.append ("#endif\n"); - saveOutput (incfilePath, m_aIncludeBuffer); - } - m_aMainBuffer.insert (0, "/* " + new File (fileName).getName () + " */\n"); saveOutput (fileName, m_aMainBuffer); } @@ -359,19 +269,7 @@ public final String getGeneratedCode () */ public final void genAnnotation (final String ann) { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - genCode ("@" + ann); - break; - case CPP: - // For now, it's only C++ for now - genCode ("/*" + ann + "*/"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + genCode ("@" + ann); } /** @@ -382,21 +280,7 @@ public final void genAnnotation (final String ann) */ public final void genModifier (final String mod) { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - genCode (mod); - break; - case CPP: - // For now, it's only C++ for now - final String origMod = mod.trim ().toLowerCase (Locale.US); - if (origMod.equals ("public") || origMod.equals ("protected") || origMod.equals ("private")) - genCode (origMod + ": "); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + genCode (mod); } /** @@ -414,32 +298,15 @@ public final void genModifier (final String mod) */ public final void genClassStart (final String mod, final String name, final String [] superClasses, final String [] superInterfaces) { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - if (mod != null) - genModifier (mod); - genCode ("class " + name); - if (superClasses.length == 1 && superClasses[0] != null) - genCode (" extends " + superClasses[0]); - if (superInterfaces.length != 0) - genCode (" implements "); - _genCommaSeperatedString (superInterfaces); - genCodeLine (" {"); - break; - case CPP: - genCode ("class " + name); - if (superClasses.length > 0 || superInterfaces.length > 0) - genCode (" : "); - _genCommaSeperatedString (superClasses); - _genCommaSeperatedString (superInterfaces); - genCodeLine (" {"); - genCodeLine ("public:"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + if (mod != null) + genModifier (mod); + genCode ("class " + name); + if (superClasses.length == 1 && superClasses[0] != null) + genCode (" extends " + superClasses[0]); + if (superInterfaces.length != 0) + genCode (" implements "); + _genCommaSeperatedString (superInterfaces); + genCodeLine (" {"); } private void _genCommaSeperatedString (final String [] strings) @@ -462,49 +329,12 @@ public final void generateMethodDefHeader (final String sQualifiedModsAndRetType final String sNameAndParams, final String sExceptions) { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - switch (eOutputLanguage) + genCode (sQualifiedModsAndRetType + " " + sNameAndParams); + if (sExceptions != null) { - case JAVA: - genCode (sQualifiedModsAndRetType + " " + sNameAndParams); - if (sExceptions != null) - { - genCode (" throws " + sExceptions); - } - genCodeNewLine (); - break; - case CPP: - // for C++, we generate the signature in the header file and body in - // main file - m_aIncludeBuffer.append (sQualifiedModsAndRetType + " " + sNameAndParams); - // if (exceptions != null) - // includeBuffer.append(" throw(" + exceptions + ")"); - m_aIncludeBuffer.append (";\n"); - - String modsAndRetType = null; - int i = sQualifiedModsAndRetType.lastIndexOf (':'); - if (i >= 0) - modsAndRetType = sQualifiedModsAndRetType.substring (i + 1); - - if (modsAndRetType != null) - { - i = modsAndRetType.lastIndexOf ("virtual"); - if (i >= 0) - modsAndRetType = modsAndRetType.substring (i + "virtual".length ()); - } - - String sNonVirtual = sQualifiedModsAndRetType; - i = sNonVirtual.lastIndexOf ("virtual"); - if (i >= 0) - sNonVirtual = sNonVirtual.substring (i + "virtual".length ()); - m_aMainBuffer.append ("\n" + sNonVirtual + " " + getClassQualifier (sClassName) + sNameAndParams); - // if (exceptions != null) - // mainBuffer.append(" throw( " + exceptions + ")"); - switchToMainFile (); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); + genCode (" throws " + sExceptions); } + genCodeNewLine (); } protected final String getClassQualifier (final String className) @@ -512,6 +342,18 @@ protected final String getClassQualifier (final String className) return className == null ? "" : className + "::"; } + @Nonnull + public static String getLongHex (final long n) + { + return "0x" + Long.toHexString (n) + "L"; + } + + @Nonnull + public static String getLongPlain (final long n) + { + return "0x" + Long.toString (n) + "L"; + } + public static String getCharStreamName () { if (Options.isJavaUserCharStream ()) diff --git a/src/main/java/com/helger/pgcc/parser/CodeProductionCpp.java b/src/main/java/com/helger/pgcc/parser/CodeProductionCpp.java deleted file mode 100644 index 2bd4516a5..000000000 --- a/src/main/java/com/helger/pgcc/parser/CodeProductionCpp.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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; - -/** - * Describes CPPCODE productions. - */ -public class CodeProductionCpp extends AbstractCodeProduction -{} diff --git a/src/main/java/com/helger/pgcc/parser/JavaCCGlobals.java b/src/main/java/com/helger/pgcc/parser/JavaCCGlobals.java index 0bebc1a68..a94032f80 100644 --- a/src/main/java/com/helger/pgcc/parser/JavaCCGlobals.java +++ b/src/main/java/com/helger/pgcc/parser/JavaCCGlobals.java @@ -56,7 +56,6 @@ import com.helger.pgcc.CPG; import com.helger.pgcc.PGPrinter; import com.helger.pgcc.PGVersion; -import com.helger.pgcc.output.UnsupportedOutputLanguageException; import com.helger.pgcc.parser.exp.AbstractExpRegularExpression; import com.helger.pgcc.parser.exp.ExpAction; @@ -494,31 +493,21 @@ public static String addEscapes (@Nonnull final String str) public static String addUnicodeEscapes (final String str) { - switch (Options.getOutputLanguage ()) + final StringBuilder retval = new StringBuilder (str.length () * 2); + for (final char ch : str.toCharArray ()) { - case JAVA: + if (ch < 0x20 || + ch > 0x7e /* || ch == '\\' -- cba commented out 20140305 */ ) { - final StringBuilder retval = new StringBuilder (str.length () * 2); - for (final char ch : str.toCharArray ()) - { - if (ch < 0x20 || - ch > 0x7e /* || ch == '\\' -- cba commented out 20140305 */ ) - { - final String s = "0000" + Integer.toString (ch, 16); - retval.append ("\\u").append (s.substring (s.length () - 4, s.length ())); - } - else - { - retval.append (ch); - } - } - return retval.toString (); + final String s = "0000" + Integer.toString (ch, 16); + retval.append ("\\u").append (s.substring (s.length () - 4, s.length ())); + } + else + { + retval.append (ch); } - case CPP: - return str; - default: - throw new UnsupportedOutputLanguageException (Options.getOutputLanguage ()); } + return retval.toString (); } public static int s_cline; @@ -722,15 +711,7 @@ public static void reInitStatic () @Nonempty static String getFileExtension () { - switch (Options.getOutputLanguage ()) - { - case JAVA: - return ".java"; - case CPP: - return ".cc"; - default: - throw new UnsupportedOutputLanguageException (Options.getOutputLanguage ()); - } + return ".java"; } /** diff --git a/src/main/java/com/helger/pgcc/parser/LexGenCpp.java b/src/main/java/com/helger/pgcc/parser/LexGenCpp.java deleted file mode 100644 index 2516b0692..000000000 --- a/src/main/java/com/helger/pgcc/parser/LexGenCpp.java +++ /dev/null @@ -1,1366 +0,0 @@ -/* - * 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. - */ -// 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; - -import static com.helger.pgcc.parser.JavaCCGlobals.getFileExtension; -import static com.helger.pgcc.parser.JavaCCGlobals.s_aActForEof; -import static com.helger.pgcc.parser.JavaCCGlobals.s_cu_name; -import static com.helger.pgcc.parser.JavaCCGlobals.LEXSTATE_I2S; -import static com.helger.pgcc.parser.JavaCCGlobals.s_sNextStateForEof; -import static com.helger.pgcc.parser.JavaCCGlobals.REXPR_LIST; -import static com.helger.pgcc.parser.JavaCCGlobals.s_token_mgr_decls; -import static com.helger.pgcc.parser.JavaCCGlobals.s_toolNames; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import com.helger.commons.string.StringHelper; -import com.helger.pgcc.CPG; -import com.helger.pgcc.output.EOutputLanguage; -import com.helger.pgcc.output.OutputHelper; -import com.helger.pgcc.parser.exp.AbstractExpRegularExpression; -import com.helger.pgcc.parser.exp.ExpAction; -import com.helger.pgcc.parser.exp.ExpRChoice; -import com.helger.pgcc.parser.exp.ExpRStringLiteral; - -/** - * Generate lexer. - */ -public class LexGenCpp extends LexGenJava -{ - private void _printClassHead () - { - final List tn = new ArrayList <> (s_toolNames); - tn.add (CPG.APP_NAME); - - switchToStaticsFile (); - - // standard includes - switchToIncludeFile (); - genCodeLine ("#include \"stdio.h\""); - genCodeLine ("#include \"JavaCC.h\""); - genCodeLine ("#include \"CharStream.h\""); - genCodeLine ("#include \"Token.h\""); - genCodeLine ("#include \"ErrorHandler.h\""); - genCodeLine ("#include \"TokenManager.h\""); - genCodeLine ("#include \"" + s_cu_name + "Constants.h\""); - - if (Options.stringValue (Options.USEROPTION__CPP_TOKEN_MANAGER_INCLUDES).length () > 0) - { - genCodeLine ("#include \"" + Options.stringValue (Options.USEROPTION__CPP_TOKEN_MANAGER_INCLUDES) + "\"\n"); - } - - genCodeNewLine (); - - if (Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0) - { - genCodeLine ("namespace " + Options.stringValue ("NAMESPACE_OPEN")); - } - - genCodeLine ("class " + s_cu_name + ";"); - - /* - * final int l = 0, kind; i = 1; namespace? for (;;) { if - * (cu_to_insertion_point_1.size() <= l) break; kind = - * ((Token)cu_to_insertion_point_1.get(l)).kind; if(kind == PACKAGE || kind - * == IMPORT) { for (; i < cu_to_insertion_point_1.size(); i++) { kind = - * ((Token)cu_to_insertion_point_1.get(i)).kind; if (kind == CLASS) { cline - * = ((Token)(cu_to_insertion_point_1.get(l))).beginLine; ccol = - * ((Token)(cu_to_insertion_point_1.get(l))).beginColumn; for (j = l; j < i; - * j++) { printToken((Token)(cu_to_insertion_point_1.get(j))); } if (kind == - * SEMICOLON) printToken((Token)(cu_to_insertion_point_1.get(j))); - * genCodeLine(""); break; } } l = ++i; } else break; } - */ - - genCodeNewLine (); - genCodeLine ("/** Token Manager. */"); - final String superClass = Options.stringValue (Options.USEROPTION__TOKEN_MANAGER_SUPER_CLASS); - genClassStart (null, - s_tokMgrClassName, - new String [] {}, - new String [] { "public TokenManager" + (superClass == null ? "" : ", public " + superClass) }); - - if (s_token_mgr_decls != null && s_token_mgr_decls.isNotEmpty ()) - { - Token t = s_token_mgr_decls.get (0); - boolean bCommonTokenActionSeen = false; - final boolean bCommonTokenActionNeeded = Options.isCommonTokenAction (); - - printTokenSetup (s_token_mgr_decls.get (0)); - setColToStart (); - - switchToMainFile (); - for (final Token s_token_mgr_decl : s_token_mgr_decls) - { - t = s_token_mgr_decl; - if (t.kind == JavaCCParserConstants.IDENTIFIER && bCommonTokenActionNeeded && !bCommonTokenActionSeen) - { - bCommonTokenActionSeen = t.image.equals ("CommonTokenAction"); - if (bCommonTokenActionSeen) - t.image = s_cu_name + "TokenManager::" + t.image; - } - - printToken (t); - } - - switchToIncludeFile (); - genCodeLine (" void CommonTokenAction(Token* token);"); - - if (Options.isTokenManagerUsesParser ()) - { - genCodeLine (" void setParser(void* parser) {"); - genCodeLine (" this->parser = (" + s_cu_name + "*) parser;"); - genCodeLine (" }"); - } - genCodeNewLine (); - - if (bCommonTokenActionNeeded && !bCommonTokenActionSeen) - { - JavaCCErrors.warning ("You have the COMMON_TOKEN_ACTION option set. " + - "But it appears you have not defined the method :\n" + - " " + - "void CommonTokenAction(Token *t)\n" + - "in your TOKEN_MGR_DECLS. The generated token manager will not compile."); - } - } - else - if (Options.isCommonTokenAction ()) - { - JavaCCErrors.warning ("You have the COMMON_TOKEN_ACTION option set. " + - "But you have not defined the method :\n" + - " " + - "void CommonTokenAction(Token *t)\n" + - "in your TOKEN_MGR_DECLS. The generated token manager will not compile."); - } - - genCodeNewLine (); - genCodeLine (" FILE *debugStream;"); - - generateMethodDefHeader (" void ", s_tokMgrClassName, "setDebugStream(FILE *ds)"); - genCodeLine ("{ debugStream = ds; }"); - - switchToIncludeFile (); - if (Options.isTokenManagerUsesParser ()) - { - genCodeNewLine (); - genCodeLine ("private:"); - genCodeLine (" " + s_cu_name + "* parser = nullptr;"); - } - switchToMainFile (); - } - - private void _dumpDebugMethods () throws IOException - { - final Map aOpts = new HashMap <> (); - aOpts.put ("maxOrdinal", Integer.toString (s_maxOrdinal)); - aOpts.put ("stateSetSize", Integer.toString (s_stateSetSize)); - writeTemplate ("/templates/cpp/DumpDebugMethods.template", aOpts); - } - - private static void _buildLexStatesTable () - { - final Iterator it = REXPR_LIST.iterator (); - TokenProduction tp; - int i; - - final String [] tmpLexStateName = new String [LEXSTATE_I2S.size ()]; - while (it.hasNext ()) - { - tp = it.next (); - final List respecs = tp.m_respecs; - List tps; - - for (i = 0; i < tp.m_lexStates.length; i++) - { - tps = s_allTpsForState.get (tp.m_lexStates[i]); - if (tps == null) - { - tmpLexStateName[s_maxLexStates++] = tp.m_lexStates[i]; - tps = new ArrayList <> (); - s_allTpsForState.put (tp.m_lexStates[i], tps); - } - - tps.add (tp); - } - - if (respecs == null || respecs.size () == 0) - continue; - - for (i = 0; i < respecs.size (); i++) - { - final AbstractExpRegularExpression re = respecs.get (i).rexp; - if (s_maxOrdinal <= re.getOrdinal ()) - s_maxOrdinal = re.getOrdinal () + 1; - } - } - - s_kinds = new ETokenKind [s_maxOrdinal]; - s_toSkip = new long [s_maxOrdinal / 64 + 1]; - s_toSpecial = new long [s_maxOrdinal / 64 + 1]; - s_toMore = new long [s_maxOrdinal / 64 + 1]; - s_toToken = new long [s_maxOrdinal / 64 + 1]; - s_toToken[0] = 1L; - s_actions = new ExpAction [s_maxOrdinal]; - s_actions[0] = s_aActForEof; - s_hasTokenActions = s_aActForEof != null; - s_initStates.clear (); - s_canMatchAnyChar = new int [s_maxLexStates]; - s_canLoop = new boolean [s_maxLexStates]; - s_stateHasActions = new boolean [s_maxLexStates]; - s_lexStateName = new String [s_maxLexStates]; - s_singlesToSkip = new NfaState [s_maxLexStates]; - System.arraycopy (tmpLexStateName, 0, s_lexStateName, 0, s_maxLexStates); - - for (i = 0; i < s_maxLexStates; i++) - s_canMatchAnyChar[i] = -1; - - s_hasNfa = new boolean [s_maxLexStates]; - s_mixed = new boolean [s_maxLexStates]; - s_maxLongsReqd = new int [s_maxLexStates]; - s_initMatch = new int [s_maxLexStates]; - s_newLexState = new String [s_maxOrdinal]; - s_newLexState[0] = s_sNextStateForEof; - s_hasEmptyMatch = false; - s_lexStates = new int [s_maxOrdinal]; - s_ignoreCase = new boolean [s_maxOrdinal]; - s_rexprs = new AbstractExpRegularExpression [s_maxOrdinal]; - ExpRStringLiteral.s_allImages = new String [s_maxOrdinal]; - s_canReachOnMore = new boolean [s_maxLexStates]; - } - - private static int _getIndex (final String name) - { - for (int i = 0; i < s_lexStateName.length; i++) - if (s_lexStateName[i] != null && s_lexStateName[i].equals (name)) - return i; - - throw new IllegalStateException ("Should never come here"); - } - - @Override - public void start () throws IOException - { - if (!Options.isBuildTokenManager () || Options.isUserTokenManager () || JavaCCErrors.getErrorCount () > 0) - return; - - s_keepLineCol = Options.isKeepLineColumn (); - final List choices = new ArrayList <> (); - - s_tokMgrClassName = s_cu_name + "TokenManager"; - - _printClassHead (); - _buildLexStatesTable (); - - boolean ignoring = false; - - for (final Map.Entry > aEntry : s_allTpsForState.entrySet ()) - { - NfaState.reInitStatic (); - ExpRStringLiteral.reInitStatic (); - - final String key = aEntry.getKey (); - - s_lexStateIndex = _getIndex (key); - s_lexStateSuffix = "_" + s_lexStateIndex; - final List allTps = aEntry.getValue (); - s_initialState = new NfaState (); - s_initStates.put (key, s_initialState); - ignoring = false; - - s_singlesToSkip[s_lexStateIndex] = new NfaState (); - s_singlesToSkip[s_lexStateIndex].m_dummy = true; - - if (key.equals ("DEFAULT")) - s_defaultLexState = s_lexStateIndex; - - for (int i = 0; i < allTps.size (); i++) - { - final TokenProduction tp = allTps.get (i); - final ETokenKind kind = tp.m_kind; - final boolean ignore = tp.m_ignoreCase; - final List rexps = tp.m_respecs; - - if (i == 0) - ignoring = ignore; - - for (final RegExprSpec respec : rexps) - { - s_curRE = respec.rexp; - - s_rexprs[s_curKind = s_curRE.getOrdinal ()] = s_curRE; - s_lexStates[s_curRE.getOrdinal ()] = s_lexStateIndex; - s_ignoreCase[s_curRE.getOrdinal ()] = ignore; - - if (s_curRE.m_private_rexp) - { - s_kinds[s_curRE.getOrdinal ()] = null; - continue; - } - - if (s_curRE instanceof ExpRStringLiteral && StringHelper.hasText (((ExpRStringLiteral) s_curRE).m_image)) - { - ((ExpRStringLiteral) s_curRE).generateDfa (); - if (i != 0 && !s_mixed[s_lexStateIndex] && ignoring != ignore) - s_mixed[s_lexStateIndex] = true; - } - else - if (s_curRE.canMatchAnyChar ()) - { - if (s_canMatchAnyChar[s_lexStateIndex] == -1 || s_canMatchAnyChar[s_lexStateIndex] > s_curRE.getOrdinal ()) - s_canMatchAnyChar[s_lexStateIndex] = s_curRE.getOrdinal (); - } - else - { - Nfa temp; - - if (s_curRE instanceof ExpRChoice) - choices.add ((ExpRChoice) s_curRE); - - temp = s_curRE.generateNfa (ignore); - temp.end ().m_isFinal = true; - temp.end ().m_kind = s_curRE.getOrdinal (); - s_initialState.addMove (temp.start ()); - } - - if (s_kinds.length < s_curRE.getOrdinal ()) - { - final ETokenKind [] tmp = new ETokenKind [s_curRE.getOrdinal () + 1]; - - System.arraycopy (s_kinds, 0, tmp, 0, s_kinds.length); - s_kinds = tmp; - } - // System.out.println(" ordina : " + curRE.ordinal); - - s_kinds[s_curRE.getOrdinal ()] = kind; - - if (respec.nextState != null && !respec.nextState.equals (s_lexStateName[s_lexStateIndex])) - s_newLexState[s_curRE.getOrdinal ()] = respec.nextState; - - if (respec.act != null && respec.act.getActionTokens () != null && respec.act.getActionTokens ().size () > 0) - s_actions[s_curRE.getOrdinal ()] = respec.act; - - switch (kind) - { - case SPECIAL: - s_hasSkipActions |= (s_actions[s_curRE.getOrdinal ()] != null) || (s_newLexState[s_curRE.getOrdinal ()] != null); - s_hasSpecial = true; - s_toSpecial[s_curRE.getOrdinal () / 64] |= 1L << (s_curRE.getOrdinal () % 64); - s_toSkip[s_curRE.getOrdinal () / 64] |= 1L << (s_curRE.getOrdinal () % 64); - break; - case SKIP: - s_hasSkipActions |= (s_actions[s_curRE.getOrdinal ()] != null); - s_hasSkip = true; - s_toSkip[s_curRE.getOrdinal () / 64] |= 1L << (s_curRE.getOrdinal () % 64); - break; - case MORE: - s_hasMoreActions |= (s_actions[s_curRE.getOrdinal ()] != null); - s_hasMore = true; - s_toMore[s_curRE.getOrdinal () / 64] |= 1L << (s_curRE.getOrdinal () % 64); - - if (s_newLexState[s_curRE.getOrdinal ()] != null) - s_canReachOnMore[_getIndex (s_newLexState[s_curRE.getOrdinal ()])] = true; - else - s_canReachOnMore[s_lexStateIndex] = true; - - break; - case TOKEN: - s_hasTokenActions |= (s_actions[s_curRE.getOrdinal ()] != null); - s_toToken[s_curRE.getOrdinal () / 64] |= 1L << (s_curRE.getOrdinal () % 64); - break; - default: - throw new IllegalStateException (); - } - } - } - - // Generate a static block for initializing the nfa transitions - NfaState.computeClosures (); - - for (final NfaState aItem : s_initialState.m_epsilonMoves) - aItem.generateCode (); - - s_hasNfa[s_lexStateIndex] = (NfaState.s_generatedStates != 0); - if (s_hasNfa[s_lexStateIndex]) - { - s_initialState.generateCode (); - s_initialState.generateInitMoves (); - } - - if (s_initialState.m_kind != Integer.MAX_VALUE && s_initialState.m_kind != 0) - { - if ((s_toSkip[s_initialState.m_kind / 64] & (1L << s_initialState.m_kind)) != 0L || - (s_toSpecial[s_initialState.m_kind / 64] & (1L << s_initialState.m_kind)) != 0L) - s_hasSkipActions = true; - else - if ((s_toMore[s_initialState.m_kind / 64] & (1L << s_initialState.m_kind)) != 0L) - s_hasMoreActions = true; - else - s_hasTokenActions = true; - - if (s_initMatch[s_lexStateIndex] == 0 || s_initMatch[s_lexStateIndex] > s_initialState.m_kind) - { - s_initMatch[s_lexStateIndex] = s_initialState.m_kind; - s_hasEmptyMatch = true; - } - } - else - if (s_initMatch[s_lexStateIndex] == 0) - s_initMatch[s_lexStateIndex] = Integer.MAX_VALUE; - - ExpRStringLiteral.fillSubString (); - - if (s_hasNfa[s_lexStateIndex] && !s_mixed[s_lexStateIndex]) - ExpRStringLiteral.generateNfaStartStates (this, s_initialState); - - ExpRStringLiteral.dumpDfaCode (this); - - if (s_hasNfa[s_lexStateIndex]) - NfaState.dumpMoveNfa (this); - - if (s_stateSetSize < NfaState.s_generatedStates) - s_stateSetSize = NfaState.s_generatedStates; - } - - for (final ExpRChoice aItem : choices) - aItem.checkUnmatchability (); - - NfaState.dumpStateSets (this); - checkEmptyStringMatch (); - NfaState.dumpNonAsciiMoveMethods (this); - ExpRStringLiteral.dumpStrLiteralImages (this); - _dumpFillToken (); - _dumpGetNextToken (); - - if (Options.isDebugTokenManager ()) - { - NfaState.dumpStatesForKind (this); - _dumpDebugMethods (); - } - - if (s_hasLoop) - { - switchToStaticsFile (); - genCodeLine ("static int jjemptyLineNo[" + s_maxLexStates + "];"); - genCodeLine ("static int jjemptyColNo[" + s_maxLexStates + "];"); - genCodeLine ("static bool jjbeenHere[" + s_maxLexStates + "];"); - switchToMainFile (); - } - - if (s_hasSkipActions) - _dumpSkipActions (); - if (s_hasMoreActions) - _dumpMoreActions (); - if (s_hasTokenActions) - _dumpTokenActions (); - - NfaState.printBoilerPlateCPP (this); - - { - final Map aOpts = new HashMap <> (); - aOpts.put ("charStreamName", "CharStream"); - aOpts.put ("parserClassName", s_cu_name); - aOpts.put ("defaultLexState", "defaultLexState"); - aOpts.put ("lexStateNameLength", Integer.toString (s_lexStateName.length)); - writeTemplate ("/templates/cpp/TokenManagerBoilerPlateMethods.template", aOpts); - } - - _dumpBoilerPlateInHeader (); - - // in the include file close the class signature´ - // static vars actually inst - _dumpStaticVarDeclarations (); - - // remaining variables - switchToIncludeFile (); - { - final Map aOpts = new HashMap <> (); - aOpts.put ("charStreamName", "CharStream"); - aOpts.put ("lexStateNameLength", Integer.toString (s_lexStateName.length)); - writeTemplate ("/templates/cpp/DumpVarDeclarations.template", aOpts); - } - genCodeLine (/* { */ "};"); - - switchToStaticsFile (); - // TODO :: CBA -- Require Unification of output language specific processing - // into a single Enum class - final String fileName = Options.getOutputDirectory () + File.separator + s_tokMgrClassName + getFileExtension (); - saveOutput (fileName); - } - - private void _dumpBoilerPlateInHeader () - { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - - switchToIncludeFile (); - genCodeLine ("#ifndef JAVACC_CHARSTREAM"); - genCodeLine ("#define JAVACC_CHARSTREAM CharStream"); - genCodeLine ("#endif"); - genCodeNewLine (); - - genCodeLine ("private:"); - genCodeLine (" void ReInitRounds();"); - genCodeNewLine (); - genCodeLine ("public:"); - genCodeLine (" " + s_tokMgrClassName + "(JAVACC_CHARSTREAM *stream, int lexState = " + s_defaultLexState + ");"); - genCodeLine (" virtual ~" + s_tokMgrClassName + "();"); - genCodeLine (" void ReInit(JAVACC_CHARSTREAM *stream, int lexState = " + s_defaultLexState + ");"); - genCodeLine (" void SwitchTo(int lexState);"); - genCodeLine (" void clear();"); - genCodeLine (" const JJSimpleString jjKindsForBitVector(int i, " + eOutputLanguage.getTypeLong () + " vec);"); - genCodeLine (" const JJSimpleString jjKindsForStateVector(int lexState, int vec[], int start, int end);"); - genCodeNewLine (); - } - - private void _dumpStaticVarDeclarations () - { - int i; - - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - switchToStaticsFile (); // remaining variables - genCodeNewLine (); - genCodeLine ("/** Lexer state names. */"); - genStringLiteralArrayCPP ("lexStateNames", s_lexStateName); - - if (s_maxLexStates > 1) - { - genCodeNewLine (); - genCodeLine ("/** Lex State array. */"); - genCode ("static const int jjnewLexState[] = {"); - - for (i = 0; i < s_maxOrdinal; i++) - { - if (i % 25 == 0) - genCode ("\n "); - - if (s_newLexState[i] == null) - genCode ("-1, "); - else - genCode (_getIndex (s_newLexState[i]) + ", "); - } - genCodeLine ("\n};"); - } - - if (s_hasSkip || s_hasMore || s_hasSpecial) - { - // Bit vector for TOKEN - genCode ("static const " + eOutputLanguage.getTypeLong () + " jjtoToken[] = {"); - for (i = 0; i < s_maxOrdinal / 64 + 1; i++) - { - if (i % 4 == 0) - genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toToken[i]) + ", "); - } - genCodeLine ("\n};"); - } - - if (s_hasSkip || s_hasSpecial) - { - // Bit vector for SKIP - genCode ("static const " + eOutputLanguage.getTypeLong () + " jjtoSkip[] = {"); - for (i = 0; i < s_maxOrdinal / 64 + 1; i++) - { - if (i % 4 == 0) - genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toSkip[i]) + ", "); - } - genCodeLine ("\n};"); - } - - if (s_hasSpecial) - { - // Bit vector for SPECIAL - genCode ("static const " + eOutputLanguage.getTypeLong () + " jjtoSpecial[] = {"); - for (i = 0; i < s_maxOrdinal / 64 + 1; i++) - { - if (i % 4 == 0) - genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toSpecial[i]) + ", "); - } - genCodeLine ("\n};"); - } - - if (false) - if (s_hasMore) // Not needed as we just use else - { - // Bit vector for MORE - genCode ("static const " + eOutputLanguage.getTypeLong () + " jjtoMore[] = {"); - for (i = 0; i < s_maxOrdinal / 64 + 1; i++) - { - if (i % 4 == 0) - genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toMore[i]) + ", "); - } - genCodeLine ("\n};"); - } - } - - private void _dumpFillToken () - { - final double tokenVersion = OutputHelper.getVersionDashStar ("Token.java"); - final boolean hasBinaryNewToken = tokenVersion > 4.09; - - generateMethodDefHeader ("Token *", s_tokMgrClassName, "jjFillToken()"); - genCodeLine ("{"); - genCodeLine (" Token *t;"); - genCodeLine (" JJString curTokenImage;"); - if (s_keepLineCol) - { - genCodeLine (" int beginLine = -1;"); - genCodeLine (" int endLine = -1;"); - genCodeLine (" int beginColumn = -1;"); - genCodeLine (" int endColumn = -1;"); - } - - if (s_hasEmptyMatch) - { - genCodeLine (" if (jjmatchedPos < 0)"); - genCodeLine (" {"); - genCodeLine (" curTokenImage = image.c_str();"); - - if (s_keepLineCol) - { - genCodeLine (" if (input_stream->getTrackLineColumn()) {"); - genCodeLine (" beginLine = endLine = input_stream->getEndLine();"); - genCodeLine (" beginColumn = endColumn = input_stream->getEndColumn();"); - genCodeLine (" }"); - } - - genCodeLine (" }"); - genCodeLine (" else"); - genCodeLine (" {"); - genCodeLine (" JJString im = jjstrLiteralImages[jjmatchedKind];"); - genCodeLine (" curTokenImage = (im.length() == 0) ? input_stream->GetImage() : im;"); - - if (s_keepLineCol) - { - genCodeLine (" if (input_stream->getTrackLineColumn()) {"); - genCodeLine (" beginLine = input_stream->getBeginLine();"); - genCodeLine (" beginColumn = input_stream->getBeginColumn();"); - genCodeLine (" endLine = input_stream->getEndLine();"); - genCodeLine (" endColumn = input_stream->getEndColumn();"); - genCodeLine (" }"); - } - - genCodeLine (" }"); - } - else - { - genCodeLine (" JJString im = jjstrLiteralImages[jjmatchedKind];"); - genCodeLine (" curTokenImage = (im.length() == 0) ? input_stream->GetImage() : im;"); - if (s_keepLineCol) - { - genCodeLine (" if (input_stream->getTrackLineColumn()) {"); - genCodeLine (" beginLine = input_stream->getBeginLine();"); - genCodeLine (" beginColumn = input_stream->getBeginColumn();"); - genCodeLine (" endLine = input_stream->getEndLine();"); - genCodeLine (" endColumn = input_stream->getEndColumn();"); - genCodeLine (" }"); - } - } - - if (Options.getTokenFactory ().length () > 0) - { - genCodeLine (" t = " + getClassQualifier (Options.getTokenFactory ()) + "newToken(jjmatchedKind, curTokenImage);"); - } - else - if (hasBinaryNewToken) - { - genCodeLine (" t = " + getClassQualifier ("Token") + "newToken(jjmatchedKind, curTokenImage);"); - } - else - { - genCodeLine (" t = " + getClassQualifier ("Token") + "newToken(jjmatchedKind);"); - genCodeLine (" t->kind = jjmatchedKind;"); - genCodeLine (" t->image = curTokenImage;"); - } - genCodeLine (" t->specialToken = nullptr;"); - genCodeLine (" t->next = nullptr;"); - - if (s_keepLineCol) - { - genCodeNewLine (); - genCodeLine (" if (input_stream->getTrackLineColumn()) {"); - genCodeLine (" t->beginLine = beginLine;"); - genCodeLine (" t->endLine = endLine;"); - genCodeLine (" t->beginColumn = beginColumn;"); - genCodeLine (" t->endColumn = endColumn;"); - genCodeLine (" }"); - } - - genCodeNewLine (); - genCodeLine (" return t;"); - genCodeLine ("}"); - } - - private void _dumpGetNextToken () - { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - - switchToIncludeFile (); - genCodeNewLine (); - genCodeLine ("public:"); - genCodeLine (" int curLexState;"); - genCodeLine (" int jjnewStateCnt;"); - genCodeLine (" int jjround;"); - genCodeLine (" int jjmatchedPos;"); - genCodeLine (" int jjmatchedKind;"); - genCodeNewLine (); - switchToMainFile (); - genCodeLine ("const int defaultLexState = " + s_defaultLexState + ";"); - genCodeLine ("/** Get the next Token. */"); - generateMethodDefHeader ("Token *", s_tokMgrClassName, "getNextToken()"); - genCodeLine ("{"); - if (s_hasSpecial) - { - genCodeLine (" Token *specialToken = nullptr;"); - } - genCodeLine (" Token *matchedToken = nullptr;"); - genCodeLine (" int curPos = 0;"); - genCodeNewLine (); - genCodeLine (" for (;;)"); - genCodeLine (" {"); - genCodeLine (" EOFLoop: "); - // genCodeLine(" {"); - // genCodeLine(" curChar = input_stream->BeginToken();"); - // genCodeLine(" }"); - genCodeLine (" if (input_stream->endOfInput())"); - genCodeLine (" {"); - // genCodeLine(" input_stream->backup(1);"); - - if (Options.isDebugTokenManager ()) - genCodeLine (" fprintf(debugStream, \"Returning the token.\\n\");"); - - genCodeLine (" jjmatchedKind = 0;"); - genCodeLine (" jjmatchedPos = -1;"); - genCodeLine (" matchedToken = jjFillToken();"); - - if (s_hasSpecial) - genCodeLine (" matchedToken->specialToken = specialToken;"); - - if (s_sNextStateForEof != null || s_aActForEof != null) - genCodeLine (" TokenLexicalActions(matchedToken);"); - - if (Options.isCommonTokenAction ()) - genCodeLine (" CommonTokenAction(matchedToken);"); - - genCodeLine (" return matchedToken;"); - genCodeLine (" }"); - genCodeLine (" curChar = input_stream->BeginToken();"); - - if (s_hasMoreActions || s_hasSkipActions || s_hasTokenActions) - { - genCodeLine (" image = jjimage;"); - genCodeLine (" image.clear();"); - genCodeLine (" jjimageLen = 0;"); - } - - genCodeNewLine (); - - String prefix = ""; - if (s_hasMore) - { - genCodeLine (" for (;;)"); - genCodeLine (" {"); - prefix = " "; - } - - String endSwitch = ""; - String caseStr = ""; - // this also sets up the start state of the nfa - if (s_maxLexStates > 1) - { - genCodeLine (prefix + " switch(curLexState)"); - genCodeLine (prefix + " {"); - endSwitch = prefix + " }"; - caseStr = prefix + " case "; - prefix += " "; - } - - prefix += " "; - for (int i = 0; i < s_maxLexStates; i++) - { - if (s_maxLexStates > 1) - genCodeLine (caseStr + i + ":"); - - if (s_singlesToSkip[i].hasTransitions ()) - { - // added the backup(0) to make JIT happy - genCodeLine (prefix + "{ input_stream->backup(0);"); - if (s_singlesToSkip[i].m_asciiMoves[0] != 0L && s_singlesToSkip[i].m_asciiMoves[1] != 0L) - { - genCodeLine (prefix + - " while ((curChar < 64" + - " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[0]) + - " & (1L << curChar)) != 0L) || \n" + - prefix + - " (curChar >> 6) == 1" + - " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[1]) + - " & (1L << (curChar & 077))) != " + - eOutputLanguage.getLongPlain (0) + - ")"); - } - else - if (s_singlesToSkip[i].m_asciiMoves[1] == 0L) - { - genCodeLine (prefix + - " while (curChar <= " + - (int) maxChar (s_singlesToSkip[i].m_asciiMoves[0]) + - " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[0]) + - " & (1L << curChar)) != " + - eOutputLanguage.getLongPlain (0) + - ")"); - } - else - if (s_singlesToSkip[i].m_asciiMoves[0] == 0L) - { - genCodeLine (prefix + - " while (curChar > 63 && curChar <= " + - (maxChar (s_singlesToSkip[i].m_asciiMoves[1]) + 64) + - " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[1]) + - " & (1L << (curChar & 077))) != " + - eOutputLanguage.getLongPlain (0) + - ")"); - } - - genCodeLine (prefix + "{"); - if (Options.isDebugTokenManager ()) - { - if (s_maxLexStates > 1) - { - genCodeLine (" fprintf(debugStream, \"<%s>\" , addUnicodeEscapes(lexStateNames[curLexState]).c_str());"); - } - - genCodeLine (" fprintf(debugStream, \"Skipping character : %c(%d)\\n\", curChar, (int)curChar);"); - } - - genCodeLine (prefix + "if (input_stream->endOfInput()) { goto EOFLoop; }"); - genCodeLine (prefix + "curChar = input_stream->BeginToken();"); - genCodeLine (prefix + "}"); - genCodeLine (prefix + "}"); - } - - if (s_initMatch[i] != Integer.MAX_VALUE && s_initMatch[i] != 0) - { - if (Options.isDebugTokenManager ()) - genCodeLine (" fprintf(debugStream, \" Matched the empty string as %s token.\\n\", addUnicodeEscapes(tokenImage[" + - s_initMatch[i] + - "]).c_str());"); - - genCodeLine (prefix + "jjmatchedKind = " + s_initMatch[i] + ";"); - genCodeLine (prefix + "jjmatchedPos = -1;"); - genCodeLine (prefix + "curPos = 0;"); - } - else - { - genCodeLine (prefix + "jjmatchedKind = 0x" + Integer.toHexString (Integer.MAX_VALUE) + ";"); - genCodeLine (prefix + "jjmatchedPos = 0;"); - } - - if (Options.isDebugTokenManager ()) - { - genCodeLine (" fprintf(debugStream, " + - "\"<%s>Current character : %c(%d) at line %d column %d\\n\"," + - "addUnicodeEscapes(lexStateNames[curLexState]).c_str(), curChar, (int)curChar, " + - "input_stream->getEndLine(), input_stream->getEndColumn());"); - } - - genCodeLine (prefix + "curPos = jjMoveStringLiteralDfa0_" + i + "();"); - - if (s_canMatchAnyChar[i] != -1) - { - if (s_initMatch[i] != Integer.MAX_VALUE && s_initMatch[i] != 0) - genCodeLine (prefix + "if (jjmatchedPos < 0 || (jjmatchedPos == 0 && jjmatchedKind > " + s_canMatchAnyChar[i] + "))"); - else - genCodeLine (prefix + "if (jjmatchedPos == 0 && jjmatchedKind > " + s_canMatchAnyChar[i] + ")"); - genCodeLine (prefix + "{"); - - if (Options.isDebugTokenManager ()) - { - genCodeLine (" fprintf(debugStream, \" Current character matched as a %s token.\\n\", addUnicodeEscapes(tokenImage[" + - s_canMatchAnyChar[i] + - "]).c_str());"); - } - genCodeLine (prefix + " jjmatchedKind = " + s_canMatchAnyChar[i] + ";"); - - if (s_initMatch[i] != Integer.MAX_VALUE && s_initMatch[i] != 0) - genCodeLine (prefix + " jjmatchedPos = 0;"); - - genCodeLine (prefix + "}"); - } - - if (s_maxLexStates > 1) - genCodeLine (prefix + "break;"); - } - - if (s_maxLexStates > 1) - genCodeLine (endSwitch); - else - if (s_maxLexStates == 0) - genCodeLine (" jjmatchedKind = 0x" + Integer.toHexString (Integer.MAX_VALUE) + ";"); - - if (s_maxLexStates > 1) - prefix = " "; - else - prefix = ""; - - if (s_maxLexStates > 0) - { - genCodeLine (prefix + " if (jjmatchedKind != 0x" + Integer.toHexString (Integer.MAX_VALUE) + ")"); - genCodeLine (prefix + " {"); - genCodeLine (prefix + " if (jjmatchedPos + 1 < curPos)"); - - if (Options.isDebugTokenManager ()) - { - genCodeLine (prefix + " {"); - genCodeLine (prefix + - " fprintf(debugStream, " + - "\" Putting back %d characters into the input stream.\\n\", (curPos - jjmatchedPos - 1));"); - } - - genCodeLine (prefix + " input_stream->backup(curPos - jjmatchedPos - 1);"); - - if (Options.isDebugTokenManager ()) - { - genCodeLine (prefix + " }"); - } - - if (Options.isDebugTokenManager ()) - { - genCodeLine (" fprintf(debugStream, " + - "\"****** FOUND A %d(%s) MATCH (%s) ******\\n\", jjmatchedKind, addUnicodeEscapes(tokenImage[jjmatchedKind]).c_str(), addUnicodeEscapes(input_stream->GetSuffix(jjmatchedPos + 1)).c_str());"); - } - - if (s_hasSkip || s_hasMore || s_hasSpecial) - { - genCodeLine (prefix + " if ((jjtoToken[jjmatchedKind >> 6] & " + "(1L << (jjmatchedKind & 077))) != 0L)"); - genCodeLine (prefix + " {"); - } - - genCodeLine (prefix + " matchedToken = jjFillToken();"); - - if (s_hasSpecial) - genCodeLine (prefix + " matchedToken->specialToken = specialToken;"); - - if (s_hasTokenActions) - genCodeLine (prefix + " TokenLexicalActions(matchedToken);"); - - if (s_maxLexStates > 1) - { - genCodeLine (" if (jjnewLexState[jjmatchedKind] != -1)"); - genCodeLine (prefix + " curLexState = jjnewLexState[jjmatchedKind];"); - } - - if (Options.isCommonTokenAction ()) - genCodeLine (prefix + " CommonTokenAction(matchedToken);"); - - genCodeLine (prefix + " return matchedToken;"); - - if (s_hasSkip || s_hasMore || s_hasSpecial) - { - genCodeLine (prefix + " }"); - - if (s_hasSkip || s_hasSpecial) - { - if (s_hasMore) - { - genCodeLine (prefix + " else if ((jjtoSkip[jjmatchedKind >> 6] & " + "(1L << (jjmatchedKind & 077))) != 0L)"); - } - else - genCodeLine (prefix + " else"); - - genCodeLine (prefix + " {"); - - if (s_hasSpecial) - { - genCodeLine (prefix + " if ((jjtoSpecial[jjmatchedKind >> 6] & " + "(1L << (jjmatchedKind & 077))) != 0L)"); - genCodeLine (prefix + " {"); - - genCodeLine (prefix + " matchedToken = jjFillToken();"); - - genCodeLine (prefix + " if (specialToken == nullptr)"); - genCodeLine (prefix + " specialToken = matchedToken;"); - genCodeLine (prefix + " else"); - genCodeLine (prefix + " {"); - genCodeLine (prefix + " matchedToken->specialToken = specialToken;"); - genCodeLine (prefix + " specialToken = (specialToken->next = matchedToken);"); - genCodeLine (prefix + " }"); - - if (s_hasSkipActions) - genCodeLine (prefix + " SkipLexicalActions(matchedToken);"); - - genCodeLine (prefix + " }"); - - if (s_hasSkipActions) - { - genCodeLine (prefix + " else"); - genCodeLine (prefix + " SkipLexicalActions(nullptr);"); - } - } - else - if (s_hasSkipActions) - genCodeLine (prefix + " SkipLexicalActions(nullptr);"); - - if (s_maxLexStates > 1) - { - genCodeLine (" if (jjnewLexState[jjmatchedKind] != -1)"); - genCodeLine (prefix + " curLexState = jjnewLexState[jjmatchedKind];"); - } - - genCodeLine (prefix + " goto EOFLoop;"); - genCodeLine (prefix + " }"); - } - - if (s_hasMore) - { - if (s_hasMoreActions) - genCodeLine (prefix + " MoreLexicalActions();"); - else - if (s_hasSkipActions || s_hasTokenActions) - genCodeLine (prefix + " jjimageLen += jjmatchedPos + 1;"); - - if (s_maxLexStates > 1) - { - genCodeLine (" if (jjnewLexState[jjmatchedKind] != -1)"); - genCodeLine (prefix + " curLexState = jjnewLexState[jjmatchedKind];"); - } - genCodeLine (prefix + " curPos = 0;"); - genCodeLine (prefix + " jjmatchedKind = 0x" + Integer.toHexString (Integer.MAX_VALUE) + ";"); - - genCodeLine (prefix + " if (!input_stream->endOfInput()) {"); - genCodeLine (prefix + " curChar = input_stream->readChar();"); - - if (Options.isDebugTokenManager ()) - { - genCodeLine (" fprintf(debugStream, " + - "\"<%s>Current character : %c(%d) at line %d column %d\\n\"," + - "addUnicodeEscapes(lexStateNames[curLexState]).c_str(), curChar, (int)curChar, " + - "input_stream->getEndLine(), input_stream->getEndColumn());"); - } - genCodeLine (prefix + " continue;"); - genCodeLine (prefix + " }"); - } - } - - genCodeLine (prefix + " }"); - genCodeLine (prefix + " int error_line = input_stream->getEndLine();"); - genCodeLine (prefix + " int error_column = input_stream->getEndColumn();"); - genCodeLine (prefix + " JJString error_after;"); - genCodeLine (prefix + " bool EOFSeen = false;"); - genCodeLine (prefix + " if (input_stream->endOfInput()) {"); - genCodeLine (prefix + " EOFSeen = true;"); - genCodeLine (prefix + " error_after = curPos <= 1 ? EMPTY : input_stream->GetImage();"); - genCodeLine (prefix + " if (curChar == '\\n' || curChar == '\\r') {"); - genCodeLine (prefix + " error_line++;"); - genCodeLine (prefix + " error_column = 0;"); - genCodeLine (prefix + " }"); - genCodeLine (prefix + " else"); - genCodeLine (prefix + " error_column++;"); - genCodeLine (prefix + " }"); - genCodeLine (prefix + " if (!EOFSeen) {"); - genCodeLine (prefix + " error_after = curPos <= 1 ? EMPTY : input_stream->GetImage();"); - genCodeLine (prefix + " }"); - genCodeLine (prefix + " errorHandler->lexicalError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, this);"); - } - - if (s_hasMore) - genCodeLine (prefix + " }"); - - genCodeLine (" }"); - genCodeLine ("}"); - genCodeNewLine (); - } - - private void _dumpSkipActions () - { - ExpAction act; - - generateMethodDefHeader ("void ", s_tokMgrClassName, "SkipLexicalActions(Token *matchedToken)"); - genCodeLine ("{"); - genCodeLine (" switch(jjmatchedKind)"); - genCodeLine (" {"); - - Outer: for (int i = 0; i < s_maxOrdinal; i++) - { - if ((s_toSkip[i / 64] & (1L << (i % 64))) == 0L) - continue; - - for (;;) - { - if (((act = s_actions[i]) == null || act.getActionTokens () == null || act.getActionTokens ().size () == 0) && - !s_canLoop[s_lexStates[i]]) - continue Outer; - - genCodeLine (" case " + i + " : {"); - - if (s_initMatch[s_lexStates[i]] == i && s_canLoop[s_lexStates[i]]) - { - genCodeLine (" if (jjmatchedPos == -1)"); - genCodeLine (" {"); - genCodeLine (" if (jjbeenHere[" + s_lexStates[i] + "] &&"); - genCodeLine (" jjemptyLineNo[" + s_lexStates[i] + "] == input_stream->getBeginLine() &&"); - genCodeLine (" jjemptyColNo[" + s_lexStates[i] + "] == input_stream->getBeginColumn())"); - genCodeLine (" errorHandler->lexicalError(JJString(\"(\"Error: Bailing out of infinite loop caused by repeated empty string matches \" + \"at line \" + input_stream->getBeginLine() + \", \" + \"column \" + input_stream->getBeginColumn() + \".\")), this);"); - genCodeLine (" jjemptyLineNo[" + s_lexStates[i] + "] = input_stream->getBeginLine();"); - genCodeLine (" jjemptyColNo[" + s_lexStates[i] + "] = input_stream->getBeginColumn();"); - genCodeLine (" jjbeenHere[" + s_lexStates[i] + "] = true;"); - genCodeLine (" }"); - } - - if ((act = s_actions[i]) == null || act.getActionTokens ().size () == 0) - break; - - genCode (" image.append"); - if (ExpRStringLiteral.s_allImages[i] != null) - { - genCodeLine ("(jjstrLiteralImages[" + i + "]);"); - genCodeLine (" lengthOfMatch = jjstrLiteralImages[" + i + "].length();"); - } - else - { - genCodeLine ("(input_stream->GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));"); - } - - printTokenSetup (act.getActionTokens ().get (0)); - setColToStart (); - - for (final Token t : act.getActionTokens ()) - printToken (t); - genCodeNewLine (); - - break; - } - - genCodeLine (" break;"); - genCodeLine (" }"); - } - - genCodeLine (" default :"); - genCodeLine (" break;"); - genCodeLine (" }"); - genCodeLine ("}"); - } - - private void _dumpMoreActions () - { - ExpAction act; - - generateMethodDefHeader ("void ", s_tokMgrClassName, "MoreLexicalActions()"); - genCodeLine ("{"); - genCodeLine (" jjimageLen += (lengthOfMatch = jjmatchedPos + 1);"); - genCodeLine (" switch(jjmatchedKind)"); - genCodeLine (" {"); - - Outer: for (int i = 0; i < s_maxOrdinal; i++) - { - if ((s_toMore[i / 64] & (1L << (i % 64))) == 0L) - continue; - - for (;;) - { - if (((act = s_actions[i]) == null || act.getActionTokens () == null || act.getActionTokens ().size () == 0) && - !s_canLoop[s_lexStates[i]]) - continue Outer; - - genCodeLine (" case " + i + " : {"); - - if (s_initMatch[s_lexStates[i]] == i && s_canLoop[s_lexStates[i]]) - { - genCodeLine (" if (jjmatchedPos == -1)"); - genCodeLine (" {"); - genCodeLine (" if (jjbeenHere[" + s_lexStates[i] + "] &&"); - genCodeLine (" jjemptyLineNo[" + s_lexStates[i] + "] == input_stream->getBeginLine() &&"); - genCodeLine (" jjemptyColNo[" + s_lexStates[i] + "] == input_stream->getBeginColumn())"); - genCodeLine (" errorHandler->lexicalError(JJString(\"(\"Error: Bailing out of infinite loop caused by repeated empty string matches \" + \"at line \" + input_stream->getBeginLine() + \", \" + \"column \" + input_stream->getBeginColumn() + \".\")), this);"); - genCodeLine (" jjemptyLineNo[" + s_lexStates[i] + "] = input_stream->getBeginLine();"); - genCodeLine (" jjemptyColNo[" + s_lexStates[i] + "] = input_stream->getBeginColumn();"); - genCodeLine (" jjbeenHere[" + s_lexStates[i] + "] = true;"); - genCodeLine (" }"); - } - - if ((act = s_actions[i]) == null || act.getActionTokens ().size () == 0) - { - break; - } - - genCode (" image.append"); - - if (ExpRStringLiteral.s_allImages[i] != null) - genCodeLine ("(jjstrLiteralImages[" + i + "]);"); - else - genCodeLine ("(input_stream->GetSuffix(jjimageLen));"); - - genCodeLine (" jjimageLen = 0;"); - printTokenSetup (act.getActionTokens ().get (0)); - setColToStart (); - - for (final Token t : act.getActionTokens ()) - printToken (t); - genCodeNewLine (); - - break; - } - - genCodeLine (" break;"); - genCodeLine (" }"); - } - - genCodeLine (" default :"); - genCodeLine (" break;"); - - genCodeLine (" }"); - genCodeLine ("}"); - } - - private void _dumpTokenActions () - { - ExpAction act; - int i; - - generateMethodDefHeader ("void ", s_tokMgrClassName, "TokenLexicalActions(Token *matchedToken)"); - genCodeLine ("{"); - genCodeLine (" switch(jjmatchedKind)"); - genCodeLine (" {"); - - Outer: for (i = 0; i < s_maxOrdinal; i++) - { - if ((s_toToken[i / 64] & (1L << (i % 64))) == 0L) - continue; - - for (;;) - { - if (((act = s_actions[i]) == null || act.getActionTokens () == null || act.getActionTokens ().size () == 0) && - !s_canLoop[s_lexStates[i]]) - continue Outer; - - genCodeLine (" case " + i + " : {"); - - if (s_initMatch[s_lexStates[i]] == i && s_canLoop[s_lexStates[i]]) - { - genCodeLine (" if (jjmatchedPos == -1)"); - genCodeLine (" {"); - genCodeLine (" if (jjbeenHere[" + s_lexStates[i] + "] &&"); - genCodeLine (" jjemptyLineNo[" + s_lexStates[i] + "] == input_stream->getBeginLine() &&"); - genCodeLine (" jjemptyColNo[" + s_lexStates[i] + "] == input_stream->getBeginColumn())"); - genCodeLine (" errorHandler->lexicalError(JJString(\"Error: Bailing out of infinite loop caused by repeated empty string matches " + - "at line \" + input_stream->getBeginLine() + \", " + - "column \" + input_stream->getBeginColumn() + \".\"), this);"); - genCodeLine (" jjemptyLineNo[" + s_lexStates[i] + "] = input_stream->getBeginLine();"); - genCodeLine (" jjemptyColNo[" + s_lexStates[i] + "] = input_stream->getBeginColumn();"); - genCodeLine (" jjbeenHere[" + s_lexStates[i] + "] = true;"); - genCodeLine (" }"); - } - - if ((act = s_actions[i]) == null || act.getActionTokens ().size () == 0) - break; - - if (i == 0) - { - genCodeLine (" image.setLength(0);"); // For EOF no image is - // there - } - else - { - genCode (" image.append"); - - if (ExpRStringLiteral.s_allImages[i] != null) - { - genCodeLine ("(jjstrLiteralImages[" + i + "]);"); - genCodeLine (" lengthOfMatch = jjstrLiteralImages[" + i + "].length();"); - } - else - { - genCodeLine ("(input_stream->GetSuffix(jjimageLen + (lengthOfMatch = jjmatchedPos + 1)));"); - } - } - - printTokenSetup (act.getActionTokens ().get (0)); - setColToStart (); - - for (final Token t : act.getActionTokens ()) - printToken (t); - genCodeNewLine (); - - break; - } - - genCodeLine (" break;"); - genCodeLine (" }"); - } - - genCodeLine (" default :"); - genCodeLine (" break;"); - genCodeLine (" }"); - genCodeLine ("}"); - } -} diff --git a/src/main/java/com/helger/pgcc/parser/LexGenJava.java b/src/main/java/com/helger/pgcc/parser/LexGenJava.java index ccca7c7d6..c3e5ec4b2 100644 --- a/src/main/java/com/helger/pgcc/parser/LexGenJava.java +++ b/src/main/java/com/helger/pgcc/parser/LexGenJava.java @@ -86,7 +86,6 @@ import com.helger.commons.string.StringHelper; import com.helger.pgcc.CPG; -import com.helger.pgcc.output.EOutputLanguage; import com.helger.pgcc.output.OutputHelper; import com.helger.pgcc.parser.exp.AbstractExpRegularExpression; import com.helger.pgcc.parser.exp.ExpAction; @@ -674,8 +673,6 @@ public void start () throws IOException return; } - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - ExpRStringLiteral.dumpStrLiteralImages (this); _dumpFillToken (); NfaState.dumpStateSets (this); @@ -692,10 +689,7 @@ public void start () throws IOException { genCodeLine ("int[] jjemptyLineNo = new int[" + s_maxLexStates + "];"); genCodeLine ("int[] jjemptyColNo = new int[" + s_maxLexStates + "];"); - genCodeLine (eOutputLanguage.getTypeBoolean () + - "[] jjbeenHere = new " + - eOutputLanguage.getTypeBoolean () + - "[" + + genCodeLine ("boolean[] jjbeenHere = new boolean[" + s_maxLexStates + "];"); } @@ -805,8 +799,6 @@ protected static void checkEmptyStringMatch () private void _dumpStaticVarDeclarations (final String charStreamName) throws IOException { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - genCodeNewLine (); genCodeLine ("/** Lexer state names. */"); genCodeLine ("public static final String[] lexStateNames = {"); @@ -839,7 +831,7 @@ private void _dumpStaticVarDeclarations (final String charStreamName) throws IOE { if (i % 4 == 0) genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toToken[i]) + ", "); + genCode (CodeGenerator.getLongHex (s_toToken[i]) + ", "); } genCodeLine ("\n};"); } @@ -851,7 +843,7 @@ private void _dumpStaticVarDeclarations (final String charStreamName) throws IOE { if (i % 4 == 0) genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toSkip[i]) + ", "); + genCode (CodeGenerator.getLongHex (s_toSkip[i]) + ", "); } genCodeLine ("\n};"); } @@ -863,7 +855,7 @@ private void _dumpStaticVarDeclarations (final String charStreamName) throws IOE { if (i % 4 == 0) genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toSpecial[i]) + ", "); + genCode (CodeGenerator.getLongHex (s_toSpecial[i]) + ", "); } genCodeLine ("\n};"); } @@ -875,7 +867,7 @@ private void _dumpStaticVarDeclarations (final String charStreamName) throws IOE { if (i % 4 == 0) genCode ("\n "); - genCode (eOutputLanguage.getLongHex (s_toMore[i]) + ", "); + genCode (CodeGenerator.getLongHex (s_toMore[i]) + ", "); } genCodeLine ("\n};"); } @@ -992,8 +984,6 @@ private void _dumpFillToken () private void _dumpGetNextToken () { - final EOutputLanguage eOutputLanguage = getOutputLanguage (); - genCodeNewLine (); genCodeLine ("int curLexState = " + s_defaultLexState + ";"); genCodeLine ("int defaultLexState = " + s_defaultLexState + ";"); @@ -1086,14 +1076,14 @@ private void _dumpGetNextToken () genCodeLine (prefix + " while ((curChar < 64" + " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[0]) + + CodeGenerator.getLongHex (s_singlesToSkip[i].m_asciiMoves[0]) + " & (1L << curChar)) != 0L) || \n" + prefix + " (curChar >> 6) == 1" + " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[1]) + + CodeGenerator.getLongHex (s_singlesToSkip[i].m_asciiMoves[1]) + " & (1L << (curChar & 077))) != " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + ")"); } else @@ -1103,9 +1093,9 @@ private void _dumpGetNextToken () " while (curChar <= " + (int) maxChar (s_singlesToSkip[i].m_asciiMoves[0]) + " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[0]) + + CodeGenerator.getLongHex (s_singlesToSkip[i].m_asciiMoves[0]) + " & (1L << curChar)) != " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + ")"); } else @@ -1115,9 +1105,9 @@ private void _dumpGetNextToken () " while (curChar > 63 && curChar <= " + (maxChar (s_singlesToSkip[i].m_asciiMoves[1]) + 64) + " && (" + - eOutputLanguage.getLongHex (s_singlesToSkip[i].m_asciiMoves[1]) + + CodeGenerator.getLongHex (s_singlesToSkip[i].m_asciiMoves[1]) + " & (1L << (curChar & 077))) != " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + ")"); } @@ -1365,7 +1355,7 @@ private void _dumpGetNextToken () genCodeLine (prefix + " int error_line = input_stream.getEndLine();"); genCodeLine (prefix + " int error_column = input_stream.getEndColumn();"); genCodeLine (prefix + " String error_after = null;"); - genCodeLine (prefix + " " + eOutputLanguage.getTypeBoolean () + " EOFSeen = false;"); + genCodeLine (prefix + " boolean EOFSeen = false;"); genCodeLine (prefix + " try {"); genCodeLine (prefix + " input_stream.readChar();"); genCodeLine (prefix + " input_stream.backup(1);"); diff --git a/src/main/java/com/helger/pgcc/parser/Main.java b/src/main/java/com/helger/pgcc/parser/Main.java index 504daea03..53e883a67 100644 --- a/src/main/java/com/helger/pgcc/parser/Main.java +++ b/src/main/java/com/helger/pgcc/parser/Main.java @@ -74,8 +74,6 @@ import com.helger.commons.state.ESuccess; import com.helger.pgcc.CPG; import com.helger.pgcc.PGPrinter; -import com.helger.pgcc.output.EOutputLanguage; -import com.helger.pgcc.output.cpp.OtherFilesGenCPP; import com.helger.pgcc.output.java.OtherFilesGenJava; import com.helger.pgcc.utils.EOptionType; import com.helger.pgcc.utils.OptionInfo; @@ -304,10 +302,9 @@ public static ESuccess mainProgram (final String... args) throws IOException // until the cc file has been processed. Was previously setting the 'lg' // variable to a lexer before the configuration override in the cc file // had been read. - final EOutputLanguage eOutputLanguage = Options.getOutputLanguage (); // 2013/07/22 Java Modern is a - final boolean isJavaModern = eOutputLanguage.isJava () && Options.getJavaTemplateType ().equals (Options.JAVA_TEMPLATE_TYPE_MODERN); + final boolean isJavaModern = Options.getJavaTemplateType ().equals (Options.JAVA_TEMPLATE_TYPE_MODERN); JavaCCGlobals.createOutputDir (Options.getOutputDirectory ()); @@ -326,36 +323,16 @@ public static ESuccess mainProgram (final String... args) throws IOException // and have the enumerations describe the deltas between the outputs. The // current approach means that per-langauge configuration is distributed // and small changes between targets does not benefit from inheritance. - switch (eOutputLanguage) + if (isBuildParser) { - case JAVA: - if (isBuildParser) - { - new ParseGenJava ().start (isJavaModern); - } + new ParseGenJava ().start (isJavaModern); + } - // Must always create the lexer object even if not building a parser. - new LexGenJava ().start (); + // Must always create the lexer object even if not building a parser. + new LexGenJava ().start (); - Options.setStringOption (Options.NONUSER_OPTION__PARSER_NAME, JavaCCGlobals.s_cu_name); - OtherFilesGenJava.start (isJavaModern); - break; - case CPP: - // C++ for now - if (isBuildParser) - { - new ParseGenCPP ().start (); - } - if (isBuildParser) - { - new LexGenCpp ().start (); - } - Options.setStringOption (Options.NONUSER_OPTION__PARSER_NAME, JavaCCGlobals.s_cu_name); - OtherFilesGenCPP.start (); - break; - default: - throw new IllegalStateException ("Unhandled language!"); - } + Options.setStringOption (Options.NONUSER_OPTION__PARSER_NAME, JavaCCGlobals.s_cu_name); + OtherFilesGenJava.start (isJavaModern); final int nErrors = JavaCCErrors.getErrorCount (); final int nWarnings = JavaCCErrors.getWarningCount (); diff --git a/src/main/java/com/helger/pgcc/parser/NfaState.java b/src/main/java/com/helger/pgcc/parser/NfaState.java index ec6e4c1c2..3baf75f10 100644 --- a/src/main/java/com/helger/pgcc/parser/NfaState.java +++ b/src/main/java/com/helger/pgcc/parser/NfaState.java @@ -77,8 +77,6 @@ import javax.annotation.Nullable; import com.helger.commons.string.StringHelper; -import com.helger.pgcc.output.EOutputLanguage; -import com.helger.pgcc.output.UnsupportedOutputLanguageException; /** * The state of a Non-deterministic Finite Automaton. @@ -891,7 +889,6 @@ public static int moveFromSetForRegEx (final char c, final NfaState [] states, f private void _generateNonAsciiMoves (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); int i = 0, j = 0; int cnt = 0; final long [] [] loBytes = new long [256] [4]; @@ -980,13 +977,13 @@ private void _generateNonAsciiMoves (final CodeGenerator codeGenerator) if (common != null) { String tmp = "{\n " + - eOutputLanguage.getLongHex (common[0]) + + CodeGenerator.getLongHex (common[0]) + ", " + - eOutputLanguage.getLongHex (common[1]) + + CodeGenerator.getLongHex (common[1]) + ", " + - eOutputLanguage.getLongHex (common[2]) + + CodeGenerator.getLongHex (common[2]) + ", " + - eOutputLanguage.getLongHex (common[3]) + + CodeGenerator.getLongHex (common[3]) + "\n};"; Integer ind = s_lohiByteTab.get (tmp); if (ind == null) @@ -995,18 +992,7 @@ private void _generateNonAsciiMoves (final CodeGenerator codeGenerator) if (!allBitsSet (tmp)) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("static final " + eOutputLanguage.getTypeLong () + "[] jjbitVec" + s_lohiByteCnt + " = " + tmp); - break; - case CPP: - codeGenerator.switchToStaticsFile (); - codeGenerator.genCodeLine ("static const " + eOutputLanguage.getTypeLong () + " jjbitVec" + s_lohiByteCnt + "[] = " + tmp); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("static final long[] jjbitVec" + s_lohiByteCnt + " = " + tmp); } ind = Integer.valueOf (s_lohiByteCnt++); s_lohiByteTab.put (tmp, ind); @@ -1015,13 +1001,13 @@ private void _generateNonAsciiMoves (final CodeGenerator codeGenerator) s_tmpIndices[cnt++] = ind.intValue (); tmp = "{\n " + - eOutputLanguage.getLongHex (loBytes[i][0]) + + CodeGenerator.getLongHex (loBytes[i][0]) + ", " + - eOutputLanguage.getLongHex (loBytes[i][1]) + + CodeGenerator.getLongHex (loBytes[i][1]) + ", " + - eOutputLanguage.getLongHex (loBytes[i][2]) + + CodeGenerator.getLongHex (loBytes[i][2]) + ", " + - eOutputLanguage.getLongHex (loBytes[i][3]) + + CodeGenerator.getLongHex (loBytes[i][3]) + "\n};"; ind = s_lohiByteTab.get (tmp); if (ind == null) @@ -1029,19 +1015,7 @@ private void _generateNonAsciiMoves (final CodeGenerator codeGenerator) s_allBitVectors.add (tmp); if (!allBitsSet (tmp)) - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("static final " + eOutputLanguage.getTypeLong () + "[] jjbitVec" + s_lohiByteCnt + " = " + tmp); - break; - case CPP: - codeGenerator.switchToStaticsFile (); - codeGenerator.genCodeLine ("static const " + eOutputLanguage.getTypeLong () + " jjbitVec" + s_lohiByteCnt + "[] = " + tmp); - codeGenerator.switchToMainFile (); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("static final long[] jjbitVec" + s_lohiByteCnt + " = " + tmp); ind = Integer.valueOf (s_lohiByteCnt++); s_lohiByteTab.put (tmp, ind); } @@ -1069,13 +1043,13 @@ private void _generateNonAsciiMoves (final CodeGenerator codeGenerator) { // System.out.print(i + ", "); final String tmp = "{\n " + - eOutputLanguage.getLongHex (loBytes[i][0]) + + CodeGenerator.getLongHex (loBytes[i][0]) + ", " + - eOutputLanguage.getLongHex (loBytes[i][1]) + + CodeGenerator.getLongHex (loBytes[i][1]) + ", " + - eOutputLanguage.getLongHex (loBytes[i][2]) + + CodeGenerator.getLongHex (loBytes[i][2]) + ", " + - eOutputLanguage.getLongHex (loBytes[i][3]) + + CodeGenerator.getLongHex (loBytes[i][3]) + "\n};"; Integer ind = s_lohiByteTab.get (tmp); @@ -1084,18 +1058,7 @@ private void _generateNonAsciiMoves (final CodeGenerator codeGenerator) s_allBitVectors.add (tmp); if (!allBitsSet (tmp)) - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("static final " + eOutputLanguage.getTypeLong () + "[] jjbitVec" + s_lohiByteCnt + " = " + tmp); - break; - case CPP: - codeGenerator.switchToStaticsFile (); - codeGenerator.genCodeLine ("static const " + eOutputLanguage.getTypeLong () + " jjbitVec" + s_lohiByteCnt + "[] = " + tmp); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("static final long[] jjbitVec" + s_lohiByteCnt + " = " + tmp); s_lohiByteTab.put (tmp, ind = Integer.valueOf (s_lohiByteCnt++)); } @@ -1304,20 +1267,8 @@ public int generateInitMoves () public static void dumpStateSets (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); + codeGenerator.genCode ("static final int[] jjnextStates = {"); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCode ("static final int[] jjnextStates = {"); - break; - case CPP: - codeGenerator.switchToStaticsFile (); - codeGenerator.genCode ("static const int jjnextStates[] = {"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } if (s_orderedStateSet.size () > 0) { int cnt = 0; @@ -1697,37 +1648,14 @@ private static boolean _intersect (final String set1, final String set2) private static void _dumpHeadForCase (final CodeGenerator codeGenerator, final int byteNum) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); if (byteNum == 0) { - codeGenerator.genCodeLine (" " + eOutputLanguage.getTypeLong () + " l = 1L << curChar;"); - switch (eOutputLanguage) - { - case JAVA: - // Nothing - break; - case CPP: - codeGenerator.genCodeLine (" (void)l;"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" long l = 1L << curChar;"); } else if (byteNum == 1) { - codeGenerator.genCodeLine (" " + eOutputLanguage.getTypeLong () + " l = 1L << (curChar & 077);"); - switch (eOutputLanguage) - { - case JAVA: - // Nothing - break; - case CPP: - codeGenerator.genCodeLine (" (void)l;"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" long l = 1L << (curChar & 077);"); } else { @@ -1735,11 +1663,11 @@ private static void _dumpHeadForCase (final CodeGenerator codeGenerator, final i { codeGenerator.genCodeLine (" int hiByte = (curChar >> 8);"); codeGenerator.genCodeLine (" int i1 = hiByte >> 6;"); - codeGenerator.genCodeLine (" " + eOutputLanguage.getTypeLong () + " l1 = 1L << (hiByte & 077);"); + codeGenerator.genCodeLine (" long l1 = 1L << (hiByte & 077);"); } codeGenerator.genCodeLine (" int i2 = (curChar & 0xff) >> 6;"); - codeGenerator.genCodeLine (" " + eOutputLanguage.getTypeLong () + " l2 = 1L << (curChar & 077);"); + codeGenerator.genCodeLine (" long l2 = 1L << (curChar & 077);"); } // codeGenerator.genCodeLine(" MatchLoop: do"); @@ -1950,7 +1878,6 @@ private boolean _selfLoop () private void _dumpAsciiMoveForCompositeState (final CodeGenerator codeGenerator, final int byteNum, final boolean elseNeeded) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); boolean nextIntersects = _selfLoop (); for (final NfaState temp1 : s_allStates) @@ -1982,9 +1909,9 @@ private void _dumpAsciiMoveForCompositeState (final CodeGenerator codeGenerator, codeGenerator.genCodeLine (" " + (elseNeeded ? "else " : "") + "if ((" + - eOutputLanguage.getLongHex (m_asciiMoves[byteNum]) + + CodeGenerator.getLongHex (m_asciiMoves[byteNum]) + " & l) != " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + ")"); prefix = " "; } @@ -2047,7 +1974,6 @@ private void _dumpAsciiMoveForCompositeState (final CodeGenerator codeGenerator, private void _dumpAsciiMove (final CodeGenerator codeGenerator, final int byteNum, final boolean dumped[]) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); boolean nextIntersects = _selfLoop () && m_isComposite; boolean onlyState = true; @@ -2099,9 +2025,9 @@ private void _dumpAsciiMove (final CodeGenerator codeGenerator, final int byteNu codeGenerator.genCodeLine (" if (curChar == " + (64 * byteNum + oneBit) + kindCheck + ")"); else codeGenerator.genCodeLine (" if ((" + - eOutputLanguage.getLongHex (m_asciiMoves[byteNum]) + + CodeGenerator.getLongHex (m_asciiMoves[byteNum]) + " & l) != " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + kindCheck + ")"); @@ -2129,9 +2055,9 @@ private void _dumpAsciiMove (final CodeGenerator codeGenerator, final int byteNu if (m_asciiMoves[byteNum] != 0xffffffffffffffffL) { codeGenerator.genCodeLine (" if ((" + - eOutputLanguage.getLongHex (m_asciiMoves[byteNum]) + + CodeGenerator.getLongHex (m_asciiMoves[byteNum]) + " & l) == " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + ")"); codeGenerator.genCodeLine (" break;"); } @@ -2157,9 +2083,9 @@ private void _dumpAsciiMove (final CodeGenerator codeGenerator, final int byteNu if (m_asciiMoves[byteNum] != 0xffffffffffffffffL) { codeGenerator.genCodeLine (" if ((" + - eOutputLanguage.getLongHex (m_asciiMoves[byteNum]) + + CodeGenerator.getLongHex (m_asciiMoves[byteNum]) + " & l) != " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + ")"); prefix = " "; } @@ -2646,34 +2572,9 @@ public static void dumpNonAsciiMoveMethods (final CodeGenerator codeGenerator) private void _dumpNonAsciiMoveMethod (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("private static final " + - eOutputLanguage.getTypeBoolean () + - " jjCanMove_" + - m_nonAsciiMethod + - "(int hiByte, int i1, int i2, " + - eOutputLanguage.getTypeLong () + - " l1, " + - eOutputLanguage.getTypeLong () + - " l2)"); - break; - case CPP: - codeGenerator.generateMethodDefHeader (eOutputLanguage.getTypeBoolean (), - LexGenJava.s_tokMgrClassName, - "jjCanMove_" + - m_nonAsciiMethod + - "(int hiByte, int i1, int i2, " + - eOutputLanguage.getTypeLong () + - " l1, " + - eOutputLanguage.getTypeLong () + - " l2)"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("private static final boolean jjCanMove_" + + m_nonAsciiMethod + + "(int hiByte, int i1, int i2, long l1, long l2)"); codeGenerator.genCodeLine ("{"); codeGenerator.genCodeLine (" switch(hiByte)"); codeGenerator.genCodeLine (" {"); @@ -2781,56 +2682,6 @@ static void printBoilerPlateJava (final CodeGenerator codeGenerator) } } - // private static boolean boilerPlateDumped = false; - static void printBoilerPlateCPP (final CodeGenerator codeGenerator) - { - codeGenerator.switchToIncludeFile (); - codeGenerator.genCodeLine ("#define jjCheckNAdd(state)\\"); - codeGenerator.genCodeLine ("{\\"); - codeGenerator.genCodeLine (" if (jjrounds[state] != jjround)\\"); - codeGenerator.genCodeLine (" {\\"); - codeGenerator.genCodeLine (" jjstateSet[jjnewStateCnt++] = state;\\"); - codeGenerator.genCodeLine (" jjrounds[state] = jjround;\\"); - codeGenerator.genCodeLine (" }\\"); - codeGenerator.genCodeLine ("}"); - - codeGenerator.genCodeLine ("#define jjAddStates(start, end)\\"); - codeGenerator.genCodeLine ("{\\"); - codeGenerator.genCodeLine (" for (int x = start; x <= end; x++) {\\"); - codeGenerator.genCodeLine (" jjstateSet[jjnewStateCnt++] = jjnextStates[x];\\"); - codeGenerator.genCodeLine (" } /*while (start++ != end);*/\\"); - codeGenerator.genCodeLine ("}"); - - codeGenerator.genCodeLine ("#define jjCheckNAddTwoStates(state1, state2)\\"); - codeGenerator.genCodeLine ("{\\"); - codeGenerator.genCodeLine (" jjCheckNAdd(state1);\\"); - codeGenerator.genCodeLine (" jjCheckNAdd(state2);\\"); - codeGenerator.genCodeLine ("}"); - codeGenerator.genCodeNewLine (); - - if (s_jjCheckNAddStatesDualNeeded) - { - codeGenerator.genCodeLine ("#define jjCheckNAddStates(start, end)\\"); - codeGenerator.genCodeLine ("{\\"); - codeGenerator.genCodeLine (" for (int x = start; x <= end; x++) {\\"); - codeGenerator.genCodeLine (" jjCheckNAdd(jjnextStates[x]);\\"); - codeGenerator.genCodeLine (" } /*while (start++ != end);*/\\"); - codeGenerator.genCodeLine ("}"); - codeGenerator.genCodeNewLine (); - } - - if (s_jjCheckNAddStatesUnaryNeeded) - { - codeGenerator.genCodeLine ("#define jjCheckNAddStates(start)\\"); - codeGenerator.genCodeLine ("{\\"); - codeGenerator.genCodeLine (" jjCheckNAdd(jjnextStates[start]);\\"); - codeGenerator.genCodeLine (" jjCheckNAdd(jjnextStates[start + 1]);\\"); - codeGenerator.genCodeLine ("}"); - codeGenerator.genCodeNewLine (); - } - codeGenerator.switchToMainFile (); - } - @SuppressWarnings ("unused") private static void _findStatesWithNoBreak () { @@ -2938,7 +2789,6 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) // boilerPlateDumped = true; int [] kindsForStates = null; - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); if (s_kinds == null) { @@ -2981,19 +2831,7 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) s_kinds[LexGenJava.s_lexStateIndex] = kindsForStates; - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("private int jjMoveNfa" + LexGenJava.s_lexStateSuffix + "(int startState, int curPos)"); - break; - case CPP: - codeGenerator.generateMethodDefHeader ("int", - LexGenJava.s_tokMgrClassName, - "jjMoveNfa" + LexGenJava.s_lexStateSuffix + "(int startState, int curPos)"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("private int jjMoveNfa" + LexGenJava.s_lexStateSuffix + "(int startState, int curPos)"); codeGenerator.genCodeLine ("{"); if (s_generatedStates == 0) { @@ -3007,22 +2845,10 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) codeGenerator.genCodeLine (" int strKind = jjmatchedKind;"); codeGenerator.genCodeLine (" int strPos = jjmatchedPos;"); codeGenerator.genCodeLine (" int seenUpto;"); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" input_stream.backup(seenUpto = curPos + 1);"); - codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); - // TODO do not throw error - codeGenerator.genCodeLine (" catch(final java.io.IOException e) { throw new Error(\"Internal Error\"); }"); - break; - case CPP: - codeGenerator.genCodeLine (" input_stream->backup(seenUpto = curPos + 1);"); - codeGenerator.genCodeLine (" assert(!input_stream->endOfInput());"); - codeGenerator.genCodeLine (" curChar = input_stream->readChar();"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" input_stream.backup(seenUpto = curPos + 1);"); + codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); + // TODO do not throw error + codeGenerator.genCodeLine (" catch(final java.io.IOException e) { throw new Error(\"Internal Error\"); }"); codeGenerator.genCodeLine (" curPos = 0;"); } @@ -3033,41 +2859,18 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(\" Starting NFA to match one of : \" + " + - "jjKindsForStateVector(curLexState, jjstateSet, 0, 1));"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, \" Starting NFA to match one of : %s\\n\", jjKindsForStateVector(curLexState, jjstateSet, 0, 1).c_str());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(\" Starting NFA to match one of : \" + " + + "jjKindsForStateVector(curLexState, jjstateSet, 0, 1));"); } if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(" + - (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + - "\"Current character : \" + " + - Options.getTokenMgrErrorClass () + - ".addEscapes(String.valueOf(curChar)) + \" (\" + (int)curChar + \") " + - "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, " + - "\"<%s>Current character : %c(%d) at line %d column %d\\n\"," + - "addUnicodeEscapes(lexStateNames[curLexState]).c_str(), curChar, (int)curChar, " + - "input_stream->getEndLine(), input_stream->getEndColumn());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(" + + (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + + "\"Current character : \" + " + + Options.getTokenMgrErrorClass () + + ".addEscapes(String.valueOf(curChar)) + \" (\" + (int)curChar + \") " + + "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); } codeGenerator.genCodeLine (" int kind = 0x" + Integer.toHexString (Integer.MAX_VALUE) + ";"); @@ -3107,50 +2910,28 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + Integer.toHexString (Integer.MAX_VALUE) + ")"); - codeGenerator.genCodeLine (" debugStream.println(" + - "\" Currently matched the first \" + (jjmatchedPos + 1) + \" characters as" + - " a \" + tokenImage[jjmatchedKind] + \" token.\");"); - break; - case CPP: - codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + Integer.toHexString (Integer.MAX_VALUE) + ")"); - codeGenerator.genCodeLine (" fprintf(debugStream, \" Currently matched the first %d characters as a \\\"%s\\\" token.\\n\", (jjmatchedPos + 1), addUnicodeEscapes(tokenImage[jjmatchedKind]).c_str());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + Integer.toHexString (Integer.MAX_VALUE) + ")"); + codeGenerator.genCodeLine (" debugStream.println(" + + "\" Currently matched the first \" + (jjmatchedPos + 1) + \" characters as" + + " a \" + tokenImage[jjmatchedKind] + \" token.\");"); } - switch (eOutputLanguage) + if (false) { - case JAVA: - if (false) - { - // Old - codeGenerator.genCodeLine (" if ((i = jjnewStateCnt) == (startsAt = " + - s_generatedStates + - " - (jjnewStateCnt = startsAt)))"); - } - else - { - // New - codeGenerator.genCodeLine (" i = jjnewStateCnt;"); - codeGenerator.genCodeLine (" jjnewStateCnt = startsAt;"); - codeGenerator.genCodeLine (" startsAt = " + s_generatedStates + " - jjnewStateCnt;"); - codeGenerator.genCodeLine (" if (i == startsAt)"); - } - break; - case CPP: - codeGenerator.genCodeLine (" if ((i = jjnewStateCnt), (jjnewStateCnt = startsAt), (i == (startsAt = " + - s_generatedStates + - " - startsAt)))"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); + // Old + codeGenerator.genCodeLine (" if ((i = jjnewStateCnt) == (startsAt = " + + s_generatedStates + + " - (jjnewStateCnt = startsAt)))"); } + else + { + // New + codeGenerator.genCodeLine (" i = jjnewStateCnt;"); + codeGenerator.genCodeLine (" jjnewStateCnt = startsAt;"); + codeGenerator.genCodeLine (" startsAt = " + s_generatedStates + " - jjnewStateCnt;"); + codeGenerator.genCodeLine (" if (i == startsAt)"); + } + if (LexGenJava.s_mixed[LexGenJava.s_lexStateIndex]) codeGenerator.genCodeLine (" break;"); else @@ -3158,61 +2939,24 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(\" Possible kinds of longer matches : \" + " + - "jjKindsForStateVector(curLexState, jjstateSet, startsAt, i));"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, \" Possible kinds of longer matches : %s\\n\", jjKindsForStateVector(curLexState, jjstateSet, startsAt, i).c_str());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(\" Possible kinds of longer matches : \" + " + + "jjKindsForStateVector(curLexState, jjstateSet, startsAt, i));"); } - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); - if (LexGenJava.s_mixed[LexGenJava.s_lexStateIndex]) - codeGenerator.genCodeLine (" catch(final java.io.IOException e) { break; }"); - else - codeGenerator.genCodeLine (" catch(final java.io.IOException e) { return curPos; }"); - break; - case CPP: - if (LexGenJava.s_mixed[LexGenJava.s_lexStateIndex]) - codeGenerator.genCodeLine (" if (input_stream->endOfInput()) { break; }"); - else - codeGenerator.genCodeLine (" if (input_stream->endOfInput()) { return curPos; }"); - codeGenerator.genCodeLine (" curChar = input_stream->readChar();"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); + if (LexGenJava.s_mixed[LexGenJava.s_lexStateIndex]) + codeGenerator.genCodeLine (" catch(final java.io.IOException e) { break; }"); + else + codeGenerator.genCodeLine (" catch(final java.io.IOException e) { return curPos; }"); if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(" + - (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + - "\"Current character : \" + " + - Options.getTokenMgrErrorClass () + - ".addEscapes(String.valueOf(curChar)) + \" (\" + (int)curChar + \") " + - "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, " + - "\"<%s>Current character : %c(%d) at line %d column %d\\n\"," + - "addUnicodeEscapes(lexStateNames[curLexState]).c_str(), curChar, (int)curChar, " + - "input_stream->getEndLine(), input_stream->getEndColumn());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(" + + (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + + "\"Current character : \" + " + + Options.getTokenMgrErrorClass () + + ".addEscapes(String.valueOf(curChar)) + \" (\" + (int)curChar + \") " + + "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); } codeGenerator.genCodeLine (" }"); @@ -3222,35 +2966,13 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) codeGenerator.genCodeLine (" if (jjmatchedPos > strPos)"); codeGenerator.genCodeLine (" return curPos;"); codeGenerator.genCodeNewLine (); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" int toRet = Math.max(curPos, seenUpto);"); - break; - case CPP: - codeGenerator.genCodeLine (" int toRet = MAX(curPos, seenUpto);"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" int toRet = Math.max(curPos, seenUpto);"); codeGenerator.genCodeNewLine (); codeGenerator.genCodeLine (" if (curPos < toRet)"); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" for (i = toRet - Math.min(curPos, seenUpto); i-- > 0; )"); - codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); - // TODO do not throw error - codeGenerator.genCodeLine (" catch(final java.io.IOException e) { throw new Error(\"Internal Error : Please send a bug report.\"); }"); - break; - case CPP: - codeGenerator.genCodeLine (" for (i = toRet - MIN(curPos, seenUpto); i-- > 0; )"); - codeGenerator.genCodeLine (" { assert(!input_stream->endOfInput());"); - codeGenerator.genCodeLine (" curChar = input_stream->readChar(); }"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" for (i = toRet - Math.min(curPos, seenUpto); i-- > 0; )"); + codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); + // TODO do not throw error + codeGenerator.genCodeLine (" catch(final java.io.IOException e) { throw new Error(\"Internal Error : Please send a bug report.\"); }"); codeGenerator.genCodeNewLine (); codeGenerator.genCodeLine (" if (jjmatchedPos < strPos)"); codeGenerator.genCodeLine (" {"); @@ -3268,71 +2990,6 @@ public static void dumpMoveNfa (final CodeGenerator codeGenerator) s_allStates.clear (); } - public static void dumpStatesForStateCPP (final CodeGenerator codeGenerator) - { - if (s_statesForState == null) - { - assert (false) : "This should never be null."; - codeGenerator.genCodeLine ("null;"); - return; - } - - codeGenerator.switchToStaticsFile (); - for (int i = 0; i < LexGenJava.s_maxLexStates; i++) - { - if (s_statesForState[i] == null) - { - continue; - } - - for (int j = 0; j < s_statesForState[i].length; j++) - { - final int [] stateSet = s_statesForState[i][j]; - - codeGenerator.genCode ("const int stateSet_" + i + "_" + j + "[" + LexGenJava.s_stateSetSize + "] = "); - if (stateSet == null) - { - codeGenerator.genCodeLine (" { " + j + " };"); - continue; - } - - codeGenerator.genCode (" { "); - - for (final int aElement : stateSet) - codeGenerator.genCode (aElement + ", "); - - codeGenerator.genCodeLine ("};"); - } - - } - - for (int i = 0; i < LexGenJava.s_maxLexStates; i++) - { - codeGenerator.genCodeLine ("const int *stateSet_" + i + "[] = {"); - if (s_statesForState[i] == null) - { - codeGenerator.genCodeLine (" NULL, "); - codeGenerator.genCodeLine ("};"); - continue; - } - - for (int j = 0; j < s_statesForState[i].length; j++) - { - codeGenerator.genCode ("stateSet_" + i + "_" + j + ","); - } - codeGenerator.genCodeLine ("};"); - } - - codeGenerator.genCode ("const int** statesForState[] = { "); - for (int i = 0; i < LexGenJava.s_maxLexStates; i++) - { - codeGenerator.genCodeLine ("stateSet_" + i + ", "); - } - - codeGenerator.genCodeLine ("\n};"); - codeGenerator.switchToMainFile (); - } - public static void dumpStatesForStateJava (final CodeGenerator codeGenerator) { codeGenerator.genCodeLine ("protected static final class States {"); @@ -3382,34 +3039,12 @@ public static void dumpStatesForStateJava (final CodeGenerator codeGenerator) public static void dumpStatesForKind (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - dumpStatesForStateJava (codeGenerator); - break; - case CPP: - dumpStatesForStateCPP (codeGenerator); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + dumpStatesForStateJava (codeGenerator); boolean moreThanOne = false; int cnt = 0; - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("protected static final class Kinds {"); - codeGenerator.genCode (" protected static final int[][] kindForState = "); - break; - case CPP: - codeGenerator.switchToStaticsFile (); - codeGenerator.genCode ("static const int kindForState[" + LexGenJava.s_stateSetSize + "][" + LexGenJava.s_stateSetSize + "] = "); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("protected static final class Kinds {"); + codeGenerator.genCode (" protected static final int[][] kindForState = "); if (s_kinds == null) { @@ -3448,18 +3083,8 @@ public static void dumpStatesForKind (final CodeGenerator codeGenerator) codeGenerator.genCodeLine ("\n};"); } - switch (eOutputLanguage) - { - case JAVA: - // Close class - codeGenerator.genCode ("}"); - break; - case CPP: - // empty - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + // Close class + codeGenerator.genCode ("}"); codeGenerator.switchToMainFile (); } diff --git a/src/main/java/com/helger/pgcc/parser/Options.java b/src/main/java/com/helger/pgcc/parser/Options.java index 589d6ee7c..6bbf9834a 100644 --- a/src/main/java/com/helger/pgcc/parser/Options.java +++ b/src/main/java/com/helger/pgcc/parser/Options.java @@ -74,7 +74,6 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.StringTokenizer; import java.util.TreeSet; import javax.annotation.Nonnull; @@ -87,8 +86,6 @@ import com.helger.commons.system.SystemHelper; import com.helger.pgcc.EJDKVersion; import com.helger.pgcc.PGPrinter; -import com.helger.pgcc.output.EOutputLanguage; -import com.helger.pgcc.output.UnsupportedOutputLanguageException; import com.helger.pgcc.utils.EOptionType; import com.helger.pgcc.utils.OptionInfo; @@ -119,7 +116,6 @@ protected Options () public static final String USEROPTION__PARSER_SUPER_CLASS = "PARSER_SUPER_CLASS"; public static final String USEROPTION__JAVA_TEMPLATE_TYPE = "JAVA_TEMPLATE_TYPE"; public static final String USEROPTION__GENERATE_BOILERPLATE = "GENERATE_BOILERPLATE"; - public static final String USEROPTION__OUTPUT_LANGUAGE = "OUTPUT_LANGUAGE"; public static final String USEROPTION__PARSER_CODE_GENERATOR = "PARSER_CODE_GENERATOR"; public static final String USEROPTION__TOKEN_MANAGER_CODE_GENERATOR = "TOKEN_MANAGER_CODE_GENERATOR"; public static final String USEROPTION__NO_DFA = "NO_DFA"; @@ -153,20 +149,6 @@ protected Options () public static final String USEROPTION__TOKEN_EXTENDS = "TOKEN_EXTENDS"; public static final String USEROPTION__DEPTH_LIMIT = "DEPTH_LIMIT"; - public static final String USEROPTION__CPP_NAMESPACE = "NAMESPACE"; - public static final String USEROPTION__CPP_TOKEN_INCLUDES = "TOKEN_INCLUDES"; - public static final String USEROPTION__CPP_PARSER_INCLUDES = "PARSER_INCLUDES"; - public static final String USEROPTION__CPP_IGNORE_ACTIONS = "IGNORE_ACTIONS"; - public static final String USEROPTION__CPP_TOKEN_MANAGER_INCLUDES = "TOKEN_MANAGER_INCLUDES"; - public static final String USEROPTION__CPP_TOKEN_MANAGER_SUPERCLASS = "TOKEN_MANAGER_SUPERCLASS"; - public static final String USEROPTION__CPP_STOP_ON_FIRST_ERROR = "STOP_ON_FIRST_ERROR"; - public static final String USEROPTION__CPP_STACK_LIMIT = "STACK_LIMIT"; - - public static final String USEROPTION__CPP_TOKEN_INCLUDE = "TOKEN_INCLUDE"; - public static final String USEROPTION__CPP_PARSER_INCLUDE = "PARSER_INCLUDE"; - - private static EOutputLanguage s_language = EOutputLanguage.JAVA; - /** * 2013/07/22 -- GWT Compliant Output -- no external dependencies on GWT, but * generated code adds loose coupling to IO, for 6.1 release, this is opt-in, @@ -227,21 +209,10 @@ protected Options () temp.add (new OptionInfo (USEROPTION__TOKEN_FACTORY, EOptionType.STRING, "")); temp.add (new OptionInfo (USEROPTION__GRAMMAR_ENCODING, EOptionType.STRING, "")); temp.add (new OptionInfo (USEROPTION__OUTPUT_ENCODING, EOptionType.STRING, StandardCharsets.UTF_8.name ())); - s_language = EOutputLanguage.JAVA; - temp.add (new OptionInfo (USEROPTION__OUTPUT_LANGUAGE, EOptionType.STRING, s_language.getID ())); temp.add (new OptionInfo (USEROPTION__JAVA_TEMPLATE_TYPE, EOptionType.STRING, JAVA_TEMPLATE_TYPE_CLASSIC)); - temp.add (new OptionInfo (USEROPTION__CPP_NAMESPACE, EOptionType.STRING, "")); - temp.add (new OptionInfo (USEROPTION__CPP_TOKEN_INCLUDES, EOptionType.STRING, "")); - temp.add (new OptionInfo (USEROPTION__CPP_PARSER_INCLUDES, EOptionType.STRING, "")); - - temp.add (new OptionInfo (USEROPTION__CPP_TOKEN_MANAGER_INCLUDES, EOptionType.STRING, "")); - temp.add (new OptionInfo (USEROPTION__CPP_IGNORE_ACTIONS, EOptionType.BOOLEAN, Boolean.FALSE)); - temp.add (new OptionInfo (USEROPTION__CPP_STOP_ON_FIRST_ERROR, EOptionType.BOOLEAN, Boolean.FALSE)); - temp.add (new OptionInfo (USEROPTION__CPP_TOKEN_MANAGER_SUPERCLASS, EOptionType.STRING, "")); temp.add (new OptionInfo (USEROPTION__DEPTH_LIMIT, EOptionType.INTEGER, Integer.valueOf (0))); - temp.add (new OptionInfo (USEROPTION__CPP_STACK_LIMIT, EOptionType.STRING, "")); s_userOptions = Collections.unmodifiableSet (temp); } @@ -265,8 +236,6 @@ public static void init () for (final OptionInfo t : s_userOptions) s_optionValues.put (t.getName (), t.getDefault ()); - - s_language = EOutputLanguage.JAVA; } @Nullable @@ -364,15 +333,7 @@ public static String getOptionsString (final String [] interestingOptions) @Nonempty public static String getTokenMgrErrorClass () { - switch (s_language) - { - case JAVA: - return "TokenMgrException"; - case CPP: - return "TokenMgrError"; - default: - throw new UnsupportedOutputLanguageException (s_language); - } + return "TokenMgrException"; } /** @@ -492,29 +453,6 @@ public static void setInputFileOption (final Object nameloc, return; } } - else - if (sNameUC.equalsIgnoreCase (USEROPTION__OUTPUT_LANGUAGE)) - { - final String outputLanguage = (String) aRealSrc; - final EOutputLanguage eOutLanguage = EOutputLanguage.getFromIDCaseInsensitiveOrNull (outputLanguage); - if (eOutLanguage == null) - { - JavaCCErrors.warning (valueloc, - "Bad option value \"" + - aRealSrc + - "\" for \"" + - name + - "\". Option setting will be ignored. Valid options are: " + - StringHelper.getImplodedMapped (", ", EOutputLanguage.values (), EOutputLanguage::getID)); - return; - } - s_language = eOutLanguage; - } - else - if (sNameUC.equalsIgnoreCase (USEROPTION__CPP_NAMESPACE)) - { - processCPPNamespaceOption ((String) aRealSrc); - } } /** @@ -641,10 +579,6 @@ public static void setCmdLineOption (@Nonnull final String sArg) s_optionValues.put (sNameUC, val); s_cmdLineSetting.add (sNameUC); - if (sNameUC.equalsIgnoreCase (USEROPTION__CPP_NAMESPACE)) - { - processCPPNamespaceOption ((String) val); - } } public static void normalize () @@ -997,12 +931,6 @@ private static boolean _isValidJavaTemplateType (@Nullable final String sType) return sType == null ? false : s_aSupportedJavaTemplateTypes.contains (sType.toLowerCase (Locale.US)); } - @Nonnull - public static EOutputLanguage getOutputLanguage () - { - return s_language; - } - public static String getJavaTemplateType () { return stringValue (USEROPTION__JAVA_TEMPLATE_TYPE); @@ -1011,30 +939,6 @@ public static String getJavaTemplateType () public static void setStringOption (final String optionName, final String optionValue) { s_optionValues.put (optionName, optionValue); - if (optionName.equalsIgnoreCase (USEROPTION__CPP_NAMESPACE)) - { - processCPPNamespaceOption (optionValue); - } - } - - public static void processCPPNamespaceOption (final String optionValue) - { - final String ns = optionValue; - if (ns.length () > 0) - { - // We also need to split it. - final StringTokenizer st = new StringTokenizer (ns, "::"); - String expanded_ns = st.nextToken () + " {"; - String ns_close = "}"; - while (st.hasMoreTokens ()) - { - expanded_ns = expanded_ns + "\nnamespace " + st.nextToken () + " {"; - ns_close = ns_close + "\n}"; - } - s_optionValues.put (NONUSER_OPTION__NAMESPACE_OPEN, expanded_ns); - s_optionValues.put (NONUSER_OPTION__HAS_NAMESPACE, Boolean.TRUE); - s_optionValues.put (NONUSER_OPTION__NAMESPACE_CLOSE, ns_close); - } } public static boolean isTokenManagerRequiresParserAccess () @@ -1057,24 +961,6 @@ public static boolean hasDepthLimit () return getDepthLimit () > 0; } - /** - * Get defined parser stack usage limit. - * - * @return The requested stack usage limit. - */ - public static String getCPPStackLimit () - { - final String limit = stringValue (USEROPTION__CPP_STACK_LIMIT); - if (limit.equals ("0")) - return ""; - return limit; - } - - public static boolean hasCPPStackLimit () - { - return StringHelper.hasText (getCPPStackLimit ()); - } - /** * Gets all the user options (in order) * diff --git a/src/main/java/com/helger/pgcc/parser/ParseEngine.java b/src/main/java/com/helger/pgcc/parser/ParseEngine.java index 99c54f474..2cce9bac8 100644 --- a/src/main/java/com/helger/pgcc/parser/ParseEngine.java +++ b/src/main/java/com/helger/pgcc/parser/ParseEngine.java @@ -66,7 +66,6 @@ import static com.helger.pgcc.parser.JavaCCGlobals.BNF_PRODUCTIONS; import static com.helger.pgcc.parser.JavaCCGlobals.s_ccol; import static com.helger.pgcc.parser.JavaCCGlobals.s_cline; -import static com.helger.pgcc.parser.JavaCCGlobals.s_cu_name; import static com.helger.pgcc.parser.JavaCCGlobals.s_jj2index; import static com.helger.pgcc.parser.JavaCCGlobals.MASK_VALS; import static com.helger.pgcc.parser.JavaCCGlobals.s_maskindex; @@ -85,8 +84,6 @@ import com.helger.commons.collection.impl.ICommonsMap; import com.helger.commons.string.StringHelper; import com.helger.pgcc.PGPrinter; -import com.helger.pgcc.output.EOutputLanguage; -import com.helger.pgcc.output.UnsupportedOutputLanguageException; import com.helger.pgcc.parser.exp.AbstractExpRegularExpression; import com.helger.pgcc.parser.exp.ExpAction; import com.helger.pgcc.parser.exp.ExpChoice; @@ -360,7 +357,6 @@ String buildLookaheadChecker (final ExpLookahead [] conds, final String [] actio Token t = null; final int tokenMaskSize = (s_tokenCount - 1) / 32 + 1; int [] tokenMask = null; - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); // Iterate over all the conditions. int index = 0; @@ -465,17 +461,7 @@ String buildLookaheadChecker (final ExpLookahead [] conds, final String [] actio retval += "\n" + "switch ("; if (Options.isCacheTokens ()) { - switch (eOutputLanguage) - { - case JAVA: - retval += "jj_nt.kind"; - break; - case CPP: - retval += "jj_nt->kind"; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + retval += "jj_nt.kind"; } else retval += "jj_ntk == -1 ? jj_ntk_f() : jj_ntk"; @@ -672,305 +658,84 @@ void dumpFormattedString (final String str) } } - // Print CPPCODE method header. - private String _generateCPPMethodheader (final CodeProductionCpp p) + private void _genStackCheck (final boolean voidReturn) { - final StringBuilder sig = new StringBuilder (); - String ret, params; - Token t = null; - - if (false) - { - m_codeGenerator.printTokenSetup (t); - s_ccol = 1; - final String comment1 = m_codeGenerator.getLeadingComments (t); - s_cline = t.beginLine; - s_ccol = t.beginColumn; - sig.append (t.image); - } - - for (final Token element : p.getReturnTypeTokens ()) + if (Options.hasDepthLimit ()) { - t = element; - final String s = m_codeGenerator.getStringToPrint (t); - sig.append (t.toString ()); - sig.append (" "); + m_codeGenerator.genCodeLine ("if(++jj_depth > " + Options.getDepthLimit () + ") {"); + m_codeGenerator.genCodeLine (" jj_consume_token(-1);"); + m_codeGenerator.genCodeLine (" throw new ParseException();"); + m_codeGenerator.genCodeLine ("}"); + m_codeGenerator.genCodeLine ("try {"); } + } - String comment2 = ""; - if (t != null) - comment2 = m_codeGenerator.getTrailingComments (t); - ret = sig.toString (); - - sig.setLength (0); - sig.append ("("); - if (p.getParameterListTokens ().size () != 0) + void genStackCheckEnd () + { + if (Options.hasDepthLimit ()) { - m_codeGenerator.printTokenSetup (p.getParameterListTokens ().get (0)); - for (final Token aElement : p.getParameterListTokens ()) - { - t = aElement; - sig.append (m_codeGenerator.getStringToPrint (t)); - } - sig.append (m_codeGenerator.getTrailingComments (t)); + m_codeGenerator.genCodeLine (" } finally {"); + m_codeGenerator.genCodeLine (" --jj_depth;"); + m_codeGenerator.genCodeLine (" }"); } - sig.append (")"); - params = sig.toString (); - - // For now, just ignore comments - m_codeGenerator.generateMethodDefHeader (ret, s_cu_name, p.getLhs () + params, sig.toString ()); - - return ""; } - // Print method header and return the ERROR_RETURN string. - private String _generateCPPMethodheader (final BNFProduction p, final Token t2) + void buildPhase1Routine (final BNFProduction p) { - final StringBuilder sig = new StringBuilder (); - Token t = t2; - - final String method_name = p.getLhs (); - boolean void_ret = false; - boolean ptr_ret = false; - + Token t = p.getReturnTypeTokens ().get (0); + boolean voidReturn = false; + if (t.kind == JavaCCParserConstants.VOID) + { + voidReturn = true; + } m_codeGenerator.printTokenSetup (t); s_ccol = 1; - final String comment1 = m_codeGenerator.getLeadingComments (t); + m_codeGenerator.printLeadingComments (t); + m_codeGenerator.genCode (" final " + (p.getAccessMod () != null ? p.getAccessMod () : "public") + " "); s_cline = t.beginLine; s_ccol = t.beginColumn; - sig.append (t.image); - if (t.kind == JavaCCParserConstants.VOID) - void_ret = true; - if (t.kind == JavaCCParserConstants.STAR) - ptr_ret = true; - + m_codeGenerator.printTokenOnly (t); for (int i = 1; i < p.getReturnTypeTokens ().size (); i++) { t = p.getReturnTypeTokens ().get (i); - sig.append (m_codeGenerator.getStringToPrint (t)); - if (t.kind == JavaCCParserConstants.VOID) - void_ret = true; - if (t.kind == JavaCCParserConstants.STAR) - ptr_ret = true; + m_codeGenerator.printToken (t); } - - final String comment2 = m_codeGenerator.getTrailingComments (t); - final String ret = sig.toString (); - - sig.setLength (0); - sig.append ("("); + m_codeGenerator.printTrailingComments (t); + m_codeGenerator.genCode (" " + p.getLhs () + "("); if (p.getParameterListTokens ().size () != 0) { - m_codeGenerator.printTokenSetup (p.getParameterListTokens ().get (0)); + m_codeGenerator.printTokenSetup ((p.getParameterListTokens ().get (0))); for (final Token aElement : p.getParameterListTokens ()) { t = aElement; - sig.append (m_codeGenerator.getStringToPrint (t)); - } - sig.append (m_codeGenerator.getTrailingComments (t)); - } - sig.append (")"); - final String params = sig.toString (); - - // For now, just ignore comments - m_codeGenerator.generateMethodDefHeader (ret, s_cu_name, p.getLhs () + params, sig.toString ()); - - // Generate a default value for error return. - String default_return; - if (ptr_ret) - default_return = "NULL"; - else - if (void_ret) - default_return = ""; - else - { - // 0 converts to most (all?) basic types. - default_return = "0"; - } - - final String sDefine = "ERROR_RET_" + method_name; - return "\n#if !defined " + - sDefine + - "\n#define " + - sDefine + - " " + - default_return + - "\n" + - "#endif\n" + - "#define __ERROR_RET__ " + - sDefine + - "\n"; - } - - private void _genStackCheck (final boolean voidReturn) - { - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); - if (Options.hasDepthLimit ()) - { - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine ("if(++jj_depth > " + Options.getDepthLimit () + ") {"); - m_codeGenerator.genCodeLine (" jj_consume_token(-1);"); - m_codeGenerator.genCodeLine (" throw new ParseException();"); - m_codeGenerator.genCodeLine ("}"); - m_codeGenerator.genCodeLine ("try {"); - break; - case CPP: - if (!voidReturn) - { - m_codeGenerator.genCodeLine ("if(jj_depth_error){ return __ERROR_RET__; }"); - } - else - { - m_codeGenerator.genCodeLine ("if(jj_depth_error){ return; }"); - } - m_codeGenerator.genCodeLine ("__jj_depth_inc __jj_depth_counter(this);"); - m_codeGenerator.genCodeLine ("if(jj_depth > " + Options.getDepthLimit () + ") {"); - m_codeGenerator.genCodeLine (" jj_depth_error = true;"); - m_codeGenerator.genCodeLine (" jj_consume_token(-1);"); - m_codeGenerator.genCodeLine (" errorHandler->handleParseError(token, getToken(1), __FUNCTION__, this), hasError = true;"); - if (!voidReturn) - { - // Non-recoverable error - m_codeGenerator.genCodeLine (" return __ERROR_RET__;"); - } - else - { - // Non-recoverable error - m_codeGenerator.genCodeLine (" return;"); - } - m_codeGenerator.genCodeLine ("}"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } - } - } - - void genStackCheckEnd () - { - if (Options.hasDepthLimit ()) - { - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine (" } finally {"); - m_codeGenerator.genCodeLine (" --jj_depth;"); - m_codeGenerator.genCodeLine (" }"); - break; - case CPP: - // Nothing; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); + m_codeGenerator.printToken (t); } + m_codeGenerator.printTrailingComments (t); } - } + m_codeGenerator.genCode (")"); + m_codeGenerator.genCode (" throws ParseException"); - void buildPhase1Routine (final BNFProduction p) - { - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); - Token t = p.getReturnTypeTokens ().get (0); - boolean voidReturn = false; - if (t.kind == JavaCCParserConstants.VOID) + for (final List name : p.getThrowsList ()) { - voidReturn = true; - } - String error_ret_cpp = null; - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.printTokenSetup (t); - s_ccol = 1; - m_codeGenerator.printLeadingComments (t); - m_codeGenerator.genCode (" final " + (p.getAccessMod () != null ? p.getAccessMod () : "public") + " "); - s_cline = t.beginLine; - s_ccol = t.beginColumn; - m_codeGenerator.printTokenOnly (t); - for (int i = 1; i < p.getReturnTypeTokens ().size (); i++) - { - t = p.getReturnTypeTokens ().get (i); - m_codeGenerator.printToken (t); - } - m_codeGenerator.printTrailingComments (t); - m_codeGenerator.genCode (" " + p.getLhs () + "("); - if (p.getParameterListTokens ().size () != 0) - { - m_codeGenerator.printTokenSetup ((p.getParameterListTokens ().get (0))); - for (final Token aElement : p.getParameterListTokens ()) - { - t = aElement; - m_codeGenerator.printToken (t); - } - m_codeGenerator.printTrailingComments (t); - } - m_codeGenerator.genCode (")"); - m_codeGenerator.genCode (" throws ParseException"); - - for (final List name : p.getThrowsList ()) - { - m_codeGenerator.genCode (", "); - for (final Token t2 : name) - m_codeGenerator.genCode (t2.image); - } - break; - case CPP: - error_ret_cpp = _generateCPPMethodheader (p, t); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); + m_codeGenerator.genCode (", "); + for (final Token t2 : name) + m_codeGenerator.genCode (t2.image); } m_codeGenerator.genCode (" {"); - switch (eOutputLanguage) - { - case JAVA: - // Nothing - break; - case CPP: - if ((Options.booleanValue (Options.USEROPTION__CPP_STOP_ON_FIRST_ERROR) && error_ret_cpp != null) || - (Options.hasDepthLimit () && !voidReturn)) - { - m_codeGenerator.genCode (error_ret_cpp); - } - else - { - error_ret_cpp = null; - } - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } _genStackCheck (voidReturn); m_nIndentCount = 4; if (Options.isDebugParser ()) { m_codeGenerator.genCodeNewLine (); - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine (" trace_call(\"" + JavaCCGlobals.addUnicodeEscapes (p.getLhs ()) + "\");"); - break; - case CPP: - m_codeGenerator.genCodeLine (" JJEnter> jjenter([this]() {trace_call (\"" + - JavaCCGlobals.addUnicodeEscapes (p.getLhs ()) + - "\"); });"); - m_codeGenerator.genCodeLine (" JJExit > jjexit ([this]() {trace_return(\"" + - JavaCCGlobals.addUnicodeEscapes (p.getLhs ()) + - "\"); });"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + m_codeGenerator.genCodeLine (" trace_call(\"" + JavaCCGlobals.addUnicodeEscapes (p.getLhs ()) + "\");"); m_codeGenerator.genCodeLine (" try {"); m_nIndentCount += 2; } - if (!Options.booleanValue (Options.USEROPTION__CPP_IGNORE_ACTIONS) && p.getDeclarationTokens ().size () != 0) + if (p.getDeclarationTokens ().size () != 0) { m_codeGenerator.printTokenSetup (p.getDeclarationTokens ().get (0)); s_cline--; @@ -988,54 +753,16 @@ void buildPhase1Routine (final BNFProduction p) if (p.isJumpPatched () && !voidReturn) { - switch (eOutputLanguage) - { - case JAVA: - // This line is required for Java! - m_codeGenerator.genCodeLine (" throw new IllegalStateException (\"Missing return statement in function\");"); - break; - case CPP: - m_codeGenerator.genCodeLine (" throw \"Missing return statement in function\";"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + // This line is required for Java! + m_codeGenerator.genCodeLine (" throw new IllegalStateException (\"Missing return statement in function\");"); } if (Options.isDebugParser ()) { - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine (" } finally {"); - m_codeGenerator.genCodeLine (" trace_return(\"" + JavaCCGlobals.addUnicodeEscapes (p.getLhs ()) + "\");"); - m_codeGenerator.genCodeLine (" }"); - break; - case CPP: - m_codeGenerator.genCodeLine (" } catch(...) { }"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } - } - if (!voidReturn) - { - switch (eOutputLanguage) - { - case JAVA: - // Nothing - break; - case CPP: - m_codeGenerator.genCodeLine ("assert(false);"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + m_codeGenerator.genCodeLine (" } finally {"); + m_codeGenerator.genCodeLine (" trace_return(\"" + JavaCCGlobals.addUnicodeEscapes (p.getLhs ()) + "\");"); + m_codeGenerator.genCodeLine (" }"); } - if (error_ret_cpp != null) - { - m_codeGenerator.genCodeLine ("\n#undef __ERROR_RET__\n"); - } genStackCheckEnd (); m_codeGenerator.genCodeLine ("}"); m_codeGenerator.genCodeNewLine (); @@ -1053,7 +780,6 @@ private String _phase1ExpansionGen (final Expansion e) Token t = null; ExpLookahead [] conds; String [] actions; - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); if (e instanceof AbstractExpRegularExpression) { final AbstractExpRegularExpression e_nrw = (AbstractExpRegularExpression) e; @@ -1073,17 +799,7 @@ private String _phase1ExpansionGen (final Expansion e) if (e_nrw.getRhsToken () == null) tail = ");"; else - switch (eOutputLanguage) - { - case JAVA: - tail = ")." + e_nrw.getRhsToken ().image + ";"; - break; - case CPP: - tail = ")->" + e_nrw.getRhsToken ().image + ";"; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + tail = ")." + e_nrw.getRhsToken ().image + ";"; if (e_nrw.hasLabel ()) { @@ -1101,21 +817,6 @@ private String _phase1ExpansionGen (final Expansion e) retval += "jj_consume_token(" + e_nrw.getOrdinal () + tail; } } - - switch (eOutputLanguage) - { - case JAVA: - // Nothing - break; - case CPP: - if (Options.booleanValue (Options.USEROPTION__CPP_STOP_ON_FIRST_ERROR)) - { - retval += "\n { if (hasError) { return __ERROR_RET__; } }\n"; - } - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } } else if (e instanceof ExpNonTerminal) @@ -1145,27 +846,13 @@ private String _phase1ExpansionGen (final Expansion e) retval += m_codeGenerator.getTrailingComments (t); } retval += ");"; - switch (eOutputLanguage) - { - case JAVA: - // Nothing - break; - case CPP: - if (Options.booleanValue (Options.USEROPTION__CPP_STOP_ON_FIRST_ERROR)) - { - retval += "\n { if (hasError) { return __ERROR_RET__; } }\n"; - } - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } } else if (e instanceof ExpAction) { final ExpAction e_nrw = (ExpAction) e; retval += INDENT_OFF + "\n"; - if (!Options.booleanValue (Options.USEROPTION__CPP_IGNORE_ACTIONS) && e_nrw.getActionTokens ().size () != 0) + if (e_nrw.getActionTokens ().size () != 0) { m_codeGenerator.printTokenSetup (e_nrw.getActionTokens ().get (0)); s_ccol = 1; @@ -1186,20 +873,7 @@ private String _phase1ExpansionGen (final Expansion e) actions = new String [e_nrw.getChoiceCount () + 1]; String sChoice; - switch (eOutputLanguage) - { - case JAVA: - sChoice = "\n" + "jj_consume_token(-1);\n" + "throw new ParseException();"; - break; - case CPP: - sChoice = "\n" + - "jj_consume_token(-1);\n" + - "errorHandler->handleParseError(token, getToken(1), __FUNCTION__, this), hasError = true;" + - (Options.booleanValue (Options.USEROPTION__CPP_STOP_ON_FIRST_ERROR) ? "return __ERROR_RET__;\n" : ""); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + sChoice = "\n" + "jj_consume_token(-1);\n" + "throw new ParseException();"; actions[e_nrw.getChoiceCount ()] = sChoice; // In previous line, the "throw" never throws an exception since the @@ -1223,30 +897,8 @@ private String _phase1ExpansionGen (final Expansion e) for (int i = 1; i < e_nrw.getUnitCount (); i++) { // For C++, since we are not using exceptions, we will protect - // all the - // expansion choices with if (!error) + // all the expansion choices with if (!error) boolean wrap_in_block = false; - if (!JavaCCGlobals.s_jjtreeGenerated) - { - switch (eOutputLanguage) - { - case JAVA: - // nothing - break; - case CPP: - // for the last one, if it's an action, we will not - // protect it. - final Expansion elem = e_nrw.getUnitAt (i); - if (!(elem instanceof ExpAction) || !(e.getParent () instanceof BNFProduction) || i != e_nrw.getUnitCount () - 1) - { - wrap_in_block = true; - retval += "\nif (!hasError) {"; - } - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } - } retval += _phase1ExpansionGen (e_nrw.getUnitAt (i)); if (wrap_in_block) { @@ -1272,19 +924,8 @@ private String _phase1ExpansionGen (final Expansion e) } retval += "\n"; final int labelIndex = ++m_nGenSymbolIndex; - switch (eOutputLanguage) - { - case JAVA: - retval += "label_" + labelIndex + ":\n"; - retval += "while (true) {" + INDENT_INC; - break; - case CPP: - // nothing - retval += "while (!hasError) {" + INDENT_INC; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + retval += "label_" + labelIndex + ":\n"; + retval += "while (true) {" + INDENT_INC; retval += _phase1ExpansionGen (nested_e); conds = new ExpLookahead [1]; conds[0] = la; @@ -1292,32 +933,10 @@ private String _phase1ExpansionGen (final Expansion e) // [ph] empty statement needed??? actions[0] = true ? "" : "\n;"; - switch (eOutputLanguage) - { - case JAVA: - actions[1] = "\nbreak label_" + labelIndex + ";"; - break; - case CPP: - actions[1] = "\ngoto end_label_" + labelIndex + ";"; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + actions[1] = "\nbreak label_" + labelIndex + ";"; retval += buildLookaheadChecker (conds, actions); retval += INDENT_DEC + "\n" + "}"; - - switch (eOutputLanguage) - { - case JAVA: - // nothing - break; - case CPP: - retval += "\nend_label_" + labelIndex + ": ;"; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } } else if (e instanceof ExpZeroOrMore) @@ -1337,19 +956,8 @@ private String _phase1ExpansionGen (final Expansion e) } retval += "\n"; final int labelIndex = ++m_nGenSymbolIndex; - switch (eOutputLanguage) - { - case JAVA: - retval += "label_" + labelIndex + ":\n"; - retval += "while (true) {" + INDENT_INC; - break; - case CPP: - // nothing - retval += "while (!hasError) {" + INDENT_INC; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + retval += "label_" + labelIndex + ":\n"; + retval += "while (true) {" + INDENT_INC; conds = new ExpLookahead [1]; conds[0] = la; @@ -1357,33 +965,11 @@ private String _phase1ExpansionGen (final Expansion e) // [ph] empty statement needed??? actions[0] = true ? "" : "\n;"; - switch (eOutputLanguage) - { - case JAVA: - actions[1] = "\nbreak label_" + labelIndex + ";"; - break; - case CPP: - actions[1] = "\ngoto end_label_" + labelIndex + ";"; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + actions[1] = "\nbreak label_" + labelIndex + ";"; retval += buildLookaheadChecker (conds, actions); retval += _phase1ExpansionGen (nested_e); retval += INDENT_DEC + "\n" + "}"; - - switch (eOutputLanguage) - { - case JAVA: - // nothing - break; - case CPP: - retval += "\nend_label_" + labelIndex + ": ;"; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } } else if (e instanceof ExpZeroOrOne) @@ -1455,17 +1041,7 @@ private String _phase1ExpansionGen (final Expansion e) } if (e_nrw.m_finallyblk != null) { - switch (eOutputLanguage) - { - case JAVA: - retval += " finally {" + INDENT_OFF + "\n"; - break; - case CPP: - retval += " finally {" + INDENT_OFF + "\n"; - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + retval += " finally {" + INDENT_OFF + "\n"; if (e_nrw.m_finallyblk.size () != 0) { @@ -1486,19 +1062,8 @@ private String _phase1ExpansionGen (final Expansion e) private void _buildPhase2Routine (final ExpLookahead la) { - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); final Expansion e = la.getLaExpansion (); - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine (" private boolean jj_2" + e.getInternalName () + "(int xla)"); - break; - case CPP: - m_codeGenerator.genCodeLine (" inline bool jj_2" + e.getInternalName () + "(int xla)"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + m_codeGenerator.genCodeLine (" private boolean jj_2" + e.getInternalName () + "(int xla)"); m_codeGenerator.genCodeLine (" {"); m_codeGenerator.genCodeLine (" jj_la = xla;"); m_codeGenerator.genCodeLine (" jj_scanpos = token;"); @@ -1510,32 +1075,12 @@ private void _buildPhase2Routine (final ExpLookahead la) ret_suffix = " && !jj_depth_error"; } - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine (" try { return (!jj_3" + e.getInternalName () + "()" + ret_suffix + "); }"); - m_codeGenerator.genCodeLine (" catch(LookaheadSuccess ls) { return true; }"); - break; - case CPP: - m_codeGenerator.genCodeLine (" jj_done = false;"); - m_codeGenerator.genCodeLine (" return (!jj_3" + e.getInternalName () + "() || jj_done)" + ret_suffix + ";"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + m_codeGenerator.genCodeLine (" try { return (!jj_3" + e.getInternalName () + "()" + ret_suffix + "); }"); + m_codeGenerator.genCodeLine (" catch(LookaheadSuccess ls) { return true; }"); + if (Options.isErrorReporting ()) { - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine (" finally { jj_save(" + (e.getInternalIndex () - 1) + ", xla); }"); - break; - case CPP: - m_codeGenerator.genCodeLine (" { jj_save(" + (e.getInternalIndex () - 1) + ", xla); }"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + m_codeGenerator.genCodeLine (" finally { jj_save(" + (e.getInternalIndex () - 1) + ", xla); }"); } m_codeGenerator.genCodeLine (" }"); m_codeGenerator.genCodeNewLine (); @@ -1690,16 +1235,7 @@ void setupPhase3Builds (final Phase3Data inf) private String _getTypeForToken () { - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - return "Token"; - case CPP: - return "Token *"; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + return "Token"; } private String _genjj_3Call (final Expansion e) @@ -1717,34 +1253,12 @@ void buildPhase3Routine (final Phase3Data inf, final boolean recursive_call) if (e.getInternalName ().startsWith ("jj_scan_token")) return; - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); if (!recursive_call) { - switch (eOutputLanguage) - { - case JAVA: - m_codeGenerator.genCodeLine (" private " + eOutputLanguage.getTypeBoolean () + " jj_3" + e.getInternalName () + "()"); - break; - case CPP: - m_codeGenerator.genCodeLine (" inline bool jj_3" + e.getInternalName () + "()"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + m_codeGenerator.genCodeLine (" private boolean jj_3" + e.getInternalName () + "()"); m_codeGenerator.genCodeLine (" {"); - switch (eOutputLanguage) - { - case JAVA: - break; - case CPP: - m_codeGenerator.genCodeLine (" if (jj_done) return true;"); - if (Options.hasDepthLimit ()) - m_codeGenerator.genCodeLine ("#define __ERROR_RET__ true"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + _genStackCheck (false); m_xsp_declared = false; if (Options.isDebugLookahead () && e.getParent () instanceof NormalProduction) @@ -1963,20 +1477,6 @@ void buildPhase3Routine (final Phase3Data inf, final boolean recursive_call) { m_codeGenerator.genCodeLine (" " + _genReturn (false)); genStackCheckEnd (); - switch (eOutputLanguage) - { - case JAVA: - // nothing; - break; - case CPP: - if (Options.hasDepthLimit ()) - { - m_codeGenerator.genCodeLine ("#undef __ERROR_RET__"); - } - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } m_codeGenerator.genCodeLine (" }"); m_codeGenerator.genCodeNewLine (); } @@ -2097,184 +1597,76 @@ int minimumSize (final Expansion e, final int oldMin) void build (final CodeGenerator codeGenerator) { m_codeGenerator = codeGenerator; - final EOutputLanguage eOutputLanguage = m_codeGenerator.getOutputLanguage (); for (final NormalProduction p : BNF_PRODUCTIONS) { - if (p instanceof CodeProductionCpp) + if (p instanceof CodeProductionJava) { - if (!eOutputLanguage.isJava ()) + final CodeProductionJava jp = (CodeProductionJava) p; + Token t = jp.getReturnTypeTokens ().get (0); + codeGenerator.printTokenSetup (t); + s_ccol = 1; + codeGenerator.printLeadingComments (t); + codeGenerator.genCode (" " + (p.getAccessMod () != null ? p.getAccessMod () + " " : "")); + s_cline = t.beginLine; + s_ccol = t.beginColumn; + codeGenerator.printTokenOnly (t); + for (int i = 1; i < jp.getReturnTypeTokens ().size (); i++) { - JavaCCErrors.semantic_error ("Cannot use JAVACODE productions with non-Java output."); - continue; + t = jp.getReturnTypeTokens ().get (i); + codeGenerator.printToken (t); } - - final CodeProductionCpp cp = (CodeProductionCpp) p; - - _generateCPPMethodheader (cp); - - if (false) + codeGenerator.printTrailingComments (t); + codeGenerator.genCode (" " + jp.getLhs () + "("); + if (jp.getParameterListTokens ().size () != 0) { - Token t = (cp.getReturnTypeTokens ().get (0)); - codeGenerator.printTokenSetup (t); - s_ccol = 1; - codeGenerator.printLeadingComments (t); - codeGenerator.genCode (" " + (p.getAccessMod () != null ? p.getAccessMod () + " " : "")); - s_cline = t.beginLine; - s_ccol = t.beginColumn; - codeGenerator.printTokenOnly (t); - for (int i = 1; i < cp.getReturnTypeTokens ().size (); i++) + codeGenerator.printTokenSetup (jp.getParameterListTokens ().get (0)); + for (final Token aElement2 : jp.getParameterListTokens ()) { - t = (cp.getReturnTypeTokens ().get (i)); + t = aElement2; codeGenerator.printToken (t); } codeGenerator.printTrailingComments (t); - codeGenerator.genCode (" " + cp.getLhs () + "("); - if (cp.getParameterListTokens ().size () != 0) - { - codeGenerator.printTokenSetup (cp.getParameterListTokens ().get (0)); - for (final Token aElement : cp.getParameterListTokens ()) - { - t = aElement; - codeGenerator.printToken (t); - } - codeGenerator.printTrailingComments (t); - } - codeGenerator.genCode (")"); - for (final List aElement : cp.getThrowsList ()) + } + codeGenerator.genCode (")"); + codeGenerator.genCode (" throws ParseException"); + for (final List aElement2 : jp.getThrowsList ()) + { + codeGenerator.genCode (", "); + for (final Token x : aElement2) { - codeGenerator.genCode (", "); - for (final Token aElement2 : aElement) - { - t = aElement2; - codeGenerator.genCode (t.image); - } + t = x; + codeGenerator.genCode (t.image); } } - - codeGenerator.genCodeLine (" {"); + codeGenerator.genCode (" {"); if (Options.isDebugParser ()) { codeGenerator.genCodeNewLine (); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" trace_call(\"" + JavaCCGlobals.addUnicodeEscapes (cp.getLhs ()) + "\");"); - codeGenerator.genCodeLine (" try {"); - break; - case CPP: - codeGenerator.genCodeLine (" JJEnter> jjenter([this]() {trace_call (\"" + - JavaCCGlobals.addUnicodeEscapes (cp.getLhs ()) + - "\"); });"); - codeGenerator.genCodeLine (" JJExit > jjexit ([this]() {trace_return(\"" + - JavaCCGlobals.addUnicodeEscapes (cp.getLhs ()) + - "\"); });"); - codeGenerator.genCodeLine (" try {"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } - + codeGenerator.genCodeLine (" trace_call(\"" + JavaCCGlobals.addUnicodeEscapes (jp.getLhs ()) + "\");"); + codeGenerator.genCode (" try {"); } - if (cp.getCodeTokens ().size () != 0) + if (jp.getCodeTokens ().size () != 0) { - codeGenerator.printTokenSetup (cp.getCodeTokens ().get (0)); + codeGenerator.printTokenSetup ((jp.getCodeTokens ().get (0))); s_cline--; - codeGenerator.printTokenList (cp.getCodeTokens ()); + codeGenerator.printTokenList (jp.getCodeTokens ()); } codeGenerator.genCodeNewLine (); if (Options.isDebugParser ()) { - codeGenerator.genCodeLine (" } catch(...) { }"); + codeGenerator.genCodeLine (" } finally {"); + codeGenerator.genCodeLine (" trace_return(\"" + JavaCCGlobals.addUnicodeEscapes (jp.getLhs ()) + "\");"); + codeGenerator.genCodeLine (" }"); } codeGenerator.genCodeLine (" }"); codeGenerator.genCodeNewLine (); } else - if (p instanceof CodeProductionJava) - { - if (!eOutputLanguage.isJava ()) - { - JavaCCErrors.semantic_error ("Cannot use JAVACODE productions with non-Java output."); - continue; - } - final CodeProductionJava jp = (CodeProductionJava) p; - Token t = jp.getReturnTypeTokens ().get (0); - codeGenerator.printTokenSetup (t); - s_ccol = 1; - codeGenerator.printLeadingComments (t); - codeGenerator.genCode (" " + (p.getAccessMod () != null ? p.getAccessMod () + " " : "")); - s_cline = t.beginLine; - s_ccol = t.beginColumn; - codeGenerator.printTokenOnly (t); - for (int i = 1; i < jp.getReturnTypeTokens ().size (); i++) - { - t = jp.getReturnTypeTokens ().get (i); - codeGenerator.printToken (t); - } - codeGenerator.printTrailingComments (t); - codeGenerator.genCode (" " + jp.getLhs () + "("); - if (jp.getParameterListTokens ().size () != 0) - { - codeGenerator.printTokenSetup (jp.getParameterListTokens ().get (0)); - for (final Token aElement2 : jp.getParameterListTokens ()) - { - t = aElement2; - codeGenerator.printToken (t); - } - codeGenerator.printTrailingComments (t); - } - codeGenerator.genCode (")"); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCode (" throws ParseException"); - break; - case CPP: - // nothing - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } - for (final List aElement2 : jp.getThrowsList ()) - { - codeGenerator.genCode (", "); - for (final Token x : aElement2) - { - t = x; - codeGenerator.genCode (t.image); - } - } - codeGenerator.genCode (" {"); - if (Options.isDebugParser ()) - { - codeGenerator.genCodeNewLine (); - codeGenerator.genCodeLine (" trace_call(\"" + JavaCCGlobals.addUnicodeEscapes (jp.getLhs ()) + "\");"); - codeGenerator.genCode (" try {"); - } - if (jp.getCodeTokens ().size () != 0) - { - codeGenerator.printTokenSetup ((jp.getCodeTokens ().get (0))); - s_cline--; - codeGenerator.printTokenList (jp.getCodeTokens ()); - } - codeGenerator.genCodeNewLine (); - if (Options.isDebugParser ()) - { - codeGenerator.genCodeLine (" } finally {"); - codeGenerator.genCodeLine (" trace_return(\"" + JavaCCGlobals.addUnicodeEscapes (jp.getLhs ()) + "\");"); - codeGenerator.genCodeLine (" }"); - } - codeGenerator.genCodeLine (" }"); - codeGenerator.genCodeNewLine (); - } - else - { - buildPhase1Routine ((BNFProduction) p); - } + { + buildPhase1Routine ((BNFProduction) p); + } } - codeGenerator.switchToIncludeFile (); - for (final ExpLookahead element : m_phase2list) { _buildPhase2Routine (element); diff --git a/src/main/java/com/helger/pgcc/parser/ParseGenCPP.java b/src/main/java/com/helger/pgcc/parser/ParseGenCPP.java deleted file mode 100644 index 39bf0c7ff..000000000 --- a/src/main/java/com/helger/pgcc/parser/ParseGenCPP.java +++ /dev/null @@ -1,829 +0,0 @@ -/* - * 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. - */ -// Copyright 2011 Google Inc. All Rights Reserved. -// Author: sreeni@google.com (Sreeni Viswanadha) - -package com.helger.pgcc.parser; - -import static com.helger.pgcc.parser.JavaCCGlobals.CU_FROM_INSERTION_POINT_2; -import static com.helger.pgcc.parser.JavaCCGlobals.CU_TO_INSERTION_POINT_2; -import static com.helger.pgcc.parser.JavaCCGlobals.MASK_VALS; -import static com.helger.pgcc.parser.JavaCCGlobals.getFileExtension; -import static com.helger.pgcc.parser.JavaCCGlobals.s_cu_name; -import static com.helger.pgcc.parser.JavaCCGlobals.s_jj2index; -import static com.helger.pgcc.parser.JavaCCGlobals.s_jjtreeGenerated; -import static com.helger.pgcc.parser.JavaCCGlobals.s_maskindex; -import static com.helger.pgcc.parser.JavaCCGlobals.s_tokenCount; -import static com.helger.pgcc.parser.JavaCCGlobals.s_toolNames; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -import com.helger.pgcc.CPG; - -/** - * Generate the parser. - */ -public class ParseGenCPP extends ParseGenJava -{ - @SuppressWarnings ("unchecked") - public void start () throws MetaParseException - { - if (JavaCCErrors.getErrorCount () != 0) - throw new MetaParseException ("Error count is already present!"); - - final List tn = new ArrayList <> (s_toolNames); - tn.add (CPG.APP_NAME); - switchToStaticsFile (); - - switchToIncludeFile (); - - // standard includes - genCodeLine ("#include \"JavaCC.h\""); - genCodeLine ("#include \"CharStream.h\""); - genCodeLine ("#include \"Token.h\""); - genCodeLine ("#include \"TokenManager.h\""); - - final Object object = Options.objectValue (Options.USEROPTION__CPP_PARSER_INCLUDES); - - if (object instanceof String) - { - final String include = (String) object; - if (include.length () > 0) - { - if (include.charAt (0) == '<') - genCodeLine ("#include " + include); - else - genCodeLine ("#include \"" + include + "\""); - } - } - else - if (object instanceof List ) - { - for (final String include : (List ) object) - if (include.length () > 0) - { - if (include.charAt (0) == '<') - genCodeLine ("#include " + include); - else - genCodeLine ("#include \"" + include + "\""); - } - } - - genCodeLine ("#include \"" + s_cu_name + "Constants.h\""); - - if (s_jjtreeGenerated) - { - genCodeLine ("#include \"JJT" + s_cu_name + "State.h\""); - } - - genCodeLine ("#include \"ErrorHandler.h\""); - - if (s_jjtreeGenerated) - { - genCodeLine ("#include \"" + s_cu_name + "Tree.h\""); - } - - if (Options.stringValue (Options.USEROPTION__CPP_NAMESPACE).length () > 0) - { - genCodeLine ("namespace " + Options.stringValue ("NAMESPACE_OPEN")); - } - - genCodeLine (" struct JJCalls {"); - genCodeLine (" int gen;"); - genCodeLine (" int arg;"); - genCodeLine (" JJCalls* next;"); - genCodeLine (" Token* first;"); - genCodeLine (" ~JJCalls() { if (next) delete next; }"); - genCodeLine (" JJCalls() { next = nullptr; arg = 0; gen = -1; first = nullptr; }"); - genCodeLine (" };"); - genCodeNewLine (); - - final String superClass = Options.stringValue (Options.USEROPTION__PARSER_SUPER_CLASS); - genClassStart ("", s_cu_name, new String [] {}, superClass == null ? new String [0] : new String [] { "public " + superClass }); - switchToMainFile (); - if (CU_TO_INSERTION_POINT_2.size () != 0) - { - printTokenSetup (CU_TO_INSERTION_POINT_2.get (0)); - for (final Token t : CU_TO_INSERTION_POINT_2) - printToken (t); - } - - switchToMainFile (); - /* - * genCodeLine("typedef class _LookaheadSuccess { } *LookaheadSuccess; // Dummy class" - * ); - * genCodeLine(" static LookaheadSuccess jj_ls = new _LookaheadSuccess();" - * ); - */ - - genCodeNewLine (); - genCodeNewLine (); - - new ParseEngine ().build (this); - - switchToIncludeFile (); - genCodeNewLine (); - genCodeLine ("public: "); - genCodeLine (" void setErrorHandler(ErrorHandler *eh) {"); - genCodeLine (" if (errorHandler) delete errorHandler;"); - genCodeLine (" errorHandler = eh;"); - genCodeLine (" }"); - genCodeNewLine (); - genCodeLine (" TokenManager *token_source = nullptr;"); - genCodeLine (" CharStream *jj_input_stream = nullptr;"); - genCodeLine (" /** Current token. */"); - genCodeLine (" Token *token = nullptr;"); - genCodeLine (" /** Next token. */"); - genCodeLine (" Token *jj_nt = nullptr;"); - genCodeNewLine (); - genCodeLine ("private: "); - genCodeLine (" int jj_ntk;"); - - genCodeLine (" JJCalls jj_2_rtns[" + (s_jj2index + 1) + "];"); - genCodeLine (" bool jj_rescan;"); - genCodeLine (" int jj_gc;"); - genCodeLine (" Token *jj_scanpos, *jj_lastpos;"); - genCodeLine (" int jj_la;"); - genCodeLine (" /** Whether we are looking ahead. */"); - genCodeLine (" bool jj_lookingAhead;"); - genCodeLine (" bool jj_semLA;"); - - genCodeLine (" int jj_gen;"); - genCodeLine (" int jj_la1[" + (s_maskindex + 1) + "];"); - genCodeLine (" ErrorHandler *errorHandler = nullptr;"); - genCodeNewLine (); - genCodeLine ("protected: "); - genCodeLine (" bool hasError;"); - genCodeNewLine (); - final int tokenMaskSize = (s_tokenCount - 1) / 32 + 1; - - if (Options.isErrorReporting () && tokenMaskSize > 0) - { - switchToStaticsFile (); - for (int i = 0; i < tokenMaskSize; i++) - { - if (MASK_VALS.size () > 0) - { - genCodeLine (" unsigned int jj_la1_" + i + "[] = {"); - for (final int [] tokenMask : MASK_VALS) - { - genCode ("0x" + Integer.toHexString (tokenMask[i]) + ","); - } - genCodeLine ("};"); - } - } - } - - if (Options.hasDepthLimit ()) - { - genCodeLine (" private: int jj_depth;"); - genCodeLine (" private: bool jj_depth_error;"); - genCodeLine (" friend class __jj_depth_inc;"); - genCodeLine (" class __jj_depth_inc {public:"); - genCodeLine (" " + s_cu_name + "* parent;"); - genCodeLine (" __jj_depth_inc(" + s_cu_name + "* p): parent(p) { parent->jj_depth++; };"); - genCodeLine (" ~__jj_depth_inc(){ parent->jj_depth--; }"); - genCodeLine (" };"); - } - if (Options.hasCPPStackLimit ()) - { - genCodeLine (" public: size_t jj_stack_limit;"); - genCodeLine (" private: void* jj_stack_base;"); - genCodeLine (" private: bool jj_stack_error;"); - } - - genCodeNewLine (); - - genCodeLine (" /** Constructor with user supplied TokenManager. */"); - - switchToIncludeFile (); // TEMP - genCodeLine (" Token *head; "); - genCodeLine ("public: "); - generateMethodDefHeader (" ", s_cu_name, s_cu_name + "(TokenManager *tokenManager)"); - if (superClass != null) - { - genCodeLine (" : " + superClass + "()"); - } - genCodeLine ("{"); - genCodeLine (" head = nullptr;"); - genCodeLine (" ReInit(tokenManager);"); - if (Options.isTokenManagerUsesParser ()) - genCodeLine (" tokenManager->setParser(this);"); - genCodeLine ("}"); - - switchToIncludeFile (); - genCodeLine (" virtual ~" + s_cu_name + "();"); - switchToMainFile (); - genCodeLine (s_cu_name + "::~" + s_cu_name + "()"); - genCodeLine ("{"); - genCodeLine (" clear();"); - genCodeLine ("}"); - generateMethodDefHeader ("void", s_cu_name, "ReInit(TokenManager* tokenManager)"); - genCodeLine ("{"); - genCodeLine (" clear();"); - genCodeLine (" errorHandler = new ErrorHandler();"); - genCodeLine (" hasError = false;"); - genCodeLine (" token_source = tokenManager;"); - genCodeLine (" head = token = new Token();"); - genCodeLine (" token->kind = 0;"); - genCodeLine (" token->next = nullptr;"); - genCodeLine (" jj_lookingAhead = false;"); - genCodeLine (" jj_rescan = false;"); - genCodeLine (" jj_done = false;"); - genCodeLine (" jj_scanpos = jj_lastpos = nullptr;"); - genCodeLine (" jj_gc = 0;"); - genCodeLine (" jj_kind = -1;"); - genCodeLine (" indent = 0;"); - genCodeLine (" trace = " + Options.isDebugParser () + ";"); - if (Options.hasCPPStackLimit ()) - { - genCodeLine (" jj_stack_limit = " + Options.getCPPStackLimit () + ";"); - genCodeLine (" jj_stack_error = jj_stack_check(true);"); - } - - if (Options.isCacheTokens ()) - { - genCodeLine (" token->next = jj_nt = token_source->getNextToken();"); - } - else - { - genCodeLine (" jj_ntk = -1;"); - } - if (s_jjtreeGenerated) - { - genCodeLine (" jjtree.reset();"); - } - if (Options.hasDepthLimit ()) - { - genCodeLine (" jj_depth = 0;"); - genCodeLine (" jj_depth_error = false;"); - } - if (Options.isErrorReporting ()) - { - genCodeLine (" jj_gen = 0;"); - if (s_maskindex > 0) - { - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); - } - } - genCodeLine (" }"); - genCodeNewLine (); - - generateMethodDefHeader ("void", s_cu_name, "clear()"); - genCodeLine ("{"); - genCodeLine (" //Since token manager was generate from outside,"); - genCodeLine (" //parser should not take care of deleting"); - genCodeLine (" //if (token_source) delete token_source;"); - genCodeLine (" if (head) {"); - genCodeLine (" Token *next, *t = head;"); - genCodeLine (" while (t) {"); - genCodeLine (" next = t->next;"); - genCodeLine (" delete t;"); - genCodeLine (" t = next;"); - genCodeLine (" }"); - genCodeLine (" }"); - genCodeLine (" if (errorHandler) {"); - genCodeLine (" delete errorHandler, errorHandler = nullptr;"); - genCodeLine (" }"); - if (Options.hasDepthLimit ()) - { - genCodeLine (" assert(jj_depth==0);"); - } - genCodeLine ("}"); - genCodeNewLine (); - - if (Options.hasCPPStackLimit ()) - { - genCodeNewLine (); - switchToIncludeFile (); - genCodeLine (" virtual"); - switchToMainFile (); - generateMethodDefHeader ("bool ", s_cu_name, "jj_stack_check(bool init)"); - genCodeLine (" {"); - genCodeLine (" if(init) {"); - genCodeLine (" jj_stack_base = nullptr;"); - genCodeLine (" return false;"); - genCodeLine (" } else {"); - genCodeLine (" volatile int q = 0;"); - genCodeLine (" if(!jj_stack_base) {"); - genCodeLine (" jj_stack_base = (void*)&q;"); - genCodeLine (" return false;"); - genCodeLine (" } else {"); - genCodeLine (" // Stack can grow in both directions, depending on arch"); - genCodeLine (" std::ptrdiff_t used = (char*)jj_stack_base-(char*)&q;"); - genCodeLine (" return (std::abs(used) > jj_stack_limit);"); - genCodeLine (" }"); - genCodeLine (" }"); - genCodeLine (" }"); - } - - generateMethodDefHeader ("Token *", s_cu_name, "jj_consume_token(int kind)", "ParseException"); - genCodeLine (" {"); - if (Options.hasCPPStackLimit ()) - { - genCodeLine (" if(kind != -1 && (jj_stack_error || jj_stack_check(false))) {"); - genCodeLine (" if (!jj_stack_error) {"); - genCodeLine (" errorHandler->handleOtherError(\"Stack overflow while trying to parse\", this);"); - genCodeLine (" jj_stack_error=true;"); - genCodeLine (" }"); - genCodeLine (" return jj_consume_token(-1);"); - genCodeLine (" }"); - } - if (Options.isCacheTokens ()) - { - genCodeLine (" Token *oldToken = token;"); - genCodeLine (" if ((token = jj_nt)->next != nullptr) jj_nt = jj_nt->next;"); - genCodeLine (" else jj_nt = jj_nt->next = token_source->getNextToken();"); - } - else - { - genCodeLine (" Token *oldToken;"); - genCodeLine (" if ((oldToken = token)->next != nullptr) token = token->next;"); - genCodeLine (" else token = token->next = token_source->getNextToken();"); - genCodeLine (" jj_ntk = -1;"); - } - genCodeLine (" if (token->kind == kind) {"); - if (Options.isErrorReporting ()) - { - genCodeLine (" jj_gen++;"); - if (s_jj2index != 0) - { - genCodeLine (" if (++jj_gc > 100) {"); - genCodeLine (" jj_gc = 0;"); - genCodeLine (" for (int i = 0; i < " + s_jj2index + "; i++) {"); - genCodeLine (" JJCalls *c = &jj_2_rtns[i];"); - genCodeLine (" while (c != nullptr) {"); - genCodeLine (" if (c->gen < jj_gen) c->first = nullptr;"); - genCodeLine (" c = c->next;"); - genCodeLine (" }"); - genCodeLine (" }"); - genCodeLine (" }"); - } - } - if (Options.isDebugParser ()) - { - genCodeLine (" trace_token(token, \"\");"); - } - genCodeLine (" return token;"); - genCodeLine (" }"); - if (Options.isCacheTokens ()) - { - genCodeLine (" jj_nt = token;"); - } - genCodeLine (" token = oldToken;"); - if (Options.isErrorReporting ()) - { - genCodeLine (" jj_kind = kind;"); - } - // genCodeLine(" throw generateParseException();"); - if (Options.hasCPPStackLimit ()) - { - genCodeLine (" if (!jj_stack_error) {"); - } - genCodeLine (" JJString image = kind >= 0 ? tokenImage[kind] : tokenImage[0];"); - genCodeLine (" errorHandler->handleUnexpectedToken(kind, image.substr(1, image.size() - 2), getToken(1), this);"); - if (Options.hasCPPStackLimit ()) - { - genCodeLine (" }"); - } - genCodeLine (" hasError = true;"); - genCodeLine (" return token;"); - genCodeLine (" }"); - genCodeNewLine (); - - if (s_jj2index != 0) - { - switchToMainFile (); - generateMethodDefHeader ("bool ", s_cu_name, "jj_scan_token(int kind)"); - genCodeLine ("{"); - if (Options.hasCPPStackLimit ()) - { - genCodeLine (" if(kind != -1 && (jj_stack_error || jj_stack_check(false))) {"); - genCodeLine (" if (!jj_stack_error) {"); - genCodeLine (" errorHandler->handleOtherError(\"Stack overflow while trying to parse\", this);"); - genCodeLine (" jj_stack_error=true;"); - genCodeLine (" }"); - genCodeLine (" return jj_consume_token(-1);"); - genCodeLine (" }"); - } - genCodeLine (" if (jj_scanpos == jj_lastpos) {"); - genCodeLine (" jj_la--;"); - genCodeLine (" if (jj_scanpos->next == nullptr) {"); - genCodeLine (" jj_lastpos = jj_scanpos = jj_scanpos->next = token_source->getNextToken();"); - genCodeLine (" } else {"); - genCodeLine (" jj_lastpos = jj_scanpos = jj_scanpos->next;"); - genCodeLine (" }"); - genCodeLine (" } else {"); - genCodeLine (" jj_scanpos = jj_scanpos->next;"); - genCodeLine (" }"); - if (Options.isErrorReporting ()) - { - genCodeLine (" if (jj_rescan) {"); - genCodeLine (" int i = 0; Token *tok = token;"); - genCodeLine (" while (tok != nullptr && tok != jj_scanpos) { i++; tok = tok->next; }"); - genCodeLine (" if (tok != nullptr) jj_add_error_token(kind, i);"); - if (Options.isDebugLookahead ()) - { - genCodeLine (" } else {"); - genCodeLine (" trace_scan(jj_scanpos, kind);"); - } - genCodeLine (" }"); - } - else - if (Options.isDebugLookahead ()) - { - genCodeLine (" trace_scan(jj_scanpos, kind);"); - } - genCodeLine (" if (jj_scanpos->kind != kind) return true;"); - // genCodeLine(" if (jj_la == 0 && jj_scanpos == jj_lastpos) throw - // jj_ls;"); - genCodeLine (" if (jj_la == 0 && jj_scanpos == jj_lastpos) { return jj_done = true; }"); - genCodeLine (" return false;"); - genCodeLine (" }"); - genCodeNewLine (); - } - genCodeNewLine (); - genCodeLine ("/** Get the next Token. */"); - generateMethodDefHeader ("Token *", s_cu_name, "getNextToken()"); - genCodeLine ("{"); - if (Options.isCacheTokens ()) - { - genCodeLine (" if ((token = jj_nt)->next != nullptr) jj_nt = jj_nt->next;"); - genCodeLine (" else jj_nt = jj_nt->next = token_source->getNextToken();"); - } - else - { - genCodeLine (" if (token->next != nullptr) token = token->next;"); - genCodeLine (" else token = token->next = token_source->getNextToken();"); - genCodeLine (" jj_ntk = -1;"); - } - if (Options.isErrorReporting ()) - { - genCodeLine (" jj_gen++;"); - } - if (Options.isDebugParser ()) - { - genCodeLine (" trace_token(token, \" (in getNextToken)\");"); - } - genCodeLine (" return token;"); - genCodeLine (" }"); - genCodeNewLine (); - genCodeLine ("/** Get the specific Token. */"); - generateMethodDefHeader ("Token *", s_cu_name, "getToken(int index)"); - genCodeLine ("{"); - if (JavaCCGlobals.isLookAheadNeeded ()) - { - genCodeLine (" Token *t = jj_lookingAhead ? jj_scanpos : token;"); - } - else - { - genCodeLine (" Token *t = token;"); - } - genCodeLine (" for (int i = 0; i < index; i++) {"); - genCodeLine (" if (t->next != nullptr) t = t->next;"); - genCodeLine (" else t = t->next = token_source->getNextToken();"); - genCodeLine (" }"); - genCodeLine (" return t;"); - genCodeLine (" }"); - genCodeNewLine (); - if (!Options.isCacheTokens ()) - { - generateMethodDefHeader ("int", s_cu_name, "jj_ntk_f()"); - genCodeLine ("{"); - - genCodeLine (" if ((jj_nt=token->next) == nullptr)"); - genCodeLine (" return (jj_ntk = (token->next=token_source->getNextToken())->kind);"); - genCodeLine (" else"); - genCodeLine (" return (jj_ntk = jj_nt->kind);"); - genCodeLine (" }"); - genCodeNewLine (); - } - - switchToIncludeFile (); - genCodeLine ("private:"); - genCodeLine (" int jj_kind;"); - if (Options.isErrorReporting ()) - { - genCodeLine (" int **jj_expentries;"); - genCodeLine (" int *jj_expentry;"); - if (s_jj2index != 0) - { - switchToStaticsFile (); - // For now we don't support ERROR_REPORTING in the C++ version. - // genCodeLine(" static int *jj_lasttokens = new int[100];"); - // genCodeLine(" static int jj_endpos;"); - genCodeNewLine (); - - generateMethodDefHeader (" void", s_cu_name, "jj_add_error_token(int kind, int pos)"); - genCodeLine (" {"); - // For now we don't support ERROR_REPORTING in the C++ version. - - // genCodeLine(" if (pos >= 100) return;"); - // genCodeLine(" if (pos == jj_endpos + 1) {"); - // genCodeLine(" jj_lasttokens[jj_endpos++] = kind;"); - // genCodeLine(" } else if (jj_endpos != 0) {"); - // genCodeLine(" jj_expentry = new int[jj_endpos];"); - // genCodeLine(" for (int i = 0; i < jj_endpos; i++) {"); - // genCodeLine(" jj_expentry[i] = jj_lasttokens[i];"); - // genCodeLine(" }"); - // genCodeLine(" jj_entries_loop: for (java.util.Iterator it = - // jj_expentries.iterator(); it.hasNext();) {"); - // genCodeLine(" int[] oldentry = (int[])(it->next());"); - // genCodeLine(" if (oldentry.length == jj_expentry.length) {"); - // genCodeLine(" for (int i = 0; i < jj_expentry.length; i++) {"); - // genCodeLine(" if (oldentry[i] != jj_expentry[i]) {"); - // genCodeLine(" continue jj_entries_loop;"); - // genCodeLine(" }"); - // genCodeLine(" }"); - // genCodeLine(" jj_expentries.add(jj_expentry);"); - // genCodeLine(" break jj_entries_loop;"); - // genCodeLine(" }"); - // genCodeLine(" }"); - // genCodeLine(" if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = - // kind;"); - // genCodeLine(" }"); - genCodeLine (" }"); - } - genCodeNewLine (); - - switchToIncludeFile (); - genCodeLine ("protected:"); - genCodeLine (" /** Generate ParseException. */"); - generateMethodDefHeader (" virtual void ", s_cu_name, "parseError()"); - genCodeLine (" {"); - if (Options.isErrorReporting ()) - { - genCodeLine (" fprintf(stderr, \"Parse error at: %d:%d, after token: %s encountered: %s\\n\", token->beginLine, token->beginColumn, addUnicodeEscapes(token->image).c_str(), addUnicodeEscapes(getToken(1)->image).c_str());"); - } - genCodeLine (" }"); - /* - * generateMethodDefHeader("ParseException", cu_name, - * "generateParseException()"); genCodeLine(" {"); - * //genCodeLine(" jj_expentries.clear();"); - * //genCodeLine(" bool[] la1tokens = new boolean[" + tokenCount + - * "];"); //genCodeLine(" if (jj_kind >= 0) {"); - * //genCodeLine(" la1tokens[jj_kind] = true;"); - * //genCodeLine(" jj_kind = -1;"); //genCodeLine(" }"); - * //genCodeLine(" for (int i = 0; i < " + maskindex + "; i++) {"); - * //genCodeLine(" if (jj_la1[i] == jj_gen) {"); - * //genCodeLine(" for (int j = 0; j < 32; j++) {"); //for (int i = - * 0; i < (tokenCount-1)/32 + 1; i++) { - * //genCodeLine(" if ((jj_la1_" + i + "[i] & (1<beginLine, token->beginColumn, addUnicodeEscapes(token->image).c_str(), addUnicodeEscapes(getToken(1)->image).c_str());"); - } - genCodeLine (" }"); - /* - * generateMethodDefHeader("ParseException", cu_name, - * "generateParseException()"); genCodeLine(" {"); - * genCodeLine(" Token *errortok = token->next;"); if - * (Options.getKeepLineColumn()) - * genCodeLine(" int line = errortok.beginLine, column = errortok.beginColumn;" - * ); - * genCodeLine(" JJString mess = (errortok->kind == 0) ? tokenImage[0] : errortok->image;" - * ); if (Options.getKeepLineColumn()) - * genCodeLine(" return new _ParseException();");// + - * //"\"Parse error at line \" + line + \", column \" + column + \". " + - * //"Encountered: \" + mess);"); else - * genCodeLine(" return new _ParseException();");// - * \"Parse error at . " + - * //"Encountered: \" + mess);"); genCodeLine(" }"); - */ - } - genCodeNewLine (); - - switchToIncludeFile (); - genCodeLine ("private:"); - genCodeLine (" int indent; // trace indentation"); - genCodeLine (" bool trace = " + Options.isDebugParser () + "; // trace enabled if true"); - genCodeNewLine (); - genCodeLine ("public:"); - generateMethodDefHeader (" bool", s_cu_name, "trace_enabled()"); - genCodeLine (" {"); - genCodeLine (" return trace;"); - genCodeLine (" }"); - genCodeNewLine (); - if (Options.isDebugParser ()) - { - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "enable_tracing()"); - genCodeLine ("{"); - genCodeLine (" trace = true;"); - genCodeLine ("}"); - genCodeNewLine (); - - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "disable_tracing()"); - genCodeLine ("{"); - genCodeLine (" trace = false;"); - genCodeLine ("}"); - genCodeNewLine (); - - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "trace_call(const char *s)"); - genCodeLine (" {"); - genCodeLine (" if (trace_enabled()) {"); - genCodeLine (" for (int i = 0; i < indent; i++) { printf(\" \"); }"); - genCodeLine (" printf(\"Call: %s\\n\", s);"); - genCodeLine (" }"); - genCodeLine (" indent = indent + 2;"); - genCodeLine (" }"); - genCodeNewLine (); - - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "trace_return(const char *s)"); - genCodeLine (" {"); - genCodeLine (" indent = indent - 2;"); - genCodeLine (" if (trace_enabled()) {"); - genCodeLine (" for (int i = 0; i < indent; i++) { printf(\" \"); }"); - genCodeLine (" printf(\"Return: %s\\n\", s);"); - genCodeLine (" }"); - genCodeLine (" }"); - genCodeNewLine (); - - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "trace_token(Token *t, const char *where)"); - genCodeLine (" {"); - genCodeLine (" if (trace_enabled()) {"); - genCodeLine (" for (int i = 0; i < indent; i++) { printf(\" \"); }"); - genCodeLine (" printf(\"Consumed token: kind, addUnicodeEscapes(tokenImage[t->kind]).c_str(), addUnicodeEscapes(t->image).c_str());"); - // genCodeLine(" if (t->kind != 0 && !tokenImage[t->kind].equals(\"\\\"\" - // + t->image + \"\\\"\")) {"); - // genCodeLine(" System.out.print(\": \\\"\" + t->image + \"\\\"\");"); - // genCodeLine(" }"); - genCodeLine (" printf(\" at line %d column %d> %s\\n\", t->beginLine, t->beginColumn, where);"); - genCodeLine (" }"); - genCodeLine (" }"); - genCodeNewLine (); - - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "trace_scan(Token *t1, int t2)"); - genCodeLine (" {"); - genCodeLine (" if (trace_enabled()) {"); - genCodeLine (" for (int i = 0; i < indent; i++) { printf(\" \"); }"); - genCodeLine (" printf(\"Visited token: kind, addUnicodeEscapes(tokenImage[t1->kind]).c_str(), addUnicodeEscapes(t1->image).c_str());"); - // genCodeLine(" if (t1->kind != 0 && - // !tokenImage[t1->kind].equals(\"\\\"\" + t1->image + \"\\\"\")) {"); - // genCodeLine(" System.out.print(\": \\\"\" + t1->image + \"\\\"\");"); - // genCodeLine(" }"); - genCodeLine (" printf(\" at line %d column %d>; Expected token: %s\\n\", t1->beginLine, t1->beginColumn, addUnicodeEscapes(tokenImage[t2]).c_str());"); - genCodeLine (" }"); - genCodeLine (" }"); - genCodeNewLine (); - } - else - { - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "enable_tracing()"); - genCodeLine (" {"); - genCodeLine (" }"); - switchToIncludeFile (); - generateMethodDefHeader (" void", s_cu_name, "disable_tracing()"); - genCodeLine (" {"); - genCodeLine (" }"); - genCodeNewLine (); - } - - if (s_jj2index != 0 && Options.isErrorReporting ()) - { - generateMethodDefHeader (" void", s_cu_name, "jj_rescan_token()"); - genCodeLine ("{"); - genCodeLine (" jj_rescan = true;"); - genCodeLine (" for (int i = 0; i < " + s_jj2index + "; i++) {"); - // genCodeLine(" try {"); - genCodeLine (" JJCalls *p = &jj_2_rtns[i];"); - genCodeLine (" do {"); - genCodeLine (" if (p->gen > jj_gen) {"); - genCodeLine (" jj_la = p->arg; jj_lastpos = jj_scanpos = p->first;"); - genCodeLine (" switch (i) {"); - for (int i = 0; i < s_jj2index; i++) - { - genCodeLine (" case " + i + ": jj_3_" + (i + 1) + "(); break;"); - } - genCodeLine (" }"); - genCodeLine (" }"); - genCodeLine (" p = p->next;"); - genCodeLine (" } while (p != nullptr);"); - // genCodeLine(" } catch(LookaheadSuccess ls) { }"); - genCodeLine (" }"); - genCodeLine (" jj_rescan = false;"); - genCodeLine (" }"); - genCodeNewLine (); - - generateMethodDefHeader (" void", s_cu_name, "jj_save(int index, int xla)"); - genCodeLine ("{"); - genCodeLine (" JJCalls *p = &jj_2_rtns[index];"); - genCodeLine (" while (p->gen > jj_gen) {"); - genCodeLine (" if (p->next == nullptr) { p = p->next = new JJCalls(); break; }"); - genCodeLine (" p = p->next;"); - genCodeLine (" }"); - genCodeLine (" p->gen = jj_gen + xla - jj_la; p->first = token; p->arg = xla;"); - genCodeLine (" }"); - genCodeNewLine (); - } - - if (CU_FROM_INSERTION_POINT_2.isNotEmpty ()) - { - printTokenSetup (CU_FROM_INSERTION_POINT_2.get (0)); - setColToStart (); - Token t = null; - for (final Token name : CU_FROM_INSERTION_POINT_2) - { - t = name; - printToken (t); - } - printTrailingComments (t); - } - genCodeNewLine (); - - // in the include file close the class signature - switchToIncludeFile (); - - // copy other stuff - Token t1 = JavaCCGlobals.getOtherLanguageDeclTokenBegin (); - final Token t2 = JavaCCGlobals.getOtherLanguageDeclTokenEnd (); - while (t1 != t2) - { - printToken (t1); - t1 = t1.next; - } - genCodeLine ("\n"); - if (s_jjtreeGenerated) - { - genCodeLine (" JJT" + s_cu_name + "State jjtree;"); - } - genCodeLine ("private:"); - genCodeLine (" bool jj_done;"); - - genCodeLine ("};"); - - saveOutput (Options.getOutputDirectory () + File.separator + s_cu_name + getFileExtension ()); - } - - public static void reInit () - { - JavaCCGlobals.setLookAheadNeeded (false); - } -} diff --git a/src/main/java/com/helger/pgcc/parser/ParseGenJava.java b/src/main/java/com/helger/pgcc/parser/ParseGenJava.java index e1e711267..b24fb9ec0 100644 --- a/src/main/java/com/helger/pgcc/parser/ParseGenJava.java +++ b/src/main/java/com/helger/pgcc/parser/ParseGenJava.java @@ -82,7 +82,6 @@ import com.helger.pgcc.CPG; import com.helger.pgcc.EJDKVersion; -import com.helger.pgcc.output.EOutputLanguage; /** * Generate the parser. @@ -97,7 +96,6 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException if (!Options.isBuildParser ()) return; - final EOutputLanguage eOutputLanguage = getOutputLanguage (); final EJDKVersion eJavaVersion = Options.getJdkVersion (); final boolean bHasCharset = eJavaVersion.isNewerOrEqualsThan (EJDKVersion.JDK_1_6); final boolean bEmptyTypeVar = eJavaVersion.isNewerOrEqualsThan (EJDKVersion.JDK_1_7); @@ -198,8 +196,8 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException if (JavaCCGlobals.isLookAheadNeeded ()) { genCodeLine (" /** Whether we are looking ahead. */"); - genCodeLine (" private " + eOutputLanguage.getTypeBoolean () + " jj_lookingAhead = false;"); - genCodeLine (" private " + eOutputLanguage.getTypeBoolean () + " jj_semLA;"); + genCodeLine (" private boolean jj_lookingAhead = false;"); + genCodeLine (" private boolean jj_semLA;"); } } if (Options.isErrorReporting ()) @@ -214,23 +212,23 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" static {"); for (int i = 0; i < tokenMaskSize; i++) { - genCodeLine (" jj_la1_init_" + i + "();"); + genCodeLine (" jj_la1_init_" + i + "();"); } - genCodeLine (" }"); + genCodeLine (" }"); for (int i = 0; i < tokenMaskSize; i++) { - genCodeLine (" private static void jj_la1_init_" + i + "() {"); - genCode (" jj_la1_" + i + " = new int[] {"); + genCodeLine (" private static void jj_la1_init_" + i + "() {"); + genCode (" jj_la1_" + i + " = new int[] {"); for (final int [] tokenMask : MASK_VALS) genCode ("0x" + Integer.toHexString (tokenMask[i]) + ","); genCodeLine ("};"); - genCodeLine (" }"); + genCodeLine (" }"); } } if (s_jj2index != 0 && Options.isErrorReporting ()) { genCodeLine (" private final JJCalls[] jj_2_rtns = new JJCalls[" + s_jj2index + "];"); - genCodeLine (" private " + eOutputLanguage.getTypeBoolean () + " jj_rescan = false;"); + genCodeLine (" private boolean jj_rescan = false;"); genCodeLine (" private int jj_gc = 0;"); } genCodeNewLine (); @@ -245,10 +243,10 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" */"); genCodeLine (" public " + s_cu_name + "(final CharStream stream) {"); if (Options.isTokenManagerUsesParser ()) - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, stream);"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, stream);"); else - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(stream);"); - genCodeLine (" token = new Token();"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(stream);"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { genCodeLine (" jj_nt = token_source.getNextToken();"); @@ -256,7 +254,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -264,14 +262,14 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); + genCodeLine (" jj_gen = 0;"); if (s_maskindex > 0) { - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); + genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); } if (s_jj2index != 0) { - genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); + genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } genCodeLine (" }"); @@ -284,22 +282,22 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException if (Options.isTokenManagerRequiresParserAccess ()) { - genCodeLine (" token_source.ReInit(this,stream);"); + genCodeLine (" token_source.ReInit(this,stream);"); } else { - genCodeLine (" token_source.ReInit(stream);"); + genCodeLine (" token_source.ReInit(stream);"); } - genCodeLine (" token = new Token();"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { - genCodeLine (" jj_nt = token_source.getNextToken();"); - genCodeLine (" token.next = jj_nt;"); + genCodeLine (" jj_nt = token_source.getNextToken();"); + genCodeLine (" token.next = jj_nt;"); } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -307,24 +305,24 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (JavaCCGlobals.isLookAheadNeeded ()) { - genCodeLine (" jj_lookingAhead = false;"); + genCodeLine (" jj_lookingAhead = false;"); } if (s_jjtreeGenerated) { - genCodeLine (" jjtree.reset();"); + genCodeLine (" jjtree.reset();"); } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); + genCodeLine (" jj_gen = 0;"); if (s_maskindex > 0) { - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++)"); - genCodeLine (" jj_la1[i] = -1;"); + genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++)"); + genCodeLine (" jj_la1[i] = -1;"); } if (s_jj2index != 0) { - genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++)"); - genCodeLine (" jj_2_rtns[i] = new JJCalls();"); + genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++)"); + genCodeLine (" jj_2_rtns[i] = new JJCalls();"); } } genCodeLine (" }"); @@ -341,7 +339,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" * @param stream input stream"); genCodeLine (" */"); genCodeLine (" public " + s_cu_name + "(final java.io.InputStream stream) {"); - genCodeLine (" this(stream, null);"); + genCodeLine (" this(stream, null);"); genCodeLine (" }"); genCodeNewLine (); } @@ -370,10 +368,10 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (Options.isTokenManagerUsesParser ()) - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, jj_input_stream);"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, jj_input_stream);"); else - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(jj_input_stream);"); - genCodeLine (" token = new Token();"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(jj_input_stream);"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { genCodeLine (" jj_nt = token_source.getNextToken();"); @@ -381,7 +379,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -389,14 +387,14 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); + genCodeLine (" jj_gen = 0;"); if (s_maskindex > 0) { - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); + genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); } if (s_jj2index != 0) { - genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); + genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } genCodeLine (" }"); @@ -410,7 +408,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" * @param stream input stream"); genCodeLine (" */"); genCodeLine (" public void ReInit(final java.io.InputStream stream) {"); - genCodeLine (" ReInit(stream, null);"); + genCodeLine (" ReInit(stream, null);"); genCodeLine (" }"); } @@ -427,7 +425,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException else { genCodeLine (" public void ReInit(final java.io.InputStream stream, final String encoding) {"); - genCodeLine (" try {"); + genCodeLine (" try {"); genCodeLine (" jj_input_stream.reInit(stream, encoding, 1, 1);"); genCodeLine (" } catch(final java.io.UnsupportedEncodingException e) { "); genCodeLine (" throw new IllegalStateException(e);"); @@ -436,22 +434,22 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException if (Options.isTokenManagerRequiresParserAccess ()) { - genCodeLine (" token_source.ReInit(this,jj_input_stream);"); + genCodeLine (" token_source.ReInit(this,jj_input_stream);"); } else { - genCodeLine (" token_source.ReInit(jj_input_stream);"); + genCodeLine (" token_source.ReInit(jj_input_stream);"); } - genCodeLine (" token = new Token();"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { - genCodeLine (" jj_nt = token_source.getNextToken();"); - genCodeLine (" token.next = jj_nt;"); + genCodeLine (" jj_nt = token_source.getNextToken();"); + genCodeLine (" token.next = jj_nt;"); } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -459,15 +457,15 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (s_jjtreeGenerated) { - genCodeLine (" jjtree.reset();"); + genCodeLine (" jjtree.reset();"); } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); + genCodeLine (" jj_gen = 0;"); + genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); if (s_jj2index != 0) { - genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); + genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } genCodeLine (" }"); @@ -485,28 +483,28 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" public " + s_cu_name + "(final " + readerInterfaceName + " stream) {"); if (Options.isJavaUnicodeEscape ()) { - genCodeLine (" jj_input_stream = new JavaCharStream(stream, 1, 1);"); + genCodeLine (" jj_input_stream = new JavaCharStream(stream, 1, 1);"); } else { - genCodeLine (" jj_input_stream = new SimpleCharStream(stream, 1, 1);"); + genCodeLine (" jj_input_stream = new SimpleCharStream(stream, 1, 1);"); } if (Options.isTokenManagerUsesParser ()) { - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, jj_input_stream);"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, jj_input_stream);"); } else { - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(jj_input_stream);"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(jj_input_stream);"); } - genCodeLine (" token = new Token();"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { - genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); + genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -514,7 +512,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); + genCodeLine (" jj_gen = 0;"); if (s_maskindex > 0) { genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++)"); @@ -538,7 +536,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" * @param sDSL String representation to be parsed"); genCodeLine (" */"); genCodeLine (" public " + s_cu_name + "(final String sDSL) {"); - genCodeLine (" this(new " + stringReaderClass + "(sDSL));"); + genCodeLine (" this(new " + stringReaderClass + "(sDSL));"); genCodeLine (" }"); genCodeNewLine (); @@ -547,7 +545,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" * @param sDSL String representation to be parsed"); genCodeLine (" */"); genCodeLine (" public void ReInit(final String sDSL) {"); - genCodeLine (" ReInit(new " + stringReaderClass + "(sDSL));"); + genCodeLine (" ReInit(new " + stringReaderClass + "(sDSL));"); genCodeLine (" }"); } @@ -559,46 +557,46 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" public void ReInit(final " + readerInterfaceName + " stream) {"); if (Options.isJavaUnicodeEscape ()) { - genCodeLine (" if (jj_input_stream == null) {"); - genCodeLine (" jj_input_stream = new JavaCharStream(stream, 1, 1);"); - genCodeLine (" } else {"); - genCodeLine (" jj_input_stream.reInit(stream, 1, 1);"); - genCodeLine (" }"); + genCodeLine (" if (jj_input_stream == null) {"); + genCodeLine (" jj_input_stream = new JavaCharStream(stream, 1, 1);"); + genCodeLine (" } else {"); + genCodeLine (" jj_input_stream.reInit(stream, 1, 1);"); + genCodeLine (" }"); } else { - genCodeLine (" if (jj_input_stream == null) {"); - genCodeLine (" jj_input_stream = new SimpleCharStream(stream, 1, 1);"); - genCodeLine (" } else {"); - genCodeLine (" jj_input_stream.reInit(stream, 1, 1);"); - genCodeLine (" }"); + genCodeLine (" if (jj_input_stream == null) {"); + genCodeLine (" jj_input_stream = new SimpleCharStream(stream, 1, 1);"); + genCodeLine (" } else {"); + genCodeLine (" jj_input_stream.reInit(stream, 1, 1);"); + genCodeLine (" }"); } - genCodeLine (" if (token_source == null) {"); + genCodeLine (" if (token_source == null) {"); if (Options.isTokenManagerUsesParser ()) - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, jj_input_stream);"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(this, jj_input_stream);"); else - genCodeLine (" token_source = new " + s_cu_name + "TokenManager(jj_input_stream);"); - genCodeLine (" }"); + genCodeLine (" token_source = new " + s_cu_name + "TokenManager(jj_input_stream);"); + genCodeLine (" }"); genCodeNewLine (); if (Options.isTokenManagerRequiresParserAccess ()) { - genCodeLine (" token_source.ReInit(this,jj_input_stream);"); + genCodeLine (" token_source.ReInit(this,jj_input_stream);"); } else { - genCodeLine (" token_source.ReInit(jj_input_stream);"); + genCodeLine (" token_source.ReInit(jj_input_stream);"); } - genCodeLine (" token = new Token();"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { - genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); + genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -606,20 +604,20 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (s_jjtreeGenerated) { - genCodeLine (" jjtree.reset();"); + genCodeLine (" jjtree.reset();"); } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); + genCodeLine (" jj_gen = 0;"); if (s_maskindex > 0) { - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++)"); - genCodeLine (" jj_la1[i] = -1;"); + genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++)"); + genCodeLine (" jj_la1[i] = -1;"); } if (s_jj2index != 0) { - genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++)"); - genCodeLine (" jj_2_rtns[i] = new JJCalls();"); + genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++)"); + genCodeLine (" jj_2_rtns[i] = new JJCalls();"); } } genCodeLine (" }"); @@ -643,15 +641,15 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" */"); genCodeLine (" public " + s_cu_name + "(final " + s_cu_name + "TokenManager tm) {"); } - genCodeLine (" token_source = tm;"); - genCodeLine (" token = new Token();"); + genCodeLine (" token_source = tm;"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { - genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); + genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -659,14 +657,14 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); + genCodeLine (" jj_gen = 0;"); if (s_maskindex > 0) { - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); + genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); } if (s_jj2index != 0) { - genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); + genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } genCodeLine (" }"); @@ -687,15 +685,15 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" */"); genCodeLine (" public void ReInit(final " + s_cu_name + "TokenManager tm) {"); } - genCodeLine (" token_source = tm;"); - genCodeLine (" token = new Token();"); + genCodeLine (" token_source = tm;"); + genCodeLine (" token = new Token();"); if (Options.isCacheTokens ()) { - genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); + genCodeLine (" token.next = jj_nt = token_source.getNextToken();"); } else { - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.hasDepthLimit ()) { @@ -703,18 +701,18 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException } if (s_jjtreeGenerated) { - genCodeLine (" jjtree.reset();"); + genCodeLine (" jjtree.reset();"); } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen = 0;"); + genCodeLine (" jj_gen = 0;"); if (s_maskindex > 0) { - genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); + genCodeLine (" for (int i = 0; i < " + s_maskindex + "; i++) jj_la1[i] = -1;"); } if (s_jj2index != 0) { - genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); + genCodeLine (" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } genCodeLine (" }"); @@ -784,41 +782,42 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" @SuppressWarnings(\"serial\")"); genCodeLine (" private static final class LookaheadSuccess extends IllegalStateException {}"); genCodeLine (" private final LookaheadSuccess jj_ls = new LookaheadSuccess();"); - genCodeLine (" private " + eOutputLanguage.getTypeBoolean () + " jj_scan_token(int kind) {"); - genCodeLine (" if (jj_scanpos == jj_lastpos) {"); - genCodeLine (" jj_la--;"); - genCodeLine (" if (jj_scanpos.next == null) {"); - genCodeLine (" jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();"); - genCodeLine (" } else {"); - genCodeLine (" jj_lastpos = jj_scanpos = jj_scanpos.next;"); - genCodeLine (" }"); - genCodeLine (" } else {"); - genCodeLine (" jj_scanpos = jj_scanpos.next;"); - genCodeLine (" }"); + genCodeLine (" private boolean jj_scan_token(int kind) {"); + genCodeLine (" if (jj_scanpos == jj_lastpos) {"); + genCodeLine (" jj_la--;"); + genCodeLine (" if (jj_scanpos.next == null) {"); + genCodeLine (" jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();"); + genCodeLine (" } else {"); + genCodeLine (" jj_lastpos = jj_scanpos = jj_scanpos.next;"); + genCodeLine (" }"); + genCodeLine (" } else {"); + genCodeLine (" jj_scanpos = jj_scanpos.next;"); + genCodeLine (" }"); if (Options.isErrorReporting ()) { - genCodeLine (" if (jj_rescan) {"); - genCodeLine (" int i = 0; Token tok = token;"); - genCodeLine (" while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }"); - genCodeLine (" if (tok != null) jj_add_error_token(kind, i);"); + genCodeLine (" if (jj_rescan) {"); + genCodeLine (" int i = 0; Token tok = token;"); + genCodeLine (" while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }"); + genCodeLine (" if (tok != null) jj_add_error_token(kind, i);"); if (Options.isDebugLookahead ()) { - genCodeLine (" } else {"); - genCodeLine (" trace_scan(jj_scanpos, kind);"); + genCodeLine (" } else {"); + genCodeLine (" trace_scan(jj_scanpos, kind);"); } - genCodeLine (" }"); + genCodeLine (" }"); } else if (Options.isDebugLookahead ()) { - genCodeLine (" trace_scan(jj_scanpos, kind);"); + genCodeLine (" trace_scan(jj_scanpos, kind);"); } - genCodeLine (" if (jj_scanpos.kind != kind) return true;"); - genCodeLine (" if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;"); - genCodeLine (" return false;"); + genCodeLine (" if (jj_scanpos.kind != kind) return true;"); + genCodeLine (" if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;"); + genCodeLine (" return false;"); genCodeLine (" }"); genCodeNewLine (); } + genCodeNewLine (); genCodeLine (" /**"); genCodeLine (" * @return the next Token."); @@ -838,17 +837,17 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" token = token.next;"); genCodeLine (" else"); genCodeLine (" token = token.next = token_source.getNextToken();"); - genCodeLine (" jj_ntk = -1;"); + genCodeLine (" jj_ntk = -1;"); } if (Options.isErrorReporting ()) { - genCodeLine (" jj_gen++;"); + genCodeLine (" jj_gen++;"); } if (Options.isDebugParser ()) { - genCodeLine (" trace_token(token, \" (in getNextToken)\");"); + genCodeLine (" trace_token(token, \" (in getNextToken)\");"); } - genCodeLine (" return token;"); + genCodeLine (" return token;"); genCodeLine (" }"); genCodeNewLine (); genCodeLine (" /**"); @@ -956,11 +955,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" */"); genCodeLine (" public ParseException generateParseException() {"); genCodeLine (" jj_expentries.clear();"); - genCodeLine (" " + - eOutputLanguage.getTypeBoolean () + - "[] la1tokens = new " + - eOutputLanguage.getTypeBoolean () + - "[" + + genCodeLine (" boolean[] la1tokens = new boolean[" + s_tokenCount + "];"); genCodeLine (" if (jj_kind >= 0) {"); @@ -1042,9 +1037,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException if (Options.isDebugParser ()) { genCodeLine (" private int trace_indent = 0;"); - genCodeLine (" private " + - eOutputLanguage.getTypeBoolean () + - " trace_enabled = " + + genCodeLine (" private boolean trace_enabled = " + (Options.isDebugParser () ? "true" : "false") + ";"); genCodeNewLine (); @@ -1072,7 +1065,7 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException genCodeLine (" for (int i = 0; i < trace_indent; i++) {"); genCodeLine (" tracePS.print(\" \");"); genCodeLine (" }"); - genCodeLine (" tracePS.println(\"Call: \" + s);"); + genCodeLine (" tracePS.println(\"Call: \" + s);"); genCodeLine (" }"); genCodeLine (" trace_indent += 2;"); genCodeLine (" }"); @@ -1174,10 +1167,10 @@ public void start (final boolean bIsJavaModernMode) throws MetaParseException if (s_jj2index != 0 && Options.isErrorReporting ()) { genCodeLine (" static final class JJCalls {"); - genCodeLine (" int gen;"); - genCodeLine (" Token first;"); - genCodeLine (" int arg;"); - genCodeLine (" JJCalls next;"); + genCodeLine (" int gen;"); + genCodeLine (" Token first;"); + genCodeLine (" int arg;"); + genCodeLine (" JJCalls next;"); genCodeLine (" }"); genCodeNewLine (); } diff --git a/src/main/java/com/helger/pgcc/parser/exp/ExpRStringLiteral.java b/src/main/java/com/helger/pgcc/parser/exp/ExpRStringLiteral.java index 8a7a4d321..11e441574 100644 --- a/src/main/java/com/helger/pgcc/parser/exp/ExpRStringLiteral.java +++ b/src/main/java/com/helger/pgcc/parser/exp/ExpRStringLiteral.java @@ -76,8 +76,6 @@ import com.helger.commons.lang.GenericReflection; import com.helger.commons.string.StringHelper; -import com.helger.pgcc.output.EOutputLanguage; -import com.helger.pgcc.output.UnsupportedOutputLanguageException; import com.helger.pgcc.parser.CodeGenerator; import com.helger.pgcc.parser.JavaCCErrors; import com.helger.pgcc.parser.JavaCCGlobals; @@ -171,99 +169,11 @@ public static void reInitStatic () public static void dumpStrLiteralImages (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - dumpStrLiteralImagesForJava (codeGenerator); - return; - case CPP: - // For C++ - String image; - int i; - s_charCnt = 0; // Set to zero in reInit() but just to be sure - - codeGenerator.genCodeNewLine (); - codeGenerator.genCodeLine ("/** Token literal values. */"); - int literalCount = 0; - codeGenerator.switchToStaticsFile (); - - if (s_allImages == null || s_allImages.length == 0) - { - codeGenerator.genCodeLine ("static const JJString jjstrLiteralImages[] = {};"); - return; - } - - s_allImages[0] = ""; - for (i = 0; i < s_allImages.length; i++) - { - if ((image = s_allImages[i]) == null || - ((LexGenJava.s_toSkip[i / 64] & (1L << (i % 64))) == 0L && - (LexGenJava.s_toMore[i / 64] & (1L << (i % 64))) == 0L && - (LexGenJava.s_toToken[i / 64] & (1L << (i % 64))) == 0L) || - (LexGenJava.s_toSkip[i / 64] & (1L << (i % 64))) != 0L || - (LexGenJava.s_toMore[i / 64] & (1L << (i % 64))) != 0L || - LexGenJava.s_canReachOnMore[LexGenJava.s_lexStates[i]] || - ((Options.isIgnoreCase () || LexGenJava.s_ignoreCase[i]) && - (!image.equals (image.toLowerCase (Locale.US)) || !image.equals (image.toUpperCase (Locale.US))))) - { - s_allImages[i] = null; - if ((s_charCnt += 6) > 80) - { - codeGenerator.genCodeNewLine (); - s_charCnt = 0; - } - - codeGenerator.genCodeLine ("static JJChar jjstrLiteralChars_" + literalCount++ + "[] = {0};"); - continue; - } - - String toPrint = "static JJChar jjstrLiteralChars_" + literalCount++ + "[] = {"; - for (int j = 0; j < image.length (); j++) - { - toPrint += "0x" + Integer.toHexString (image.charAt (j)) + ", "; - } - - // Null char - toPrint += "0 };"; - - if ((s_charCnt += toPrint.length ()) >= 80) - { - codeGenerator.genCodeNewLine (); - s_charCnt = 0; - } - - codeGenerator.genCodeLine (toPrint); - } - - while (++i < LexGenJava.s_maxOrdinal) - { - if ((s_charCnt += 6) > 80) - { - codeGenerator.genCodeNewLine (); - s_charCnt = 0; - } - - codeGenerator.genCodeLine ("static JJChar jjstrLiteralChars_" + literalCount++ + "[] = {0};"); - continue; - } - - // Generate the array here. - codeGenerator.genCodeLine ("static const JJString " + "jjstrLiteralImages[] = {"); - for (int j = 0; j < literalCount; j++) - { - codeGenerator.genCodeLine ("jjstrLiteralChars_" + j + ", "); - } - codeGenerator.genCodeLine ("};"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + dumpStrLiteralImagesForJava (codeGenerator); } public static void dumpStrLiteralImagesForJava (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); String image; int i; s_charCnt = 0; // Set to zero in reInit() but just to be sure @@ -306,27 +216,14 @@ public static void dumpStrLiteralImagesForJava (final CodeGenerator codeGenerato for (int j = 0; j < image.length (); j++) { final char c = image.charAt (j); - switch (eOutputLanguage) + if (c <= 0xff) + toPrint.append ('\\').append (Integer.toOctalString (c)); + else { - case JAVA: - if (c <= 0xff) - toPrint.append ('\\').append (Integer.toOctalString (c)); - else - { - String hexVal = Integer.toHexString (c); - if (hexVal.length () == 3) - hexVal = "0" + hexVal; - toPrint.append ("\\u").append (hexVal); - } - break; - case CPP: - String hexVal = Integer.toHexString (c); - if (hexVal.length () == 3) - hexVal = "0" + hexVal; - toPrint.append ("\\u").append (hexVal); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); + String hexVal = Integer.toHexString (c); + if (hexVal.length () == 3) + hexVal = "0" + hexVal; + toPrint.append ("\\u").append (hexVal); } } @@ -617,76 +514,29 @@ public static void fillSubString () static void dumpStartWithStates (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("private int jjStartNfaWithStates" + LexGenJava.s_lexStateSuffix + "(int pos, int kind, int state)"); - break; - case CPP: - codeGenerator.generateMethodDefHeader ("int", - LexGenJava.s_tokMgrClassName, - "jjStartNfaWithStates" + LexGenJava.s_lexStateSuffix + "(int pos, int kind, int state)"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("private int jjStartNfaWithStates" + LexGenJava.s_lexStateSuffix + "(int pos, int kind, int state)"); codeGenerator.genCodeLine ("{"); codeGenerator.genCodeLine (" jjmatchedKind = kind;"); codeGenerator.genCodeLine (" jjmatchedPos = pos;"); if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(\" No more string literal token matches are possible.\");"); - codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" " + - "+ (jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, \" No more string literal token matches are possible.\");"); - codeGenerator.genCodeLine (" fprintf(debugStream, \" Currently matched the first %d characters as a \\\"%s\\\" token.\\n\", (jjmatchedPos + 1), addUnicodeEscapes(tokenImage[jjmatchedKind]).c_str());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(\" No more string literal token matches are possible.\");"); + codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" " + + "+ (jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); } - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); - codeGenerator.genCodeLine (" catch(java.io.IOException e) { return pos + 1; }"); - break; - case CPP: - codeGenerator.genCodeLine (" if (input_stream->endOfInput()) { return pos + 1; }"); - codeGenerator.genCodeLine (" curChar = input_stream->readChar();"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); + codeGenerator.genCodeLine (" catch(java.io.IOException e) { return pos + 1; }"); + if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(" + - (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + - "\"Current character : \" + " + - Options.getTokenMgrErrorClass () + - ".addEscapes(String.valueOf(curChar)) + \" (\" + curChar + \") " + - "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, " + - "\"<%s>Current character : %c(%d) at line %d column %d\\n\"," + - "addUnicodeEscapes(lexStateNames[curLexState]).c_str(), curChar, curChar, " + - "input_stream->getEndLine(), input_stream->getEndColumn());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(" + + (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + + "\"Current character : \" + " + + Options.getTokenMgrErrorClass () + + ".addEscapes(String.valueOf(curChar)) + \" (\" + curChar + \") " + + "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); } codeGenerator.genCodeLine (" return jjMoveNfa" + LexGenJava.s_lexStateSuffix + "(state, pos + 1);"); @@ -697,38 +547,16 @@ static void dumpStartWithStates (final CodeGenerator codeGenerator) static void dumpBoilerPlate (final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("private int jjStopAtPos(int pos, int kind)"); - break; - case CPP: - codeGenerator.generateMethodDefHeader (" int ", LexGenJava.s_tokMgrClassName, "jjStopAtPos(int pos, int kind)"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("private int jjStopAtPos(int pos, int kind)"); codeGenerator.genCodeLine ("{"); codeGenerator.genCodeLine (" jjmatchedKind = kind;"); codeGenerator.genCodeLine (" jjmatchedPos = pos;"); if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(\" No more string literal token matches are possible.\");"); - codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" + (jjmatchedPos + 1) + " + - "\" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, \" No more string literal token matches are possible.\");"); - codeGenerator.genCodeLine (" fprintf(debugStream, \" Currently matched the first %d characters as a \\\"%s\\\" token.\\n\", (jjmatchedPos + 1), addUnicodeEscapes(tokenImage[jjmatchedKind]).c_str());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(\" No more string literal token matches are possible.\");"); + codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" + (jjmatchedPos + 1) + " + + "\" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); } codeGenerator.genCodeLine (" return pos + 1;"); @@ -760,7 +588,7 @@ static void dumpBoilerPlate (final CodeGenerator codeGenerator) } @Nonnull - private static String _getCaseChar (final char c, final EOutputLanguage eOutputLanguage) + private static String _getCaseChar (final char c) { if (false) return Integer.toString (c); @@ -769,9 +597,8 @@ private static String _getCaseChar (final char c, final EOutputLanguage eOutputL if (c < 0x20 || c >= 0x7f) return Integer.toString (c); - if (eOutputLanguage.isJava ()) - if (c == '\'' || c == '\\') - return "'\\" + c + "'"; + if (c == '\'' || c == '\\') + return "'\\" + c + "'"; return "'" + c + "'"; } @@ -784,23 +611,10 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) final int maxLongsReqd = s_maxStrKind / 64 + 1; boolean ifGenerated; LexGenJava.s_maxLongsReqd[LexGenJava.s_lexStateIndex] = maxLongsReqd; - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); if (s_maxLen == 0) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine ("private int jjMoveStringLiteralDfa0" + LexGenJava.s_lexStateSuffix + "()"); - break; - case CPP: - codeGenerator.generateMethodDefHeader (" int ", - LexGenJava.s_tokMgrClassName, - "jjMoveStringLiteralDfa0" + LexGenJava.s_lexStateSuffix + "()"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine ("private int jjMoveStringLiteralDfa0" + LexGenJava.s_lexStateSuffix + "()"); dumpNullStrLiterals (codeGenerator); return; } @@ -833,14 +647,14 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) params.append (", "); else atLeastOne = true; - params.append (eOutputLanguage.getTypeLong () + " active" + j); + params.append ("long active" + j); } if (i <= s_maxLenForActive[j]) { if (atLeastOne) params.append (", "); - params.append (eOutputLanguage.getTypeLong () + " active" + j); + params.append ("long active" + j); } } else @@ -853,32 +667,20 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) params.append (", "); else atLeastOne = true; - params.append (eOutputLanguage.getTypeLong () + " old" + j + ", " + eOutputLanguage.getTypeLong () + " active" + j); + params.append ("long old" + j + ", long active" + j); } if (i <= s_maxLenForActive[j] + 1) { if (atLeastOne) params.append (", "); - params.append (eOutputLanguage.getTypeLong () + " old" + j + ", " + eOutputLanguage.getTypeLong () + " active" + j); + params.append ("long old" + j + ", long active" + j); } } } params.append (")"); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCode ("private int jjMoveStringLiteralDfa" + i + LexGenJava.s_lexStateSuffix + params); - break; - case CPP: - codeGenerator.generateMethodDefHeader (" int ", - LexGenJava.s_tokMgrClassName, - "jjMoveStringLiteralDfa" + i + LexGenJava.s_lexStateSuffix + params); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCode ("private int jjMoveStringLiteralDfa" + i + LexGenJava.s_lexStateSuffix + params); codeGenerator.genCodeLine ("{"); @@ -936,82 +738,28 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) if (i != 0 && Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + - Integer.toHexString (Integer.MAX_VALUE) + - ")"); - codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" + " + - "(jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); - codeGenerator.genCodeLine (" debugStream.println(\" Possible string literal matches : { \""); - break; - case CPP: - codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + - Integer.toHexString (Integer.MAX_VALUE) + - ")"); - codeGenerator.genCodeLine (" fprintf(debugStream, \" Currently matched the first %d characters as a \\\"%s\\\" token.\\n\", (jjmatchedPos + 1), addUnicodeEscapes(tokenImage[jjmatchedKind]).c_str());"); - codeGenerator.genCodeLine (" fprintf(debugStream, \" Possible string literal matches : { \");"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + + Integer.toHexString (Integer.MAX_VALUE) + + ")"); + codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" + " + + "(jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); + codeGenerator.genCodeLine (" debugStream.println(\" Possible string literal matches : { \""); - final StringBuilder fmt = new StringBuilder (); - final StringBuilder args = new StringBuilder (); for (int vecs = 0; vecs < s_maxStrKind / 64 + 1; vecs++) { if (i <= s_maxLenForActive[vecs]) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" +"); - codeGenerator.genCode (" jjKindsForBitVector(" + vecs + ", "); - codeGenerator.genCode ("active" + vecs + ") "); - break; - case CPP: - if (fmt.length () > 0) - { - fmt.append (", "); - args.append (", "); - } - fmt.append ("%s"); - args.append (" jjKindsForBitVector(" + vecs + ", "); - args.append ("active" + vecs + ").c_str() "); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" +"); + codeGenerator.genCode (" jjKindsForBitVector(" + vecs + ", "); + codeGenerator.genCode ("active" + vecs + ") "); } } - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" + \" } \");"); - break; - case CPP: - fmt.append ("}\\n"); - codeGenerator.genCodeLine (" fprintf(debugStream, \"" + fmt + "\"," + args + ");"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" + \" } \");"); } - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); - codeGenerator.genCodeLine (" catch(java.io.IOException e) {"); - break; - case CPP: - codeGenerator.genCodeLine (" if (input_stream->endOfInput()) {"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" try { curChar = input_stream.readChar(); }"); + codeGenerator.genCodeLine (" catch(java.io.IOException e) {"); if (!LexGenJava.s_mixed[LexGenJava.s_lexStateIndex] && NfaState.s_generatedStates != 0) { @@ -1037,24 +785,11 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) if (i != 0 && Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + - Integer.toHexString (Integer.MAX_VALUE) + - ")"); - codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" + " + - "(jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); - break; - case CPP: - codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + - Integer.toHexString (Integer.MAX_VALUE) + - ")"); - codeGenerator.genCodeLine (" fprintf(debugStream, \" Currently matched the first %d characters as a \\\"%s\\\" token.\\n\", (jjmatchedPos + 1), addUnicodeEscapes(tokenImage[jjmatchedKind]).c_str());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" if (jjmatchedKind != 0 && jjmatchedKind != 0x" + + Integer.toHexString (Integer.MAX_VALUE) + + ")"); + codeGenerator.genCodeLine (" debugStream.println(\" Currently matched the first \" + " + + "(jjmatchedPos + 1) + \" characters as a \" + tokenImage[jjmatchedKind] + \" token.\");"); } codeGenerator.genCodeLine (" return " + i + ";"); @@ -1080,39 +815,14 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) if (i != 0) { - switch (eOutputLanguage) - { - case JAVA: - // Nothing - break; - case CPP: - codeGenerator.genCodeLine (" curChar = input_stream->readChar();"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } - if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(" + - (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + - "\"Current character : \" + " + - Options.getTokenMgrErrorClass () + - ".addEscapes(String.valueOf(curChar)) + \" (\" + curChar + \") " + - "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, " + - "\"<%s>Current character : %c(%d) at line %d column %d\\n\"," + - "addUnicodeEscapes(lexStateNames[curLexState]).c_str(), curChar, curChar, " + - "input_stream->getEndLine(), input_stream->getEndColumn());"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(" + + (LexGenJava.s_maxLexStates > 1 ? "\"<\" + lexStateNames[curLexState] + \">\" + " : "") + + "\"Current character : \" + " + + Options.getTokenMgrErrorClass () + + ".addEscapes(String.valueOf(curChar)) + \" (\" + curChar + \") " + + "at line \" + input_stream.getEndLine() + \" column \" + input_stream.getEndColumn());"); } } @@ -1170,13 +880,13 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) if (Options.isIgnoreCase ()) { if (c != Character.toUpperCase (c)) - codeGenerator.genCodeLine (" case " + _getCaseChar (Character.toUpperCase (c), eOutputLanguage) + ":"); + codeGenerator.genCodeLine (" case " + _getCaseChar (Character.toUpperCase (c)) + ":"); if (c != Character.toLowerCase (c)) - codeGenerator.genCodeLine (" case " + _getCaseChar (Character.toLowerCase (c), eOutputLanguage) + ":"); + codeGenerator.genCodeLine (" case " + _getCaseChar (Character.toLowerCase (c)) + ":"); } - codeGenerator.genCodeLine (" case " + _getCaseChar (c, eOutputLanguage) + ":"); + codeGenerator.genCodeLine (" case " + _getCaseChar (c) + ":"); long matchedKind; final String prefix = (i == 0) ? " " : " "; @@ -1209,9 +919,9 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) codeGenerator.genCodeLine ("((active" + j + " & " + - eOutputLanguage.getLongHex (1L << k) + + CodeGenerator.getLongHex (1L << k) + ") != " + - eOutputLanguage.getLongPlain (0) + + CodeGenerator.getLongPlain (0) + ")"); } @@ -1310,7 +1020,7 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) else atLeastOne = true; - codeGenerator.genCode (eOutputLanguage.getLongHex (info.m_validKinds[j])); + codeGenerator.genCode (CodeGenerator.getLongHex (info.m_validKinds[j])); } if ((i + 1) <= s_maxLenForActive[j]) @@ -1318,7 +1028,7 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) if (atLeastOne) codeGenerator.genCode (", "); - codeGenerator.genCode (eOutputLanguage.getLongHex (info.m_validKinds[j])); + codeGenerator.genCode (CodeGenerator.getLongHex (info.m_validKinds[j])); } codeGenerator.genCodeLine (");"); } @@ -1338,9 +1048,9 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) atLeastOne = true; if (info.m_validKinds[j] != 0L) - codeGenerator.genCode ("active" + j + ", " + eOutputLanguage.getLongHex (info.m_validKinds[j])); + codeGenerator.genCode ("active" + j + ", " + CodeGenerator.getLongHex (info.m_validKinds[j])); else - codeGenerator.genCode ("active" + j + ", " + eOutputLanguage.getLongPlain (0)); + codeGenerator.genCode ("active" + j + ", " + CodeGenerator.getLongPlain (0)); } if ((i + 1) <= s_maxLenForActive[j] + 1) @@ -1348,9 +1058,9 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) if (atLeastOne) codeGenerator.genCode (", "); if (info.m_validKinds[j] != 0L) - codeGenerator.genCode ("active" + j + ", " + eOutputLanguage.getLongHex (info.m_validKinds[j])); + codeGenerator.genCode ("active" + j + ", " + CodeGenerator.getLongHex (info.m_validKinds[j])); else - codeGenerator.genCode ("active" + j + ", " + eOutputLanguage.getLongPlain (0)); + codeGenerator.genCode ("active" + j + ", " + CodeGenerator.getLongPlain (0)); } codeGenerator.genCodeLine (");"); @@ -1387,17 +1097,7 @@ public static void dumpDfaCode (final CodeGenerator codeGenerator) if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(\" No string literal matches possible.\");"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, \" No string literal matches possible.\\n\");"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(\" No string literal matches possible.\");"); } if (NfaState.s_generatedStates != 0) @@ -1622,7 +1322,6 @@ static void dumpNfaStartStatesCode (final Map [] statesForPos, return; } - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); int i; final int maxKindsReqd = s_maxStrKind / 64 + 1; boolean condGenerated = false; @@ -1630,38 +1329,16 @@ static void dumpNfaStartStatesCode (final Map [] statesForPos, final StringBuilder params = new StringBuilder (); for (i = 0; i < maxKindsReqd - 1; i++) - params.append (eOutputLanguage.getTypeLong () + " active" + i + ", "); - params.append (eOutputLanguage.getTypeLong () + " active" + i + ")"); + params.append ("long active" + i + ", "); + params.append ("long active" + i + ")"); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCode ("private final int jjStopStringLiteralDfa" + LexGenJava.s_lexStateSuffix + "(int pos, " + params); - break; - case CPP: - codeGenerator.generateMethodDefHeader (" int", - LexGenJava.s_tokMgrClassName, - "jjStopStringLiteralDfa" + LexGenJava.s_lexStateSuffix + "(int pos, " + params); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCode ("private final int jjStopStringLiteralDfa" + LexGenJava.s_lexStateSuffix + "(int pos, " + params); codeGenerator.genCodeLine ("{"); if (Options.isDebugTokenManager ()) { - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCodeLine (" debugStream.println(\" No more string literal token matches are possible.\");"); - break; - case CPP: - codeGenerator.genCodeLine (" fprintf(debugStream, \" No more string literal token matches are possible.\");"); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCodeLine (" debugStream.println(\" No more string literal token matches are possible.\");"); } codeGenerator.genCodeLine (" switch (pos)"); @@ -1694,9 +1371,9 @@ static void dumpNfaStartStatesCode (final Map [] statesForPos, codeGenerator.genCode ("(active" + j + " & " + - eOutputLanguage.getLongHex (actives[j]) + + CodeGenerator.getLongHex (actives[j]) + ") != " + - eOutputLanguage.getLongPlain (0)); + CodeGenerator.getLongPlain (0)); } if (condGenerated) @@ -1776,20 +1453,10 @@ static void dumpNfaStartStatesCode (final Map [] statesForPos, params.setLength (0); params.append ("(int pos, "); for (i = 0; i < maxKindsReqd - 1; i++) - params.append (eOutputLanguage.getTypeLong () + " active" + i + ", "); - params.append (eOutputLanguage.getTypeLong () + " active" + i + ")"); + params.append ("long active" + i + ", "); + params.append ("long active" + i + ")"); - switch (eOutputLanguage) - { - case JAVA: - codeGenerator.genCode ("private final int jjStartNfa" + LexGenJava.s_lexStateSuffix + params); - break; - case CPP: - codeGenerator.generateMethodDefHeader ("int ", LexGenJava.s_tokMgrClassName, "jjStartNfa" + LexGenJava.s_lexStateSuffix + params); - break; - default: - throw new UnsupportedOutputLanguageException (eOutputLanguage); - } + codeGenerator.genCode ("private final int jjStartNfa" + LexGenJava.s_lexStateSuffix + params); codeGenerator.genCodeLine ("{"); if (LexGenJava.s_mixed[LexGenJava.s_lexStateIndex]) diff --git a/src/main/java/com/helger/pgcc/parser/table/TableDrivenJavaCodeGenerator.java b/src/main/java/com/helger/pgcc/parser/table/TableDrivenJavaCodeGenerator.java index 568936c21..9882fedfc 100644 --- a/src/main/java/com/helger/pgcc/parser/table/TableDrivenJavaCodeGenerator.java +++ b/src/main/java/com/helger/pgcc/parser/table/TableDrivenJavaCodeGenerator.java @@ -41,7 +41,6 @@ import java.util.Map; import com.helger.commons.string.StringHelper; -import com.helger.pgcc.output.EOutputLanguage; import com.helger.pgcc.parser.CodeGenerator; import com.helger.pgcc.parser.Options; import com.helger.pgcc.parser.TokenizerData; @@ -147,11 +146,9 @@ private void _dumpDfaTables (final CodeGenerator codeGenerator, final TokenizerD private void dumpNfaTables (final CodeGenerator codeGenerator, final TokenizerData tokenizerData) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); - // WE do the following for java so that the generated code is reasonable // size and can be compiled. May not be needed for other languages. - codeGenerator.genCodeLine ("private static final " + eOutputLanguage.getTypeLong () + "[][] jjCharData = {"); + codeGenerator.genCodeLine ("private static final long[][] jjCharData = {"); final Map nfa = tokenizerData.m_nfa; for (int i = 0; i < nfa.size (); i++) { @@ -178,7 +175,7 @@ private void dumpNfaTables (final CodeGenerator codeGenerator, final TokenizerDa if (k > 0) codeGenerator.genCode (", "); codeGenerator.genCode (rep + ", "); - codeGenerator.genCode (eOutputLanguage.getLongHex (longs[k])); + codeGenerator.genCode (CodeGenerator.getLongHex (longs[k])); k += rep - 1; } codeGenerator.genCode ("}"); @@ -421,14 +418,13 @@ private void _dumpLexicalActions (final Map a private static void generateBitVector (final String name, final BitSet bits, final CodeGenerator codeGenerator) { - final EOutputLanguage eOutputLanguage = codeGenerator.getOutputLanguage (); - codeGenerator.genCodeLine ("private static final " + eOutputLanguage.getTypeLong () + "[] " + name + " = {"); + codeGenerator.genCodeLine ("private static final long[] " + name + " = {"); final long [] longs = bits.toLongArray (); for (int i = 0; i < longs.length; i++) { if (i > 0) codeGenerator.genCode (", "); - codeGenerator.genCode (eOutputLanguage.getLongHex (longs[i])); + codeGenerator.genCode (CodeGenerator.getLongHex (longs[i])); } codeGenerator.genCodeLine ("};"); } diff --git a/src/main/javacc/ConditionParser.jj b/src/main/javacc/ConditionParser.jj index e2f09a1f8..1d43062e1 100644 --- a/src/main/javacc/ConditionParser.jj +++ b/src/main/javacc/ConditionParser.jj @@ -117,7 +117,7 @@ TOKEN : boolean CompilationUnit(Map options): { - boolean value; + boolean value; this.options = options; } { @@ -126,13 +126,13 @@ boolean CompilationUnit(Map options): boolean ConditionalExpression(): { - boolean value; + boolean value; } { value = ConditionalAndExpression() { if (value) return true; } - + ( "||" - value = ConditionalAndExpression() { if (value) return true; } + value = ConditionalAndExpression() { if (value) return true; } )* { return false; } @@ -140,7 +140,7 @@ boolean ConditionalExpression(): boolean ConditionalAndExpression(): { - boolean value; + boolean value; } { value = UnaryExpressionNotPlusMinus() { if (!value) return false; } @@ -155,7 +155,7 @@ boolean ConditionalAndExpression(): boolean UnaryExpressionNotPlusMinus(): { - boolean value; + boolean value; } { ( "~" | "!" ) value = UnaryExpressionNotPlusMinus() { return !value; } @@ -164,10 +164,10 @@ boolean UnaryExpressionNotPlusMinus(): boolean UnaryExpression(): { - boolean value; + boolean value; } { - value = Literal() { return value; } + value = Literal() { return value; } | "(" value = ConditionalExpression() ")" { return value; } | @@ -176,7 +176,7 @@ boolean UnaryExpression(): boolean Literal(): { - boolean value; + boolean value; } { value = BooleanLiteral() { return value; } @@ -194,25 +194,25 @@ boolean Name() : String name; } { - - - { - name = getToken(0).image.trim(); - - final Object obj = options.get(name); - if (obj instanceof Boolean) - { - return ((Boolean)obj).booleanValue(); - } - if (obj instanceof String) - { - final String string = ((String)obj).trim(); - return string.length() > 0 && !string.equalsIgnoreCase("false") && !string.equalsIgnoreCase("no"); - } - - // Unsupported data type in options map + + + { + name = getToken(0).image.trim(); + + final Object obj = options.get(name); + if (obj instanceof Boolean) + { + return ((Boolean)obj).booleanValue(); + } + if (obj instanceof String) + { + final String string = ((String)obj).trim(); + return string.length() > 0 && !string.equalsIgnoreCase("false") && !string.equalsIgnoreCase("no"); + } + + // Unsupported data type in options map return false; - } + } } /* IDENTIFIERS */ diff --git a/src/main/javacc/JavaCC.jj b/src/main/javacc/JavaCC.jj index dcc413617..52d321e8e 100644 --- a/src/main/javacc/JavaCC.jj +++ b/src/main/javacc/JavaCC.jj @@ -127,11 +127,6 @@ public class JavaCCParser extends JavaCCParserInternals { */ private boolean m_bJumpPatched = false; - protected static boolean isJavaLanguage() - { - return Options.getOutputLanguage ().isJava (); - } - /* * 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. @@ -148,11 +143,8 @@ public class JavaCCParser extends JavaCCParserInternals { * result type as an error for a java grammar */ private static boolean isAllowed(Token t) { - if (isJavaLanguage()) - { - if (t.kind == STAR || t.kind == BIT_AND || t.kind == CONST) - return false; - } + if (t.kind == STAR || t.kind == BIT_AND || t.kind == CONST) + return false; return true; } @@ -241,7 +233,6 @@ TOKEN : | < _PARSER_BEGIN: "PARSER_BEGIN" > | < _PARSER_END: "PARSER_END" > | < _JAVACODE: "JAVACODE" > -| < _CPPCODE: "CPPCODE" > | < _TOKEN: "TOKEN" > | < _SPECIAL_TOKEN: "SPECIAL_TOKEN" > | < _MORE: "MORE" > @@ -559,14 +550,6 @@ void javacc_input() : { m_processing_cu = true; m_sParserClassName = id1; - - if (!isJavaLanguage()) { - JavaCCGlobals.setOtherLanguageDeclTokenBegin (getToken(1)); - while(getToken(1).kind != _PARSER_END) { - getNextToken(); - } - JavaCCGlobals.setOtherLanguageDeclTokenEnd (getToken(1)); - } } CompilationUnit() { @@ -652,14 +635,6 @@ void production() : * "bnf_production". */ javacode_production() -| - LOOKAHEAD(1) - /* - * Since CPPCODE is both a JavaCC reserved word and a Java identifier, - * we need to give preference to "cppcode_production" over - * "bnf_production". - */ - cppcode_production() | LOOKAHEAD(1) /* @@ -722,48 +697,6 @@ void javacode_production() : } } -void cppcode_production() : - { - CodeProductionCpp p = new CodeProductionCpp(); - String lhs; - Token t = getToken(1); - p.setFirstToken(t); - List excName; - p.setThrowsList(new ArrayList>()); - p.setLine(t.beginLine); - p.setColumn(t.beginColumn); - } -{ - "CPPCODE" - AccessModifier(p) - ResultType(p.getReturnTypeTokens()) - lhs=identifier() { p.setLhs(lhs); } - FormalParameters(p.getParameterListTokens()) - [ "throws" - { - excName = new ArrayList(); - } - Name(excName) - { - p.getThrowsList().add(excName); - } - ( - { - excName = new ArrayList(); - } - "," Name(excName) - { - p.getThrowsList().add(excName); - } - )* - ] - Block(p.getCodeTokens()) - { - p.setLastToken(getToken(0)); - addProduction(p); - } -} - void bnf_production() : { Container c = new Container(); @@ -895,13 +828,6 @@ void token_manager_decls() : } { t="TOKEN_MGR_DECLS" ":" - { - if (!isJavaLanguage()) { - getNextToken(); // eat { - eatUptoCloseBrace(decls); - getNextToken(); // eat } - } - } [ ClassOrInterfaceBody(false, decls) ] { @@ -1097,17 +1023,6 @@ ExpLookahead local_lookahead() : ] [ LOOKAHEAD(0, { emptyLA || commaAtEnd } ) "{" - { - if (!isJavaLanguage()) { - int b = 0; - while(getToken(1).kind != RBRACE || --b > 0) { - t = getNextToken(); - la.getActionTokens().add(t); - if (t.kind == LBRACE) b++; - } - } - } - [ Expression(la.getActionTokens()) ] "}" { @@ -1200,15 +1115,11 @@ void expansion_unit(Container c) : ("catch" "(" [ "final" ] { - if (!isJavaLanguage()) { - while (getToken(1).kind != RPAREN) - getNextToken(); - } t = getToken(0); t.kind = IDENTIFIER; t.image = "..."; } - [ LOOKAHEAD({isJavaLanguage()}) Name(vec) t= ] + [ LOOKAHEAD( { true } ) Name(vec) t= ] ")" { types.add(vec); @@ -1587,9 +1498,7 @@ void CompilationUnit() : ( ImportDeclaration() )* ( TypeDeclaration() )* { - if (Options.getOutputLanguage().isJava()) { - insertionpointerrors(getToken(1)); - } + insertionpointerrors(getToken(1)); } } @@ -2432,11 +2341,6 @@ void Arguments(List tokens) : "(" { first = getToken(1); - // Added by Sreenivas Viswanadha for 6.0 - // TODO :: 2013/07/16 -- cba : Think this condition should be if the language IS C++, not if the language ISN'T Java ... - if (!isJavaLanguage()) { - eatUptoRParen(null); - } } [ ArgumentList() ] { @@ -2556,9 +2460,6 @@ void Block(List tokens) : "{" { first = getToken(1); - if (!isJavaLanguage()) { - eatUptoCloseBrace(null); - } } ( BlockStatement() )* { diff --git a/src/main/jjtree/JJTree.jjt b/src/main/jjtree/JJTree.jjt index 742a31ecb..84fb01b3c 100644 --- a/src/main/jjtree/JJTree.jjt +++ b/src/main/jjtree/JJTree.jjt @@ -50,12 +50,12 @@ package com.helger.pgcc.jjtree; public class JJTreeParser { void jjtreeOpenNodeScope(final Node n) { - ((JJTreeNode)n).setFirstToken(getToken(1)); + ((JJTreeNode)n).setFirstToken(getToken(1)); } void jjtreeCloseNodeScope(final Node n) { - ((JJTreeNode)n).setLastToken(getToken(0)); + ((JJTreeNode)n).setLastToken(getToken(0)); } /** @@ -69,8 +69,6 @@ public class JJTreeParser { return true; } - protected boolean isJavaLanguage = true; - private void eatUptoCloseBrace() { int b = 1; while(getToken(1).kind != RBRACE || --b != 0) { @@ -326,9 +324,9 @@ TOKEN : | < BIT_OR: "|" > | < XOR: "^" > | < REM: "%" > -// | < LSHIFT: "<<" > -// | < RSIGNEDSHIFT: ">>" > -// | < RUNSIGNEDSHIFT: ">>>" > +// | < LSHIFT: "<<" > +// | < RSIGNEDSHIFT: ">>" > +// | < RUNSIGNEDSHIFT: ">>>" > | < PLUSASSIGN: "+=" > | < MINUSASSIGN: "-=" > | < STARASSIGN: "*=" > @@ -337,9 +335,9 @@ TOKEN : | < ORASSIGN: "|=" > | < XORASSIGN: "^=" > | < REMASSIGN: "%=" > -// | < LSHIFTASSIGN: "<<=" > -// | < RSIGNEDSHIFTASSIGN: ">>=" > -// | < RUNSIGNEDSHIFTASSIGN: ">>>=" > +// | < LSHIFTASSIGN: "<<=" > +// | < RSIGNEDSHIFTASSIGN: ">>=" > +// | < RUNSIGNEDSHIFTASSIGN: ">>>=" > } @@ -369,34 +367,25 @@ TOKEN : ************************************************/ void javacc_input() #Grammar : - { - Token t; - } -{ - javacc_options() { - isJavaLanguage = JJTreeOptions.getOutputLanguage().isJava(); + Token t; } +{ + javacc_options() ( "PARSER_BEGIN" "(" t=identifier() ")" - { - JJTreeGlobals.s_parserName = t.image; - - if (!isJavaLanguage) { - while(getToken(1).kind != _PARSER_END) { - getNextToken(); - } - } - } + { + JJTreeGlobals.s_parserName = t.image; + } CompilationUnit() "PARSER_END" "(" identifier() ")" - { - if (JJTreeOptions.getNodePackage().equals("")) { - JJTreeGlobals.s_nodePackageName = JJTreeGlobals.s_packageName; - } else { - JJTreeGlobals.s_nodePackageName = JJTreeOptions.getNodePackage(); - } - } + { + if (JJTreeOptions.getNodePackage().equals("")) { + JJTreeGlobals.s_nodePackageName = JJTreeGlobals.s_packageName; + } else { + JJTreeGlobals.s_nodePackageName = JJTreeOptions.getNodePackage(); + } + } ) #CompilationUnit(true) ( ( production() )+ @@ -405,46 +394,46 @@ void javacc_input() #Grammar : } void javacc_options() : - { - } + { + } { [ LOOKAHEAD( { getToken(1).image.equals("options") }) ( "{" ( option_binding() )* "}" ) #Options ] - { - JJTreeOptions.normalize(); - } + { + JJTreeOptions.normalize(); + } } void option_binding() #OptionBinding : - { - Token o, v; - } + { + Token o, v; + } { ( o= | o="LOOKAHEAD" | o="IGNORE_CASE" | o="static" ) "=" ( v=IntegerLiteral() { - JJTreeOptions.setInputFileOption(o, v, o.image, Integer.valueOf(v.image)); - jjtThis.initialize(o.image, v.image); - } + JJTreeOptions.setInputFileOption(o, v, o.image, Integer.valueOf(v.image)); + jjtThis.initialize(o.image, v.image); + } | v=BooleanLiteral() { - JJTreeOptions.setInputFileOption(o, v, o.image, - Boolean.valueOf(v.image)); - jjtThis.initialize(o.image, v.image); - } + JJTreeOptions.setInputFileOption(o, v, o.image, + Boolean.valueOf(v.image)); + jjtThis.initialize(o.image, v.image); + } | v=StringLiteral() - { - String vs = TokenUtils.remove_escapes_and_quotes(v, v.image); - JJTreeOptions.setInputFileOption(o, v, o.image, (Object)vs); - jjtThis.initialize(o.image, vs); - } + { + String vs = TokenUtils.remove_escapes_and_quotes(v, v.image); + JJTreeOptions.setInputFileOption(o, v, o.image, (Object)vs); + jjtThis.initialize(o.image, vs); + } ) ";" } void production() : - { - } + { + } { LOOKAHEAD(1) /* @@ -474,34 +463,27 @@ void production() : } void javacode_production() #Javacode : - { - Token t1, t2; - ASTJavacode prod; - ASTNodeDescriptor nd = null; - String n; - } + { + Token t1, t2; + ASTJavacode prod; + ASTNodeDescriptor nd = null; + String n; + } { { - prod = jjtThis; - } + prod = jjtThis; + } "JAVACODE" AccessModifier() ResultType() t1=identifier() FormalParameters() - { - if (!isJavaLanguage) { - while(getToken(1).kind != LBRACE) { - getNextToken(); - } - } - } [ "throws" n=Name() - { - prod.m_throws_list.add(n); - } + { + prod.m_throws_list.add(n); + } ( "," n=Name() - { - prod.m_throws_list.add(n); - } + { + prod.m_throws_list.add(n); + } )* ] [ nd=node_descriptor() ] @@ -509,54 +491,44 @@ void javacode_production() #Javacode : // This is really a Block() t2="{" { - prod.m_name = t1.image; - prod.stmBeginLoc = t2; - if (!isJavaLanguage) { - eatUptoCloseBrace(); - } - } + prod.m_name = t1.image; + prod.stmBeginLoc = t2; + } ( ( BlockStatement() )* { - jjtThis.m_node_scope = new NodeScope(prod, nd); - } + jjtThis.m_node_scope = new NodeScope(prod, nd); + } ) #JavacodeBody "}" { - JJTreeGlobals.s_productions.put(prod.m_name, prod); - } + JJTreeGlobals.s_productions.put(prod.m_name, prod); + } } void bnf_production() #BNF : - { - Token t1, t2; - ASTBNF prod; - ASTNodeDescriptor nd = null; - NodeScope ns; - JJTreeNode eu; - String n; - } + { + Token t1, t2; + ASTBNF prod; + ASTNodeDescriptor nd = null; + NodeScope ns; + JJTreeNode eu; + String n; + } { { - prod = jjtThis; - } + prod = jjtThis; + } AccessModifier() ResultType() t1=identifier() FormalParameters() - /*{ - if (!isJavaLanguage) { - while(getToken(1).kind != LBRACE && getToken(1).kind != HASH) { - getNextToken(); - } - } - }*/ [ "throws" n=Name() { - prod.m_throws_list.add(n); - } + prod.m_throws_list.add(n); + } ( "," n=Name() { - prod.m_throws_list.add(n); - } + prod.m_throws_list.add(n); + } )* ] [ nd=node_descriptor() ] @@ -565,18 +537,15 @@ void bnf_production() #BNF : // This is really a Block() t2="{" { - prod.m_name = t1.image; - prod.declBeginLoc = t2; - ns = new NodeScope(prod, nd); - if (!isJavaLanguage) { - eatUptoCloseBrace(); - } - } + prod.m_name = t1.image; + prod.declBeginLoc = t2; + ns = new NodeScope(prod, nd); + } ( ( BlockStatement() )* { - jjtThis.m_node_scope = ns; - } + jjtThis.m_node_scope = ns; + } ) #BNFDeclaration "}" @@ -584,25 +553,25 @@ void bnf_production() #BNF : ( eu=expansion_choices(prod) { - jjtThis.m_node_scope = ns; - jjtThis.m_expansion_unit = eu; - } + jjtThis.m_node_scope = ns; + jjtThis.m_expansion_unit = eu; + } ) #BNFNodeScope "}" { - JJTreeGlobals.s_productions.put(prod.m_name, prod); - } + JJTreeGlobals.s_productions.put(prod.m_name, prod); + } } void AccessModifier() : {} { - ( "public" | "protected" | "private" )? + ( "public" | "protected" | "private" )? } void regular_expr_production() #RE : - { - } + { + } { [ LOOKAHEAD(2) "<" "*" ">" @@ -614,23 +583,18 @@ void regular_expr_production() #RE : } void token_manager_decls() #TokenDecls : - { - } + { + } { "TOKEN_MGR_DECLS" ":" { - if (!isJavaLanguage) { - getNextToken(); // eat { - eatUptoCloseBrace(); - getNextToken(); // eat } - } } [ ClassOrInterfaceBody() ] } void regexpr_kind() : - { - } + { + } { "TOKEN" | @@ -650,20 +614,20 @@ void regexpr_spec() #RESpec : } JJTreeNode expansion_choices(ASTProduction p) #BNFChoice(>1) : - { - } + { + } { expansion(p) ( "|" expansion(p) )* { - return (JJTreeNode)jjtree.peekNode(); - } + return (JJTreeNode)jjtree.peekNode(); + } } void expansion(ASTProduction p) #BNFSequence(>1) : - { - JJTreeNode eu; - ASTNodeDescriptor nd = null; - } + { + JJTreeNode eu; + ASTNodeDescriptor nd = null; + } { ( LOOKAHEAD(1) @@ -675,19 +639,19 @@ void expansion(ASTProduction p) #BNFSequence(>1) : eu=expansion_unit(p) [ nd=node_descriptor() ] { - if (jjtree.nodeCreated()) { - jjtThis.m_node_scope = new NodeScope(p, nd); - jjtThis.m_expansion_unit = eu; - } - } + if (jjtree.nodeCreated()) { + jjtThis.m_node_scope = new NodeScope(p, nd); + jjtThis.m_expansion_unit = eu; + } + } ) #ExpansionNodeScope(>1) )+ } void local_lookahead(ASTProduction p) : - { - boolean commaAtEnd = false, emptyLA = true; - } + { + boolean commaAtEnd = false, emptyLA = true; + } { [ /* @@ -698,43 +662,40 @@ void local_lookahead(ASTProduction p) : */ LOOKAHEAD(1) IntegerLiteral() - { - emptyLA = false; - } + { + emptyLA = false; + } ] [ LOOKAHEAD(0, { !emptyLA && (getToken(1).kind != RPAREN) } ) "," - { - commaAtEnd = true; - } + { + commaAtEnd = true; + } ] [ LOOKAHEAD(0, { getToken(1).kind != RPAREN && getToken(1).kind != LBRACE } ) expansion_choices(p) - { - emptyLA = false; commaAtEnd = false; - } + { + emptyLA = false; commaAtEnd = false; + } ] [ LOOKAHEAD(0, { !emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN) } ) "," - { - commaAtEnd = true; - } + { + commaAtEnd = true; + } ] [ LOOKAHEAD(0, { emptyLA || commaAtEnd } ) "{" { - if (!isJavaLanguage) { - eatUptoCloseBrace(); - } } [ Expression() ] "}" ] } JJTreeNode expansion_unit(ASTProduction p) : - { - Token t; - } + { + Token t; + } { ( LOOKAHEAD(1) @@ -755,9 +716,6 @@ JJTreeNode expansion_unit(ASTProduction p) : ( "try" "{" { - if (!isJavaLanguage) { - eatUptoCloseBrace(); - } } [ expansion_choices(p) ] "}" @@ -775,7 +733,7 @@ JJTreeNode expansion_unit(ASTProduction p) : regular_expression() [ "." t= ] | ( identifier() Arguments() ) #BNFNonTerminal ) - + ) #BNFAssignment(>1) | t="(" expansion_choices(p) ")" @@ -792,18 +750,18 @@ JJTreeNode expansion_unit(ASTProduction p) : {} #BNFParenthesized(1) ) - { - ((JJTreeNode)jjtree.peekNode()).setFirstToken(t); - } + { + ((JJTreeNode)jjtree.peekNode()).setFirstToken(t); + } ) { - return (JJTreeNode)jjtree.peekNode(); - } + return (JJTreeNode)jjtree.peekNode(); + } } void regular_expression() : - { - } + { + } { StringLiteral() #REStringLiteral | @@ -835,9 +793,9 @@ void complex_regular_expression() #RESequence(>1) : } void complex_regular_expression_unit() : - { - Token t; - } + { + Token t; + } { StringLiteral() #REStringLiteral | @@ -861,9 +819,9 @@ void complex_regular_expression_unit() : {} #REParenthesized(1) ) - { - ((JJTreeNode)jjtree.peekNode()).setFirstToken(t); - } + { + ((JJTreeNode)jjtree.peekNode()).setFirstToken(t); + } } void character_list() #RECharList : @@ -885,8 +843,8 @@ Token identifier() : { t= { - return t; - } + return t; + } } @@ -905,31 +863,31 @@ ASTNodeDescriptor node_descriptor() #NodeDescriptor : s=Name() { jjtThis.m_name = s; - } + } | t= { jjtThis.m_name = t.image; - } + } ) [ LOOKAHEAD(1) "(" [ ">" { - jjtThis.m_isGT = true; - } + jjtThis.m_isGT = true; + } ] node_descriptor_expression() - { - jjtThis.m_expression = - (ASTNodeDescriptorExpression)jjtree.peekNode(); - } + { + jjtThis.m_expression = + (ASTNodeDescriptorExpression)jjtree.peekNode(); + } ")" ] { - jjtThis.setNodeIdValue(); - return jjtThis; - } + jjtThis.setNodeIdValue(); + return jjtThis; + } } @@ -985,8 +943,8 @@ String JavaIdentifier() : | "EOF" ) { - return token.image; - } + return token.image; + } } /* @@ -1009,8 +967,8 @@ void PackageDeclaration() : { Modifiers() "package" s=Name() ";" { - JJTreeGlobals.s_packageName = s; - } + JJTreeGlobals.s_packageName = s; + } } void ImportDeclaration() : @@ -1091,15 +1049,15 @@ void ClassOrInterfaceDeclaration(): [ ExtendsList() ] [ { t = getToken(1); } ImplementsList() ] { - if (s.equals(JJTreeGlobals.s_parserName)) { - if (t != null) { - JJTreeGlobals.s_parserImplements = t; - } else { - JJTreeGlobals.s_parserImplements = getToken(1); - } - JJTreeGlobals.s_parserClassBodyStart = getToken(1); - } - } + if (s.equals(JJTreeGlobals.s_parserName)) { + if (t != null) { + JJTreeGlobals.s_parserImplements = t; + } else { + JJTreeGlobals.s_parserImplements = getToken(1); + } + JJTreeGlobals.s_parserClassBodyStart = getToken(1); + } + } ClassOrInterfaceBody() } @@ -1314,21 +1272,21 @@ void ReferenceType(): void Template(): {} { - "template" "<" - TemplatePack() ( "," TemplatePack() )* - ">" + "template" "<" + TemplatePack() ( "," TemplatePack() )* + ">" } void TemplatePack(): {} { - TemplateBase() ["..."] + TemplateBase() ["..."] } void TemplateBase(): {} { - ("class" | "typename") + ("class" | "typename") } @@ -1405,8 +1363,8 @@ String Name() : s=JavaIdentifier() ( LOOKAHEAD(2) "." ss=JavaIdentifier() { s += "." + ss; } )* { - return s; - } + return s; + } } void NameList(): @@ -1434,7 +1392,7 @@ void Expression() : { ConditionalExpression() [ - LOOKAHEAD(2) + LOOKAHEAD(2) AssignmentOperator() Expression() ] } @@ -1656,8 +1614,8 @@ Token IntegerLiteral() : { t= { - return t; - } + return t; + } } Token BooleanLiteral() : @@ -1667,13 +1625,13 @@ Token BooleanLiteral() : { t="true" { - return t; - } + return t; + } | t="false" { - return t; - } + return t; + } } Token StringLiteral() : @@ -1682,9 +1640,9 @@ Token StringLiteral() : } { t= - { - return t; - } + { + return t; + } } void NullLiteral() : @@ -1800,11 +1758,6 @@ void Block() : {} { "{" - { - if (!isJavaLanguage) { - eatUptoCloseBrace(); - } - } ( BlockStatement() )* "}" } diff --git a/src/main/resources/templates/ParseException.template b/src/main/resources/templates/ParseException.template index a259faf34..2b6eaa58a 100644 --- a/src/main/resources/templates/ParseException.template +++ b/src/main/resources/templates/ParseException.template @@ -94,22 +94,22 @@ public class ParseException extends Exception { expected.append(EOL).append(" "); } - StringBuilder sb = new StringBuilder(); + 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); + String escapedTokenText = add_escapes(tokenText); if (i != 0) sb.append (' '); if (tok.kind == 0) { - sb.append(tokenImage[0]); + sb.append(tokenImage[0]); break; } sb.append(" " + tokenImage[tok.kind]); sb.append(" \""); - sb.append(escapedTokenText); + sb.append(escapedTokenText); sb.append("\""); tok = tok.next; } @@ -119,7 +119,7 @@ public class ParseException extends Exception { .append (", column ") .append (currentToken.next.beginColumn); #fi - sb.append(".").append(EOL); + sb.append(".").append(EOL); if (expectedTokenSequences.length == 0) { // Nothing to add here diff --git a/src/main/resources/templates/TableDrivenTokenManager.template b/src/main/resources/templates/TableDrivenTokenManager.template index e62b9b4e5..fbc7c4fd8 100755 --- a/src/main/resources/templates/TableDrivenTokenManager.template +++ b/src/main/resources/templates/TableDrivenTokenManager.template @@ -50,7 +50,7 @@ ${decls} #fi { #if TOKEN_MANAGER_USES_PARSER - this.parser = parserArg; + this.parser = parserArg; #fi jjmatchedPos = 0; diff --git a/src/main/resources/templates/TokenManagerBoilerPlateMethods.template b/src/main/resources/templates/TokenManagerBoilerPlateMethods.template index ed8fd854a..8e78f8ff2 100755 --- a/src/main/resources/templates/TokenManagerBoilerPlateMethods.template +++ b/src/main/resources/templates/TokenManagerBoilerPlateMethods.template @@ -31,7 +31,7 @@ #fi { #if TOKEN_MANAGER_USES_PARSER - this.parser = parserArg; + this.parser = parserArg; #else #fi diff --git a/src/main/resources/templates/cpp/DumpDebugMethods.template b/src/main/resources/templates/cpp/DumpDebugMethods.template deleted file mode 100644 index acbdd9420..000000000 --- a/src/main/resources/templates/cpp/DumpDebugMethods.template +++ /dev/null @@ -1,51 +0,0 @@ - const JJSimpleString ${tokMgrClassName}::jjKindsForBitVector(int i, unsigned long long vec) - { - int kindCnt = 0; - JJSimpleString retVal; - if (i == 0) - kindCnt = 0; - for (int j = 0; j < 64; j++) - { - if ((vec & (1L << j)) != 0L) - { - if (kindCnt++ > 0) - retVal += ", "; - if (kindCnt % 5 == 0) - retVal += "\n "; - retVal += addUnicodeEscapes(tokenImage[i * 64 + j]); - } - } - - return retVal; - } - - const JJSimpleString ${tokMgrClassName}::jjKindsForStateVector(int lexState, int vec[], int start, int end) - { - bool kindDone[${maxOrdinal}]; - JJSimpleString retVal; - int cnt = 0; - for (int i = start; i < end; i++) - { - if (vec[i] == -1) - continue; - const int *stateSet = statesForState[curLexState][vec[i]]; - for (int j = 0; j < ${stateSetSize}; j++) - { - int state = stateSet[j]; - if (!kindDone[kindForState[lexState][state]]) - { - kindDone[kindForState[lexState][state]] = true; - if (cnt++ > 0) - retVal += ", "; - if (cnt % 5 == 0) - retVal += "\n "; - retVal += addUnicodeEscapes(tokenImage[kindForState[lexState][state]]); - } - } - } - if (cnt == 0) - return "{ }"; - else - return "{ " + retVal + " }"; - } - diff --git a/src/main/resources/templates/cpp/DumpVarDeclarations.template b/src/main/resources/templates/cpp/DumpVarDeclarations.template deleted file mode 100644 index 85597605e..000000000 --- a/src/main/resources/templates/cpp/DumpVarDeclarations.template +++ /dev/null @@ -1,16 +0,0 @@ - JAVACC_CHARSTREAM* input_stream; - int jjrounds[${stateSetSize}]; - int jjstateSet[2 * ${stateSetSize}]; - JJString jjimage; - JJString image; - int jjimageLen; - int lengthOfMatch; - JJChar curChar; - TokenManagerErrorHandler* errorHandler = nullptr; - -public: - void setErrorHandler(TokenManagerErrorHandler *eh) { - if (errorHandler) delete errorHandler, errorHandler = nullptr; - errorHandler = eh; - } - \ No newline at end of file diff --git a/src/main/resources/templates/cpp/ErrorHandler.h.template b/src/main/resources/templates/cpp/ErrorHandler.h.template deleted file mode 100644 index b665501f2..000000000 --- a/src/main/resources/templates/cpp/ErrorHandler.h.template +++ /dev/null @@ -1,84 +0,0 @@ -\#ifndef JAVACC_ERRORHANDLER_H -\#define JAVACC_ERRORHANDLER_H - -\#include -\#include -\#include "JavaCC.h" -\#include "Token.h" - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi - -JJSimpleString addUnicodeEscapes(const JJString& str); - -#if BUILD_PARSER - class ${PARSER_NAME}; - class ErrorHandler { - friend class ${PARSER_NAME}TokenManager; - friend class ${PARSER_NAME}; - protected: - int error_count; - public: - // Called when the parser encounters a different token when expecting to - // consume a specific kind of token. - // expectedKind - token kind that the parser was trying to consume. - // expectedToken - the image of the token - tokenImages[expectedKind]. - // actual - the actual token that the parser got instead. - virtual void handleUnexpectedToken(int expectedKind, const JJString& expectedToken, Token *actual, ${PARSER_NAME} *parser) { - error_count++; - fprintf(stderr, "Expecting %s at: %d:%d but got %s\n", addUnicodeEscapes(expectedToken).c_str(), actual->beginLine, actual->beginColumn, addUnicodeEscapes(actual->image).c_str()); - } - // Called when the parser cannot continue parsing. - // last - the last token successfully parsed. - // unexpected - the token at which the error occurs. - // production - the production in which this error occurrs. - virtual void handleParseError(Token *last, Token *unexpected, const JJSimpleString& production, ${PARSER_NAME} *parser) { - error_count++; - fprintf(stderr, "Encountered: %s at: %d:%d while parsing: %s\n", addUnicodeEscapes(unexpected->image).c_str(), unexpected->beginLine, unexpected->beginColumn, production.c_str()); - } - virtual int getErrorCount() { - return error_count; - } - virtual void handleOtherError(const JJString& message, ${PARSER_NAME} *parser) { - fprintf(stderr, "Error: %s\n", (char*)message.c_str()); - } - virtual ~ErrorHandler() {} - ErrorHandler() { error_count = 0; } - }; -#fi - -#if BUILD_TOKEN_MANAGER - class ${PARSER_NAME}TokenManager; - class TokenManagerErrorHandler { - friend class ${PARSER_NAME}TokenManager; - protected: - int error_count; - public: - // 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 - // - virtual void lexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, const JJString& errorAfter, JJChar curChar, ${PARSER_NAME}TokenManager* token_manager) { - // by default, we just print an error message and return. - fprintf(stderr, "Lexical error at: %d:%d. Encountered: %c after: %s.\n", errorLine, errorColumn, curChar, (EOFSeen? "EOF" : (const char*)errorAfter.c_str())); - } - virtual void lexicalError(const JJString& errorMessage, ${PARSER_NAME}TokenManager* token_manager) { - fprintf(stderr, "%s\n", (char*)errorMessage.c_str()); - } - virtual ~TokenManagerErrorHandler() {} - }; -#fi - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi - -\#endif - diff --git a/src/main/resources/templates/cpp/JavaCC.h.template b/src/main/resources/templates/cpp/JavaCC.h.template deleted file mode 100644 index 70e190a4e..000000000 --- a/src/main/resources/templates/cpp/JavaCC.h.template +++ /dev/null @@ -1,60 +0,0 @@ -\#ifndef JAVACC_JAVACC_H_ -\#define JAVACC_JAVACC_H_ - -\#include -\#include -\#include -\#include - -\#ifndef JAVACC_CHAR_TYPE -\#define JAVACC_CHAR_TYPE char -\#endif - -\#ifndef JAVACC_STRING_TYPE -\#define JAVACC_STRING_TYPE std::basic_string -\#endif - -\#define JAVACC_SIMPLE_STRING std::basic_string - -typedef JAVACC_CHAR_TYPE JJChar; -typedef JAVACC_STRING_TYPE JJString; -typedef JAVACC_STRING_TYPE JJStringBuffer; -typedef JAVACC_SIMPLE_STRING JJSimpleString; - -// Abstraction on stream classes to read a block of data into a buffer. -class ReaderStream { -public: - // Read block of data into a buffer and return the actual number read. - virtual size_t read(JAVACC_CHAR_TYPE *buffer, int offset, size_t len) { return 0; } - virtual bool endOfInput() { return true; } - virtual ~ReaderStream() {} -}; - -const JAVACC_CHAR_TYPE EMPTY[] = { 0 }; - -\#ifndef MAX -\#define MAX(a,b) (a>=b?a:b) -\#endif -\#ifndef MIN -\#define MIN(a,b) (a<=b?a:b) -\#endif -\#ifndef null -\#define null 0 -\#endif - -template -struct JJEnter -{ - JJEnter(T f_) : f{f_} {f();} - ~JJEnter(){} - T f; -}; -template -struct JJExit -{ - JJExit(T f_) : f{f_} {} - ~JJExit(){f();} - T f; -}; - -\#endif diff --git a/src/main/resources/templates/cpp/MultiNode.cc.template b/src/main/resources/templates/cpp/MultiNode.cc.template deleted file mode 100644 index cce9b18cf..000000000 --- a/src/main/resources/templates/cpp/MultiNode.cc.template +++ /dev/null @@ -1,26 +0,0 @@ -\#include "${NODE_TYPE}.h" -\#include "JJTree.h" -#if VISITOR -\#include "${PARSER_NAME}Visitor.h" -#fi - - _${NODE_TYPE}::_${NODE_TYPE}(int id) : ${NODE_CLASS:-_SimpleNode}(id){ - } - - _${NODE_TYPE}::_${NODE_TYPE}(${PARSER_NAME} *p, int id) : ${NODE_CLASS:-_SimpleNode}(p, id){ - } - -#if VISITOR - - /** Accept the visitor. **/ - ${VISITOR_RETURN_TYPE} _${NODE_TYPE}::jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data) { -#if VISITOR_RETURN_TYPE_VOID - visitor->visit(this, data); -#else - return visitor->visit(this, data); -#fi - } - - _${NODE_TYPE}::~_${NODE_TYPE}() { - } -#fi diff --git a/src/main/resources/templates/cpp/MultiNode.h.template b/src/main/resources/templates/cpp/MultiNode.h.template deleted file mode 100644 index 8bf77e6d1..000000000 --- a/src/main/resources/templates/cpp/MultiNode.h.template +++ /dev/null @@ -1,25 +0,0 @@ -\#ifndef JAVACC_${NODE_TYPE}_H -\#define JAVACC_${NODE_TYPE}_H - -\#include "JavaCC.h" -\#include "SimpleNode.h" - -#if NODE_FACTORY -\#define jjtCreate(id) new _${NODE_TYPE}(id) -\#define jjtCreate(parser, id) new _${NODE_TYPE}(parser, id); -#fi - -typedef class _${NODE_TYPE} *${NODE_TYPE}; -class _${NODE_TYPE} : public ${NODE_CLASS:-_SimpleNode} { -public: - _${NODE_TYPE}(int id); - _${NODE_TYPE}(${PARSER_NAME} *parser, int id); - virtual ~_${NODE_TYPE}(); - -#if VISITOR - /** Accept the visitor. **/ - virtual ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor visitor, ${VISITOR_DATA_TYPE:-Object} data); -#fi -}; - -\#endif diff --git a/src/main/resources/templates/cpp/MultiNode.template b/src/main/resources/templates/cpp/MultiNode.template deleted file mode 100644 index c40c1c15a..000000000 --- a/src/main/resources/templates/cpp/MultiNode.template +++ /dev/null @@ -1,24 +0,0 @@ - -class ${NODE_TYPE} : public ${NODE_CLASS:-SimpleNode} { -public: - ${NODE_TYPE}(int id) : ${NODE_CLASS:-SimpleNode}(id){ - } - ${NODE_TYPE}(${PARSER_NAME} *parser, int id) : ${NODE_CLASS:-SimpleNode}(parser, id) { - } - virtual ~${NODE_TYPE}(){ - -#if VISITOR - /** Accept the visitor. **/ - ${VISITOR_RETURN_TYPE} jjtAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const { -#if !VISITOR_RETURN_TYPE_VOID - return -#fi -#if VISITOR_METHOD_NAME_INCLUDES_TYPE_NAME - visitor->visit${NODE_TYPE}(this, data); -#else - visitor->visit(this, data); -#fi - } - } -#fi -}; diff --git a/src/main/resources/templates/cpp/ParseException.cc.template b/src/main/resources/templates/cpp/ParseException.cc.template deleted file mode 100644 index 5cbd2323e..000000000 --- a/src/main/resources/templates/cpp/ParseException.cc.template +++ /dev/null @@ -1,183 +0,0 @@ -\#include "ParseException.h" - - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi -/** - * This exception is thrown when parse errors are encountered. - * You can explicitly create objects of this exception type by - * calling the method generate_ParseException in the generated - * parser. - * - * You can modify this class to customize your error reporting - * mechanisms so long as you retain the fields. - */ - - /** - * This constructor is used by the method "generate_ParseException" - * in the generated parser. Calling this constructor generates - * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. - */ - ParseException::ParseException(Token currentTokenVal, - int** expectedTokenSequencesVal, - JJString* tokenImageVal - ) - { - 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. - */ - - ParseException::ParseException() { - } - - /** Constructor with message. */ - ParseException::ParseException(const JJString& 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. - */ - 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. - */ - 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 class. - */ - JJString* 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. - */ - JJString ParseException::initialise(Token currentToken, - int** expectedTokenSequences, - JJString* tokenImage) { -\#if 0 - //JJString eol = System.getProperty("line.separator", "\n"); - expected = new JJString(); - 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((JJChar*)"..."); - } - expected.append(eol).append(" "); - } - JJString retval = (JJChar*)"Encountered \""; - Token tok = currentToken.next; - for (int i = 0; i < maxSize; i++) { - if (i != 0) retval += (JJChar*)" "; - if (tok.kind == 0) { - retval += tokenImage[0]; - break; - } - retval += (JJChar*)" " + tokenImage[tok.kind]; - retval += (JJChar*)" \""; - retval += add_escapes(tok.image); - retval += (JJChar*)" \""; - tok = tok.next; - } - retval += (JJChar*)"\" at line " + currentToken.next.beginLine + (JJChar*)", column " + currentToken.next.beginColumn; - retval += (JJChar*)"." + eol; - if (expectedTokenSequences.length == 1) { - retval += (JJChar*)"Was expecting:" + eol + (JJChar*)" "; - } else { - retval += (JJChar*)"Was expecting one of:" + eol + (JJChar*)" "; - } - retval += expected.toString(); - return retval; -\#endif - return (JJChar*)"Parse exception"; - } - - /** - * The end of line JJString for this machine. - */ -\#define eol "\n" - - /** - * Used to convert raw characters to their escaped version - * when these raw version cannot be used as part of an ASCII - * string literal. - */ - JJString ParseException::add_escapes(const JJString& str) { -/* - JJString *retval = new JJString(); - JJChar ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - 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 = str.charAt(i)) < 0x20 || ch > 0x7e) { - JJString s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } - } - return retval.toString(); -*/ return str; - } - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi diff --git a/src/main/resources/templates/cpp/ParseException.h.template b/src/main/resources/templates/cpp/ParseException.h.template deleted file mode 100644 index bf6e87a84..000000000 --- a/src/main/resources/templates/cpp/ParseException.h.template +++ /dev/null @@ -1,100 +0,0 @@ -\#ifndef JAVACC_PARSE_EXCEPTION_H -\#define JAVACC_PARSE_EXCEPTION_H - -\#include "JavaCC.h" -\#include "Token.h" - - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi -/** - * 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 fields. - */ -class ParseException { - public: - - /** - * 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. - */ - ParseException(Token currentTokenVal, - int** expectedTokenSequencesVal, - JJString* 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. - */ - - ParseException(); - - /** Constructor with message. */ - ParseException(const JJString& 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. - */ - 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. - */ - 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 class. - */ - JJString* 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: JJString initialise(Token currentToken, - int** expectedTokenSequences, - JJString* tokenImage); - - /** - * The end of line string for this machine. - */ -\#define eol "\n" - - /** - * Used to convert raw characters to their escaped version - * when these raw version cannot be used as part of an ASCII - * string literal. - */ - JJString add_escapes(const JJString& str); - -}; - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi - -\#endif diff --git a/src/main/resources/templates/cpp/SimpleNodeImpl.template b/src/main/resources/templates/cpp/SimpleNodeImpl.template deleted file mode 100644 index 3ed67acad..000000000 --- a/src/main/resources/templates/cpp/SimpleNodeImpl.template +++ /dev/null @@ -1,140 +0,0 @@ - - SimpleNode::SimpleNode(int i) -#if NODE_EXTENDS - : ${NODE_EXTENDS}(), parent(nullptr), value(nullptr) -#fi -{ - id = i; - parser = nullptr; - value = nullptr; - } - - SimpleNode::SimpleNode(${PARSER_NAME} *p, int i) -#if NODE_EXTENDS - : ${NODE_EXTENDS}(), parent(nullptr), value(nullptr) -#fi -{ - id = i; - parser = p; - value = nullptr; - } - - void SimpleNode::jjtOpen() const { - } - - void SimpleNode::jjtClose() const { - } - - void SimpleNode::jjtSetParent(Node *n) { parent = n; } - Node *SimpleNode::jjtGetParent() const { return parent; } - - void SimpleNode::jjtAddChild(Node *n, int i) { - if (i >= children.size()) { - children.resize(i + 1, nullptr); - } - - children[i] = n; - } - - Node *SimpleNode::jjtGetChild(int i) const { - return i < children.size() ? children[i] : nullptr; - } - - int SimpleNode::jjtGetNumChildren() const { - return children.size(); - } - - void SimpleNode::jjtSetValue(void * value) { this->value = value; } - void * SimpleNode::jjtGetValue() const { return value; } - -#if TRACK_TOKENS - Token* SimpleNode::jjtGetFirstToken() const { return firstToken; } - void SimpleNode::jjtSetFirstToken(Token* token) { this->firstToken = token; } - Token* SimpleNode::jjtGetLastToken() const { return lastToken; } - void SimpleNode::jjtSetLastToken(Token* token) { this->lastToken = token; } - -#fi -#if VISITOR - /** Accept the visitor. **/ - ${VISITOR_RETURN_TYPE} SimpleNode::jjtAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const -{ -#if VISITOR_RETURN_TYPE_VOID - visitor->visit(this, data); -#else - return visitor->visit(this, data); -#fi - } - - /** Accept the visitor. **/ - void SimpleNode::childrenAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const { - for (int i = 0; i < children.size(); ++i) { - children[i]->jjtAccept(visitor, data); - } - } - -#fi - /* You can override these two methods in subclasses of SimpleNode to - customize the way the node appears when the tree is dumped. If - your output uses more than one line you should override - toString(string), otherwise overriding toString() is probably all - you need to do. */ - - JJString SimpleNode::toString() const { return jjtNodeName[id]; } - JJString SimpleNode::toString(const JJString& prefix) const { return prefix + toString(); } - - static JJChar space_char_arr_[] = { ' ', '\0' }; - static JJChar newline_char_arr_[] = { '\n', '\0' }; - static JJString space = space_char_arr_; - static JJString newline = newline_char_arr_; - - /* Override this method if you want to customize how the node dumps - out its children. */ - - void SimpleNode::dumpToBuffer(const JJString& prefix, const JJString& separator, JJString *buffer) const { - buffer->append(toString(prefix)); - buffer->append(separator); - for (int i = 0; i < children.size(); ++i) { - SimpleNode *n = (SimpleNode*)children[i]; - if (n != nullptr) { - n->dumpToBuffer(prefix + space, separator, buffer); - } - } - } - - void SimpleNode::dump(const JJString& prefix) const { - JJString *buffer = new JJString(); - dumpToBuffer(prefix, newline, buffer); - for (int i = 0; i < buffer->size(); i++) { - printf("%c", (*buffer)[i]); - } - delete buffer; - } - - // Clear list of children, and return children that we have before. - // Used in destructor to do linear destruction of tree. - std::vector SimpleNode::jjtExtractChildrenForDestruction() { - std::vector ret; - ret.swap(children); - return ret; - } - - // When tree generated, it deepness can be high, so trying to destruct it - // with simple recursive destruction can cause stack overflow. Thus we get - // each node's children, put them into destruction queue and destruct node. - // That is linear, non-recursive process, unsing memory instead of stack. - SimpleNode::~SimpleNode() { - std::vector tree = children; - std::vector nodes; - for (int i = 0; i < tree.size(); ++i) { - if (tree[i]) { - nodes = tree[i]->jjtExtractChildrenForDestruction(); - for (Node* child : nodes) { - tree.push_back(child); - } - } - } - - for (Node* node : tree) { - delete node; - } - } diff --git a/src/main/resources/templates/cpp/SimpleNodeInterface.template b/src/main/resources/templates/cpp/SimpleNodeInterface.template deleted file mode 100644 index 57720fbd4..000000000 --- a/src/main/resources/templates/cpp/SimpleNodeInterface.template +++ /dev/null @@ -1,69 +0,0 @@ -#if NODE_EXTENDS -class SimpleNode : public ${NODE_EXTENDS}, public Node { -#else -class SimpleNode : public Node { -#fi - - protected: Node *parent; - protected: std::vector children; - protected: int id; - protected: void * value; - protected: ${PARSER_NAME} *parser; - //protected: int numChildren; -#if TRACK_TOKENS - protected: Token *firstToken; - protected: Token *lastToken; -#fi - - public: SimpleNode(int i); - public: SimpleNode(${PARSER_NAME} *p, int i); - -//#if !NODE_FACTORY -//\#define jjtCreate(id) new SimpleNode(id) -//\#define jjtCreate(p, id) new SimpleNode(p, id) -//#fi - - public: virtual void jjtOpen() const; - public: virtual void jjtClose() const; - public: virtual void jjtSetParent(Node *n); - public: virtual Node *jjtGetParent() const; - public: virtual void jjtAddChild(Node *n, int i); - public: virtual Node *jjtGetChild(int i) const; - public: virtual int jjtGetNumChildren() const; - public: virtual void jjtSetValue(void * value); - public: virtual void * jjtGetValue() const; - -#if TRACK_TOKENS - public: virtual Token *jjtGetFirstToken() const; - public: virtual void jjtSetFirstToken(Token* token); - public: virtual Token *jjtGetLastToken() const; - public: virtual void jjtSetLastToken(Token* token); - -#fi -#if VISITOR - /** Accept the visitor. **/ - public: virtual ${VISITOR_RETURN_TYPE:-void} jjtAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const; - - /** Accept the visitor. **/ - public: virtual void childrenAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const; -#fi - /* You can override these two methods in subclasses of SimpleNode to - customize the way the node appears when the tree is dumped. If - your output uses more than one line you should override - toString(string), otherwise overriding toString() is probably all - you need to do. */ - - public: virtual JJString toString() const; - public: virtual JJString toString(const JJString& prefix) const; - - /* Override this method if you want to customize how the node dumps - out its children. */ - - public: virtual void dump(JJString prefix) const; - public: virtual void dumpToBuffer(const JJString& prefix, const JJString& separator, JJString *sb) const; - private: virtual std::vector jjtExtractChildrenForDestruction() override; - public: virtual ~SimpleNode(); - public: virtual int getId() const { - return id; - } -}; diff --git a/src/main/resources/templates/cpp/Token.cc.template b/src/main/resources/templates/cpp/Token.cc.template deleted file mode 100644 index e861c920d..000000000 --- a/src/main/resources/templates/cpp/Token.cc.template +++ /dev/null @@ -1,98 +0,0 @@ -\#include "Token.h" - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi - -/** - * Describes the input token stream. - */ - - /** - * 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. - */ - void * Token::getValue() { - return nullptr; - } - - /** - * No-argument constructor - */ - Token::Token() : - beginLine(0), beginColumn(0), endLine(0), endColumn(0) - { - this->next = nullptr; - this->specialToken = nullptr; - } - - /** - * Constructs a new token for the specified Image. - */ - Token::Token(int kind) : - beginLine(0), beginColumn(0), endLine(0), endColumn(0) - { - this->kind = kind; - this->next = nullptr; - this->specialToken = nullptr; - } - - /** - * Constructs a new token for the specified Image and Kind. - */ - Token::Token(int kind, const JJString& image) - : beginLine(0), beginColumn(0), endLine(0), endColumn(0) - { - this->kind = kind; - this->image = image; - this->next = nullptr; - this->specialToken = nullptr; - } - - /** - * Returns the image. - */ - const JJString& Token::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. - */ - Token *Token::newToken(int ofKind, const JJString& image) - { - switch(ofKind) - { - default : return new Token(ofKind, image); - } - } - - Token *Token::newToken(int ofKind) - { - return newToken(ofKind, JJString()); - } - - Token::~Token() { - if (specialToken) delete specialToken; - this->kind = 0; - this->next = nullptr; - this->specialToken = nullptr; - } - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi diff --git a/src/main/resources/templates/cpp/Token.h.template b/src/main/resources/templates/cpp/Token.h.template deleted file mode 100644 index c1fa5e385..000000000 --- a/src/main/resources/templates/cpp/Token.h.template +++ /dev/null @@ -1,124 +0,0 @@ -\#ifndef JAVACC_TOKEN_H -\#define JAVACC_TOKEN_H - -\#include "JavaCC.h" - -#if TOKEN_INCLUDES -\#include "${TOKEN_INCLUDES}" -#fi - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi - -/** - * Describes the input token stream. - */ - -class Token -#if TOKEN_EXTENDS - : public ${TOKEN_EXTENDS} -#fi -{ - public: - - /** - * 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. - */ - int kind; - - /** The line number of the first character of this Token. */ - int beginLine; - /** The column number of the first character of this Token. */ - int beginColumn; - /** The line number of the last character of this Token. */ - int endLine; - /** The column number of the last character of this Token. */ - int endColumn; - - /** - * The string image of the token. - */ - JJString 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. - */ - 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 specialToke_ 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. - */ - Token *specialToken; - - /** - * 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. - */ - void * getValue(); - - /** - * No-argument constructor - */ - Token(); - - /** - * Constructs a new token for the specified Image. - */ - Token(int kind); - - /** - * Constructs a new token for the specified Image and Kind. - */ - Token(int kind, const JJString& image); - - virtual ~Token(); - - /** - * Returns the image. - */ - const JJString& toString(); - - - /** - * Returns a new Token void *, 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. - */ - static Token *newToken(int ofKind, const JJString& image); - - static Token *newToken(int ofKind); -}; - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi - -\#endif diff --git a/src/main/resources/templates/cpp/TokenManager.h.template b/src/main/resources/templates/cpp/TokenManager.h.template deleted file mode 100644 index 331a5b5ef..000000000 --- a/src/main/resources/templates/cpp/TokenManager.h.template +++ /dev/null @@ -1,35 +0,0 @@ -\#ifndef JAVACC_TOKENMANAGER_H -\#define JAVACC_TOKENMANAGER_H - -\#include -\#include "JavaCC.h" -\#include "Token.h" - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi -/** - * An implementation for this interface is generated by - * JavaCCParser. The user is free to use any implementation - * of their choice. - */ - -class TokenManager { -public: - /** This gets the next token from the input stream. - * A token of kind 0 () should be returned on EOF. - */ - virtual ~TokenManager() { } - virtual Token *getNextToken() = 0; - virtual void setParser(void* parser) {}; - virtual void lexicalError() { - std::cerr << "Lexical error encountered." << std::endl; - } - -}; - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi - -\#endif diff --git a/src/main/resources/templates/cpp/TokenManagerBoilerPlateMethods.template b/src/main/resources/templates/cpp/TokenManagerBoilerPlateMethods.template deleted file mode 100644 index 95a0edf64..000000000 --- a/src/main/resources/templates/cpp/TokenManagerBoilerPlateMethods.template +++ /dev/null @@ -1,59 +0,0 @@ - /** Reinitialise parser. */ - void ${tokMgrClassName}::ReInit(JAVACC_CHARSTREAM *stream, int lexState) { - clear(); - jjmatchedPos = jjnewStateCnt = 0; - curLexState = lexState; - input_stream = stream; - ReInitRounds(); - debugStream = stdout; // init - SwitchTo(lexState); - errorHandler = new TokenManagerErrorHandler(); - } - - void ${tokMgrClassName}::ReInitRounds() { - int i; - jjround = 0x80000001; - for (i = ${stateSetSize}; i-- > 0;) - jjrounds[i] = 0x80000000; - } - - /** Switch to specified lex state. */ - void ${tokMgrClassName}::SwitchTo(int lexState) { - if (lexState >= ${lexStateNameLength} || lexState < 0) { - JJString message; -\#ifdef WIDE_CHAR - message += L"Error: Ignoring invalid lexical state : "; - message += lexState; message += L". State unchanged."; -\#else - message += "Error: Ignoring invalid lexical state : "; - message += lexState; message += ". State unchanged."; -\#endif - throw new TokenMgrError(message, INVALID_LEXICAL_STATE); - } else - curLexState = lexState; - } - - /** Constructor. */ - ${tokMgrClassName}::${tokMgrClassName} (JAVACC_CHARSTREAM *stream, int lexState) -#if TOKEN_MANAGER_SUPER_CLASS - : ${TOKEN_MANAGER_SUPER_CLASS}() -#fi - { - input_stream = nullptr; - ReInit(stream, lexState); - } - - // Destructor - ${tokMgrClassName}::~${tokMgrClassName} () { - clear(); - } - - // clear - void ${tokMgrClassName}::clear() { - //Since input_stream was generated outside of TokenManager - //TokenManager should not take care of deleting it - //if (input_stream) delete input_stream; - if (errorHandler) delete errorHandler, errorHandler = nullptr; - } - - diff --git a/src/main/resources/templates/cpp/TokenMgrError.cc.template b/src/main/resources/templates/cpp/TokenMgrError.cc.template deleted file mode 100644 index 754b6aad6..000000000 --- a/src/main/resources/templates/cpp/TokenMgrError.cc.template +++ /dev/null @@ -1,117 +0,0 @@ -\#include "TokenMgrError.h" - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi - - /** - * 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 - * curJJChar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - JJString TokenMgrError::LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, const JJString& errorAfter, JJChar curChar) { -\#if 0 - JJString s; - stringstream ss; - ss << "Lexical error at line " << errorLine << " column " << errorColumn - << ". Encountered: " << curChar << "(" << (int)curChar - << ") after : \"" << errorAfter.c_str() << "\""; - return (JJString)ss.rdbuf()->str(); -\#endif - return EMPTY; - } - - /** - * 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. - */ - JJString TokenMgrError::getMessage() { - return message; - } - - /* - * Constructors of various flavors follow. - */ - - /** No arg constructor. */ - TokenMgrError::TokenMgrError() { - } - - /** Constructor with message and reason. */ - TokenMgrError::TokenMgrError(const JJString& message, int reason) { - errorCode = reason; - } - - /** Full Constructor. */ - TokenMgrError::TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, const JJString& errorAfter, JJChar curChar, int reason) { - message = LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar); - errorCode = reason; - } - -// i < 16 - guaranteed -char hexChar(int i) { - if (i < 10) { - return i - '0'; - } - return 'a' + (i - 10); -} - -/** - * Replaces unprintable characters by their escaped (or unicode escaped) - * equivalents in the given string - */ -JJSimpleString addUnicodeEscapes(const JJString& str) { - JJSimpleString retval; - for (size_t i = 0; i < str.size(); i++) { - JJChar ch = str[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; - default: - if (ch < 0xff) { - retval += ch; - continue; - } - retval.append("\\u"); - retval += (hexChar(ch >> 12)); - retval += (hexChar((ch & 0x0f00) >> 8)); - retval += (hexChar((ch & 0x00f0) >> 4)); - retval += (hexChar(ch & 0x000f)); - continue; - } - } - return retval; -} - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi diff --git a/src/main/resources/templates/cpp/TokenMgrError.h.template b/src/main/resources/templates/cpp/TokenMgrError.h.template deleted file mode 100644 index 37116ecae..000000000 --- a/src/main/resources/templates/cpp/TokenMgrError.h.template +++ /dev/null @@ -1,92 +0,0 @@ -\#ifndef JAVACC_TOKENMGRERROR_H -\#define JAVACC_TOKENMGRERROR_H - -\#include "JavaCC.h" - - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi - -enum LexerErrors { - /** - * Lexical error occurred. - */ - LEXICAL_ERROR = 0, - - /** - * An attempt was made to create a second instance of a token manager. - */ - STATIC_LEXER_ERROR = 1, - - /** - * Tried to change to an invalid lexical state. - */ - INVALID_LEXICAL_STATE = 2, - - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - LOOP_DETECTED = 3, -}; - -class TokenMgrError { -public: - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; - - /** - * 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. - */ - JJString LexicalError(bool EOFSeen, int lexState, int errorLine, int errorColumn, const JJString& errorAfter, JJChar curChar); - -private: - JJString message; - - /** - * 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. - */ -public: - JJString getMessage() ; - - /* - * Constructors of various flavors follow. - */ - - /** No arg constructor. */ - TokenMgrError() ; - - /** Constructor with message and reason. */ - TokenMgrError(const JJString& message, int reason) ; - - /** Full Constructor. */ - TokenMgrError(bool EOFSeen, int lexState, int errorLine, int errorColumn, const JJString& errorAfter, JJChar curChar, int reason) ; -}; - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi - -\#endif diff --git a/src/main/resources/templates/cpp/TreeIncludeHeader.template b/src/main/resources/templates/cpp/TreeIncludeHeader.template deleted file mode 100644 index 727d3306a..000000000 --- a/src/main/resources/templates/cpp/TreeIncludeHeader.template +++ /dev/null @@ -1,11 +0,0 @@ -\#include -\#include "JavaCC.h" -\#include "Token.h" -\#include "Node.h" -\#include "${PARSER_NAME}TreeConstants.h" -\#include "SimpleNode.h" - -#if NODE_INCLUDES -\#include "${NODE_INCLUDES}" -#fi - diff --git a/src/main/resources/templates/gwt/ParseException.template b/src/main/resources/templates/gwt/ParseException.template index e01fe11a0..3db9c7b3e 100644 --- a/src/main/resources/templates/gwt/ParseException.template +++ b/src/main/resources/templates/gwt/ParseException.template @@ -107,34 +107,34 @@ public class ParseException extends Exception { for (String option : sortedOptions) expected.append(INDENT).append(option).append(EOL); - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.append ("Encountered unexpected token:"); Token tok = currentToken.next; for (int i = 0; i < maxSize; i++) { String tokenText = tok.image; - String escapedTokenText = add_escapes(tokenText); + String escapedTokenText = add_escapes(tokenText); if (i != 0) - sb.append (' '); + sb.append (' '); if (tok.kind == 0) { - sb.append(tokenImage[0]); + sb.append(tokenImage[0]); break; } sb.append(" \""); - sb.append(escapedTokenText); + sb.append(escapedTokenText); sb.append("\""); sb.append(" " + tokenImage[tok.kind]); tok = tok.next; } #if KEEP_LINE_COLUMN - sb.append (EOL) - .append (INDENT) - .append ("at line ") - .append (currentToken.next.beginLine) - .append (", column ") - .append (currentToken.next.beginColumn); + sb.append (EOL) + .append (INDENT) + .append ("at line ") + .append (currentToken.next.beginLine) + .append (", column ") + .append (currentToken.next.beginColumn); #fi - sb.append(".").append(EOL); + sb.append(".").append(EOL); if (expectedTokenSequences.length == 0) { // Nothing to add here @@ -148,7 +148,7 @@ public class ParseException extends Exception { } // 2013/07/30 --> Seems to be inaccurate as represents the readahead state, not the lexical state BEFORE the unknown token // if (lexicalStateName != null) { -// sb.append(EOL).append("** Lexical State : ").append(lexicalStateName).append(EOL).append(EOL); +// sb.append(EOL).append("** Lexical State : ").append(lexicalStateName).append(EOL).append(EOL); // } return sb.toString(); diff --git a/src/main/resources/templates/jjtree/cpp/SimpleNode.cc.template b/src/main/resources/templates/jjtree/cpp/SimpleNode.cc.template index 597bd9bdf..9d6ab509b 100644 --- a/src/main/resources/templates/jjtree/cpp/SimpleNode.cc.template +++ b/src/main/resources/templates/jjtree/cpp/SimpleNode.cc.template @@ -87,7 +87,7 @@ void SimpleNode::jjtChildrenAccept(${PARSER_NAME}Visitor *visitor, ${VISITOR_DAT void SimpleNode::jjtChildAccept(int childNo, ${PARSER_NAME}Visitor *visitor, ${VISITOR_DATA_TYPE:-void *} data) const { if (0 <= childNo && childNo < children.size()) children[childNo]->jjtAccept(visitor, data); -} +} #fi /* You can override these two methods in subclasses of SimpleNode to diff --git a/src/main/resources/templates/stream/cpp/CharStream.cc.template b/src/main/resources/templates/stream/cpp/CharStream.cc.template deleted file mode 100644 index a4d475cf7..000000000 --- a/src/main/resources/templates/stream/cpp/CharStream.cc.template +++ /dev/null @@ -1,211 +0,0 @@ -\#include "CharStream.h" - -namespace { -template -void ArrayCopy(T* src, int src_offset, T* dest, int dest_offset, int len) { - for (int i = 0; i < len; i++) { - dest[dest_offset + i] = src[src_offset + i]; - } -} - -class StringReaderStream : public ReaderStream { - public: - StringReaderStream(const JJString& str) : str_(str), cur_(0), max_(str.size()) {} - virtual size_t read(JJChar *bufptr, int offset, size_t len) { - size_t count = str_.copy(bufptr + offset, len > max_ ? max_ : len, cur_); - cur_ += count; - max_ -= count; - return count; - } - virtual ~StringReaderStream() {} - virtual bool endOfInput() { - return max_ == 0; - } - - private: - const JJString str_; - size_t cur_; - size_t max_; -}; -} - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi -void CharStream::ReInit(const JJString& str, int startline, - int startcolumn, int buffersize) { - StringReaderStream *stream = new StringReaderStream(str); - ReInit(stream, startline, startcolumn, buffersize); - deleteStream = true; -} - -void CharStream::ReInit(ReaderStream *input_stream, int startline, - int startcolumn, int buffersize) { - if (deleteStream) { - delete inputStream; - } - - if (buffer) { - DeleteBuffers(); - } - - available = bufsize = buffersize; - buffer = new JJChar[buffersize]; - bufline = new int[buffersize]; - bufcolumn = new int[buffersize]; - - column = startcolumn - 1; - inputStream = input_stream; - line = startline; - prevCharIsLF = prevCharIsCR = false; - tokenBegin = inBuf = maxNextCharInd = 0; - bufpos = -1; - deleteStream = false; -} - -void CharStream::DeleteBuffers() { - delete[] buffer; - delete[] bufline; - delete[] bufcolumn; -} - -void CharStream::adjustBeginLineColumn(int newLine, int newCol) { - int start = tokenBegin; - int len; - - if (bufpos >= tokenBegin) { - len = bufpos - tokenBegin + inBuf + 1; - } else { - len = bufsize - tokenBegin + bufpos + 1 + inBuf; - } - - int i = 0, j = 0, k = 0; - int nextColDiff = 0, columnDiff = 0; - - while (i < len && bufline[j = start % bufsize] == - bufline[k = (start + 1) % bufsize]) { - bufline[j] = newLine; - nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; - bufcolumn[j] = newCol + columnDiff; - columnDiff = nextColDiff; - i++; - start++; - } - - if (i < len) { - bufline[j] = newLine++; - bufcolumn[j] = newCol + columnDiff; - - while (i++ < len) { - if (bufline[j = start % bufsize] != bufline[(start + 1) % bufsize]) - bufline[j] = newLine++; - else - bufline[j] = newLine; - start++; - } - } - - line = bufline[j]; - column = bufcolumn[j]; -} - -void CharStream::ExpandBuff(bool wrapAround) { - JJChar *newbuffer = new JJChar[bufsize + 2048]; - int *newbufline = new int[bufsize + 2048]; - int *newbufcolumn = new int[bufsize + 2048]; - - if (wrapAround) { - ArrayCopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - ArrayCopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); - ArrayCopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - ArrayCopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); - ArrayCopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - ArrayCopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); - bufpos += (bufsize - tokenBegin); - } else { - ArrayCopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - ArrayCopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - ArrayCopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - bufpos -= tokenBegin; - } - - maxNextCharInd = bufpos; - DeleteBuffers(); - buffer = newbuffer; - bufline = newbufline; - bufcolumn = newbufcolumn; - bufsize += 2048; - available = bufsize; - tokenBegin = 0; -} - -void CharStream::FillBuff() { - if (maxNextCharInd == available) { - if (available == bufsize) { - if (tokenBegin > 2048) { - bufpos = maxNextCharInd = 0; - available = tokenBegin; - } else if (tokenBegin < 0) { - bufpos = maxNextCharInd = 0; - } else { - ExpandBuff(false); - } - } else if (available > tokenBegin) { - available = bufsize; - } else if ((tokenBegin - available) < 2048) { - ExpandBuff(true); - } else { - available = tokenBegin; - } - } - - size_t i = inputStream->read(buffer, maxNextCharInd, available - maxNextCharInd); - if (i > 0) { - maxNextCharInd += i; - } else { - --bufpos; - backup(0); - if (tokenBegin == -1) { - tokenBegin = bufpos; - } - } -} - -void CharStream::UpdateLineColumn(JJChar c) { - column++; - if (prevCharIsLF) { - prevCharIsLF = false; - column = 1; - line++; - } else if (prevCharIsCR) { - prevCharIsCR = false; - if (c == '\n') { - prevCharIsLF = true; - } else { - column = 1; - line++; - } - } - - switch (c) { - case '\r' : - prevCharIsCR = true; - break; - case '\n' : - prevCharIsLF = true; - break; - case '\t' : - column--; - column += (tabSize - (column % tabSize)); - break; - default : - break; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; -} - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi diff --git a/src/main/resources/templates/stream/cpp/CharStream.h.template b/src/main/resources/templates/stream/cpp/CharStream.h.template deleted file mode 100644 index 75c8131f2..000000000 --- a/src/main/resources/templates/stream/cpp/CharStream.h.template +++ /dev/null @@ -1,276 +0,0 @@ -\#ifndef JAVACC_CHARSTREAM_H_ -\#define JAVACC_CHARSTREAM_H_ - -\#include "JavaCC.h" - -\#ifndef INITIAL_BUFFER_SIZE -\#define INITIAL_BUFFER_SIZE 4096 -\#endif - -#if NAMESPACE -namespace ${NAMESPACE_OPEN} -#fi - -/** - * This class 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 - * class 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. - */ - - -class CharStream { -public: - void setTabSize(int i) { tabSize = i; } - int getTabSize(int i) { return tabSize; } - -#if KEEP_LINE_COLUMN -private: - int getBufcolumn(int pos) { - if (trackLineColumn && pos>=0) { - return bufcolumn[pos]; - } else { - return -1; - } - } - int getBufline(int pos) { - if (trackLineColumn && pos>=0) { - return bufline[pos]; - } else { - return -1; - } - } - -public: - virtual int getEndColumn() { return getBufcolumn(bufpos); } - virtual int getEndLine() { return getBufline(bufpos); } - virtual int getBeginColumn() { return getBufcolumn(tokenBegin); } - virtual int getBeginLine() { return getBufline(tokenBegin); } -#else - virtual int getEndColumn() { return -1; } - virtual int getEndLine() { return -1; } - virtual int getBeginColumn() { return -1; } - virtual int getBeginLine() { return -1; } -#fi - - virtual bool getTrackLineColumn() { return trackLineColumn; } - virtual void setTrackLineColumn(bool val) { trackLineColumn = val; } - -/** - * 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. - */ - virtual inline void backup(int amount) { - inBuf += amount; - bufpos -= amount; - if (bufpos < 0) { - bufpos += bufsize; - } - } - -/** - * Returns 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. - */ - virtual inline JJChar BeginToken() { - tokenBegin = -1; - JJChar c = readChar(); - tokenBegin = bufpos; - return c; - } - - -/** - * Returns the next character from the selected input. The method - * of selecting the input is the responsibility of the class - * implementing this class. - */ - virtual inline JJChar readChar() { - if (inBuf > 0) { - --inBuf; - ++bufpos; - if (bufpos == bufsize) { - bufpos = 0; - } - return buffer[bufpos]; - } - - ++bufpos; - if (bufpos >= maxNextCharInd) { - FillBuff(); - } - - JJChar c = buffer[bufpos]; - -#if KEEP_LINE_COLUMN - if (trackLineColumn) { - UpdateLineColumn(c); - } -#fi - - return c; - } - - - virtual void ExpandBuff(bool wrapAround); - virtual void FillBuff(); - - /** - * Returns a string made up of characters from the marked token beginning - * to the current buffer position. Implementations can return - * anything that they want to. For example, for efficiency, one might decide - * to just return NULL, which is a valid implementation. - */ - virtual JJString GetImage() { - if (bufpos >= tokenBegin) - return JJString(buffer + tokenBegin, bufpos - tokenBegin + 1); - return JJString(buffer + tokenBegin, bufsize - tokenBegin).append(buffer, bufpos + 1); - } - - /** - * Returns 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 : - */ - virtual JJString GetSuffix(int len) { - if ((bufpos + 1) >= len) { - return JJString(buffer + bufpos - len + 1, len); - } - return JJString(buffer + bufsize - (len - bufpos - 1), len - bufpos - 1).append(buffer, bufpos + 1); - } - - /** - * 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. - */ - virtual void DeleteBuffers(); - - virtual ~CharStream() { - if (deleteStream) { - delete inputStream; - } - DeleteBuffers(); - } - - bool endOfInput() { - return inBuf == 0 && bufpos + 1 >= maxNextCharInd && inputStream->endOfInput(); - } - - CharStream(const JJChar *buf, int sz, int startline, - int startcolumn, int buffersize) : - bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0), - tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false), - available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true), - inputStream(nullptr), deleteStream(false) { - ReInit(JJString(buf, sz), startline, startcolumn, buffersize); - } - - CharStream(const JJChar *buf, int sz, int startline, int startcolumn) : - bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0), - tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false), - available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true), - inputStream(nullptr), deleteStream(false) { - ReInit(JJString(buf, sz), startline, startcolumn, INITIAL_BUFFER_SIZE); - } - - CharStream(const JJString& str, int startline, - int startcolumn, int buffersize) : - bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0), - tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false), - available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true), - inputStream(nullptr), deleteStream(false) { - ReInit(str, startline, startcolumn, buffersize); - } - - CharStream(const JJString& str, int startline, int startcolumn) : - bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0), - tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false), - available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true), - inputStream(nullptr), deleteStream(false) { - ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE); - } - - CharStream(ReaderStream *input_stream, int startline, - int startcolumn, int buffersize) : - bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0), - tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false), - available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true), - inputStream(nullptr), deleteStream(false) { - ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE); - } - - CharStream(ReaderStream *input_stream, int startline, int startcolumn) : - bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0), - tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false), - available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true), - inputStream(nullptr), deleteStream(false) { - ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE); - } - - CharStream(ReaderStream *input_stream) : - bufline(nullptr), bufcolumn(nullptr), buffer(nullptr), bufpos(0), bufsize(0), - tokenBegin(0), column(0), line(0), prevCharIsCR(false), prevCharIsLF(false), - available(0), maxNextCharInd(0), inBuf(0), tabSize(1), trackLineColumn(true), - inputStream(nullptr), deleteStream(false) { - ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE); - } - - virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn, int buffersize); - - virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn) { - ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE); - } - - virtual void ReInit(ReaderStream *input_stream) { - ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE); - } - - virtual void ReInit(const JJString& str, int startline, - int startcolumn, int buffersize); - - virtual void ReInit(const JJString& str, int startline, - int startcolumn) { - ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE); - } - - virtual void adjustBeginLineColumn(int newLine, int newCol); - -protected: - virtual void UpdateLineColumn(JJChar c); - - int* bufline; - int* bufcolumn; - JJChar* buffer; - int bufpos; - int bufsize; - int tokenBegin; - int column; - int line; - bool prevCharIsCR; - bool prevCharIsLF; - int available; - int maxNextCharInd; - int inBuf; - int tabSize; - bool trackLineColumn; - ReaderStream* inputStream; - bool deleteStream; -}; - -#if NAMESPACE -${NAMESPACE_CLOSE} -#fi - -\#endif diff --git a/src/main/resources/templates/stream/java/modern/StreamProvider.template b/src/main/resources/templates/stream/java/modern/StreamProvider.template index 2e4ec7207..258d52fa1 100644 --- a/src/main/resources/templates/stream/java/modern/StreamProvider.template +++ b/src/main/resources/templates/stream/java/modern/StreamProvider.template @@ -10,8 +10,8 @@ import java.io.Reader; */ public class StreamProvider implements Provider { - private Reader m_aReader; - + private Reader m_aReader; + #if AT_LEAST_JDK6 @Deprecated #fi @@ -39,17 +39,17 @@ public class StreamProvider implements Provider as in C# 0 represents end of file, and in Java, -1 represents end of file See : http://msdn.microsoft.com/en-us/library/9kstw824(v=vs.110).aspx ** Technically, this is not required for java but the overhead is extremely low compared to the code generation benefits. - */ + */ if (result == 0) if (nOfs < aDest.length && nLen > 0) result = -1; - + return result; - } + } - public void close () throws IOException - { - if (m_aReader != null) + public void close () throws IOException + { + if (m_aReader != null) m_aReader.close(); - } + } } diff --git a/src/test/java/com/helger/pgcc/parser/OptionsTest.java b/src/test/java/com/helger/pgcc/parser/OptionsTest.java index a6bbe5a20..303a1aa49 100644 --- a/src/test/java/com/helger/pgcc/parser/OptionsTest.java +++ b/src/test/java/com/helger/pgcc/parser/OptionsTest.java @@ -63,7 +63,7 @@ public void beforeEach () @Test public void testDefaults () { - assertEquals (44, Options.s_optionValues.size ()); + assertEquals (35, Options.s_optionValues.size ()); assertTrue (Options.isBuildParser ()); assertTrue (Options.isBuildTokenManager ()); diff --git a/src/test/java/com/helger/pgcc/parser/test/NfaStateTest.java b/src/test/java/com/helger/pgcc/parser/test/NfaStateTest.java index 3d95a6ccf..ffec78505 100644 --- a/src/test/java/com/helger/pgcc/parser/test/NfaStateTest.java +++ b/src/test/java/com/helger/pgcc/parser/test/NfaStateTest.java @@ -696,22 +696,31 @@ public void testDumpStatesForKindInitialised () "protected static final class Kinds {\n" + " protected static final int[][] kindForState = {\n" + "{ \n" + - " 27, \n" + - " 27, \n" + - " 27, \n" + - " 27, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + + " 26, \n" + + " 26, \n" + + " 26, \n" + + " 26, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 99, \n" + + " 99, \n" + + " 99, \n" + + " 99, \n" + + " 99, \n" + + " 99, \n" + + " 99, \n" + + " 99, \n" + + " 99, \n" + " 100, \n" + " 100, \n" + " 100, \n" + @@ -721,72 +730,63 @@ public void testDumpStatesForKindInitialised () " 100, \n" + " 100, \n" + " 100, \n" + - " 101, \n" + - " 101, \n" + - " 101, \n" + - " 101, \n" + - " 101, \n" + - " 101, \n" + - " 101, \n" + - " 101, \n" + - " 101, \n" + - " 152, \n" + - " 152, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 89, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, \n" + - " 94, },\n" + + " 151, \n" + + " 151, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 88, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, \n" + + " 93, },\n" + "{}\n" + ",\n" + "{ \n" + - " 30, \n" + - " 30, \n" + - " 30, },\n" + + " 29, \n" + + " 29, \n" + + " 29, },\n" + "{}\n" + ",\n" + "{}\n" + diff --git a/www/doc/JavaCC.html b/www/doc/JavaCC.html index c33edac50..8408d0381 100644 --- a/www/doc/JavaCC.html +++ b/www/doc/JavaCC.html @@ -28,7 +28,6 @@

TOKENS

| <_PARSER_BEGIN: "PARSER_BEGIN"> | <_PARSER_END: "PARSER_END"> | <_JAVACODE: "JAVACODE"> -| <_CPPCODE: "CPPCODE"> | <_TOKEN: "TOKEN"> | <_SPECIAL_TOKEN: "SPECIAL_TOKEN"> | <_MORE: "MORE"> @@ -3619,27 +3618,6 @@

TOKENS

- - - -
-   
- - - - - -
-   
- - - - - -
-   
- - @@ -3711,55 +3689,45 @@

NON-TERMINALS

| -cppcode_production +regular_expr_production | -regular_expr_production +token_manager_decls | -token_manager_decls - - - -| -bnf_production +bnf_production javacode_production ::= -"JAVACODE" AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? Block - - -cppcode_production -::= -"CPPCODE" AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? Block +"JAVACODE" AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? Block -bnf_production +bnf_production ::= -AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? ":" Block "{" expansion_choices "}" +AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? ":" Block "{" expansion_choices "}" -AccessModifier +AccessModifier ::= ( "public" | "protected" | "private" )? -regular_expr_production +regular_expr_production ::= -( "<" "*" ">" | "<" <IDENTIFIER> ( "," <IDENTIFIER> )* ">" )? regexpr_kind ( "[" "IGNORE_CASE" "]" )? ":" "{" regexpr_spec ( "|" regexpr_spec )* "}" +( "<" "*" ">" | "<" <IDENTIFIER> ( "," <IDENTIFIER> )* ">" )? regexpr_kind ( "[" "IGNORE_CASE" "]" )? ":" "{" regexpr_spec ( "|" regexpr_spec )* "}" -token_manager_decls +token_manager_decls ::= -"TOKEN_MGR_DECLS" ":" ( ClassOrInterfaceBody )? +"TOKEN_MGR_DECLS" ":" ( ClassOrInterfaceBody )? -regexpr_kind +regexpr_kind ::= "TOKEN" @@ -3779,64 +3747,64 @@

NON-TERMINALS

"MORE" -regexpr_spec +regexpr_spec ::= -regular_expression ( Block )? ( ":" <IDENTIFIER> )? +regular_expression ( Block )? ( ":" <IDENTIFIER> )? -expansion_choices +expansion_choices ::= -expansion ( "|" expansion )* +expansion ( "|" expansion )* -expansion +expansion ::= -( "LOOKAHEAD" "(" local_lookahead ")" )? ( expansion_unit )+ +( "LOOKAHEAD" "(" local_lookahead ")" )? ( expansion_unit )+ -local_lookahead +local_lookahead ::= -( IntegerLiteral )? ( "," )? ( expansion_choices )? ( "," )? ( "{" ( Expression )? "}" )? +( IntegerLiteral )? ( "," )? ( expansion_choices )? ( "," )? ( "{" ( Expression )? "}" )? -expansion_unit +expansion_unit ::= -"LOOKAHEAD" "(" local_lookahead ")" +"LOOKAHEAD" "(" local_lookahead ")" | -Block +Block | -"[" expansion_choices "]" +"[" expansion_choices "]" | -"try" "{" expansion_choices "}" ( "catch" "(" ( "final" )? ( Name <IDENTIFIER> )? ")" Block )* ( "finally" Block )? +"try" "{" expansion_choices "}" ( "catch" "(" ( "final" )? ( Name <IDENTIFIER> )? ")" Block )* ( "finally" Block )? | -( PrimaryExpression "=" )? ( identifier ( TypeArguments )? Arguments | regular_expression ( "." <IDENTIFIER> )? ) +( PrimaryExpression "=" )? ( identifier ( TypeArguments )? Arguments | regular_expression ( "." <IDENTIFIER> )? ) | -"(" expansion_choices ")" ( "+" | "*" | "?" )? +"(" expansion_choices ")" ( "+" | "*" | "?" )? -regular_expression +regular_expression ::= StringLiteral | -<LANGLE: "<"> ( ( "#" )? identifier ":" )? complex_regular_expression_choices <RANGLE: ">"> +<LANGLE: "<"> ( ( "#" )? identifier ":" )? complex_regular_expression_choices <RANGLE: ">"> @@ -3849,17 +3817,17 @@

NON-TERMINALS

"<" "EOF" ">" -complex_regular_expression_choices +complex_regular_expression_choices ::= -complex_regular_expression ( "|" complex_regular_expression )* +complex_regular_expression ( "|" complex_regular_expression )* -complex_regular_expression +complex_regular_expression ::= -( complex_regular_expression_unit )+ +( complex_regular_expression_unit )+ -complex_regular_expression_unit +complex_regular_expression_unit ::= StringLiteral @@ -3871,20 +3839,20 @@

NON-TERMINALS

| -character_list +character_list | -"(" complex_regular_expression_choices ")" ( "+" | "*" | "?" | "{" IntegerLiteral ( "," ( IntegerLiteral )? )? "}" )? +"(" complex_regular_expression_choices ")" ( "+" | "*" | "?" | "{" IntegerLiteral ( "," ( IntegerLiteral )? )? "}" )? -character_list +character_list ::= -( "~" )? "[" ( character_descriptor ( "," character_descriptor )* )? "]" +( "~" )? "[" ( character_descriptor ( "," character_descriptor )* )? "]" -character_descriptor +character_descriptor ::= StringLiteral ( "-" StringLiteral )? @@ -3913,7 +3881,7 @@

NON-TERMINALS

-JavaIdentifier +JavaIdentifier ::= ( <IDENTIFIER> | "LOOKAHEAD" | "IGNORE_CASE" | "PARSER_BEGIN" | "PARSER_END" | "JAVACODE" | "TOKEN" | "SPECIAL_TOKEN" | "MORE" | "SKIP" | "TOKEN_MGR_DECLS" | "EOF" | "DCL_PARSER_BEGIN" | "DCL_PARSER_END" | "INC_PARSER_BEGIN" | "INC_PARSER_END" | "DEF_PARSER_BEGIN" | "DEF_PARSER_END" ) @@ -3929,17 +3897,17 @@

NON-TERMINALS

CompilationUnit ::= -( PackageDeclaration )? ( ImportDeclaration )* ( TypeDeclaration )* +( PackageDeclaration )? ( ImportDeclaration )* ( TypeDeclaration )* -PackageDeclaration +PackageDeclaration ::= -Modifiers "package" Name ";" +Modifiers "package" Name ";" -ImportDeclaration +ImportDeclaration ::= -"import" ( "static" )? Name ( "." "*" )? ";" +"import" ( "static" )? Name ( "." "*" )? ";" @@ -3953,9 +3921,9 @@

NON-TERMINALS

-Modifiers +Modifiers ::= -( ( "public" | "static" | "protected" | "private" | "final" | "abstract" | "synchronized" | "native" | "transient" | "volatile" | "strictfp" | Annotation ) )* +( ( "public" | "static" | "protected" | "private" | "final" | "abstract" | "synchronized" | "native" | "transient" | "volatile" | "strictfp" | Annotation ) )* @@ -3967,74 +3935,74 @@

NON-TERMINALS

-TypeDeclaration +TypeDeclaration ::= ";" | -Modifiers ( ClassOrInterfaceDeclaration | EnumDeclaration | AnnotationTypeDeclaration ) +Modifiers ( ClassOrInterfaceDeclaration | EnumDeclaration | AnnotationTypeDeclaration ) -ClassOrInterfaceDeclaration +ClassOrInterfaceDeclaration ::= -( "class" | "interface" ) <IDENTIFIER> ( TypeParameters )? ( ExtendsList )? ( ImplementsList )? ClassOrInterfaceBody +( "class" | "interface" ) <IDENTIFIER> ( TypeParameters )? ( ExtendsList )? ( ImplementsList )? ClassOrInterfaceBody -ExtendsList +ExtendsList ::= -"extends" ClassOrInterfaceType ( "," ClassOrInterfaceType )* +"extends" ClassOrInterfaceType ( "," ClassOrInterfaceType )* -ImplementsList +ImplementsList ::= -"implements" ClassOrInterfaceType ( "," ClassOrInterfaceType )* +"implements" ClassOrInterfaceType ( "," ClassOrInterfaceType )* -EnumDeclaration +EnumDeclaration ::= -"enum" <IDENTIFIER> ( ImplementsList )? EnumBody +"enum" <IDENTIFIER> ( ImplementsList )? EnumBody -EnumBody +EnumBody ::= -"{" ( EnumConstant ( "," EnumConstant )* )? ( "," )? ( ";" ( ClassOrInterfaceBodyDeclaration )* )? "}" +"{" ( EnumConstant ( "," EnumConstant )* )? ( "," )? ( ";" ( ClassOrInterfaceBodyDeclaration )* )? "}" -EnumConstant +EnumConstant ::= -Modifiers <IDENTIFIER> ( Arguments )? ( ClassOrInterfaceBody )? +Modifiers <IDENTIFIER> ( Arguments )? ( ClassOrInterfaceBody )? -TypeParameters +TypeParameters ::= -"<" ( TypeParameter ( "," TypeParameter )* )? ">" +"<" ( TypeParameter ( "," TypeParameter )* )? ">" -TypeParameter +TypeParameter ::= -<IDENTIFIER> ( TypeBound )? +<IDENTIFIER> ( TypeBound )? -TypeBound +TypeBound ::= -"extends" ClassOrInterfaceType ( "&" ClassOrInterfaceType )* +"extends" ClassOrInterfaceType ( "&" ClassOrInterfaceType )* -ClassOrInterfaceBody +ClassOrInterfaceBody ::= -"{" ( ClassOrInterfaceBodyDeclaration )* "}" +"{" ( ClassOrInterfaceBodyDeclaration )* "}" -ClassOrInterfaceBodyDeclaration +ClassOrInterfaceBodyDeclaration ::= -Initializer +Initializer | -Modifiers ( ClassOrInterfaceDeclaration | EnumDeclaration | ConstructorDeclaration | FieldDeclaration | MethodDeclaration ) +Modifiers ( ClassOrInterfaceDeclaration | EnumDeclaration | ConstructorDeclaration | FieldDeclaration | MethodDeclaration ) @@ -4042,74 +4010,74 @@

NON-TERMINALS

";" -FieldDeclaration +FieldDeclaration ::= -Type VariableDeclarator ( "," VariableDeclarator )* ";" +Type VariableDeclarator ( "," VariableDeclarator )* ";" -VariableDeclarator +VariableDeclarator ::= -VariableDeclaratorId ( "=" VariableInitializer )? +VariableDeclaratorId ( "=" VariableInitializer )? -VariableDeclaratorId +VariableDeclaratorId ::= <IDENTIFIER> ( "[" "]" )* -VariableInitializer +VariableInitializer ::= -ArrayInitializer +ArrayInitializer | -Expression +Expression -ArrayInitializer +ArrayInitializer ::= -"{" ( VariableInitializer ( "," VariableInitializer )* )? ( "," )? "}" +"{" ( VariableInitializer ( "," VariableInitializer )* )? ( "," )? "}" -MethodDeclaration +MethodDeclaration ::= -( TypeParameters )? ResultType MethodDeclarator ( "throws" NameList )? ( Block | ";" ) +( TypeParameters )? ResultType MethodDeclarator ( "throws" NameList )? ( Block | ";" ) -MethodDeclarator +MethodDeclarator ::= -<IDENTIFIER> FormalParameters ( "[" "]" )* +<IDENTIFIER> FormalParameters ( "[" "]" )* -FormalParameters +FormalParameters ::= -"(" ( FormalParameter ( "," FormalParameter )* )? ")" +"(" ( FormalParameter ( "," FormalParameter )* )? ")" -FormalParameter +FormalParameter ::= -Modifiers Type ( ( "&" | "*" ) | "..." )? VariableDeclaratorId +Modifiers Type ( ( "&" | "*" ) | "..." )? VariableDeclaratorId -ConstructorDeclaration +ConstructorDeclaration ::= -( TypeParameters )? <IDENTIFIER> FormalParameters ( "throws" NameList )? "{" ( ExplicitConstructorInvocation )? ( BlockStatement )* "}" +( TypeParameters )? <IDENTIFIER> FormalParameters ( "throws" NameList )? "{" ( ExplicitConstructorInvocation )? ( BlockStatement )* "}" -ExplicitConstructorInvocation +ExplicitConstructorInvocation ::= -"this" Arguments ";" +"this" Arguments ";" | -( PrimaryExpression "." )? "super" Arguments ";" +( PrimaryExpression "." )? "super" Arguments ";" -Initializer +Initializer ::= -( "static" )? Block +( "static" )? Block @@ -4121,72 +4089,72 @@

NON-TERMINALS

-Type +Type ::= -ReferenceType +ReferenceType | -PrimitiveType +PrimitiveType -ReferenceType +ReferenceType ::= -PrimitiveType ( "[" "]" )+ +PrimitiveType ( "[" "]" )+ | -( ( Template )? ClassOrInterfaceType ) ( "[" "]" )* +( ( Template )? ClassOrInterfaceType ) ( "[" "]" )* -Template +Template ::= -"template" "<" TemplateBase ( "," TemplateBase )* ">" +"template" "<" TemplateBase ( "," TemplateBase )* ">" -TemplateBase +TemplateBase ::= -TemplatePack ( "..." )? <IDENTIFIER> +TemplatePack ( "..." )? <IDENTIFIER> -TemplatePack +TemplatePack ::= ( "class" | "typename" ) -ClassOrInterfaceType +ClassOrInterfaceType ::= -<IDENTIFIER> ( TypeArguments )? ( ( "." | "::" ) <IDENTIFIER> ( TypeArguments )? )* +<IDENTIFIER> ( TypeArguments )? ( ( "." | "::" ) <IDENTIFIER> ( TypeArguments )? )* -TypeArguments +TypeArguments ::= -"<" ( TypeArgument ( "," TypeArgument ( "..." )? )* )? ">" +"<" ( TypeArgument ( "," TypeArgument ( "..." )? )* )? ">" -TypeArgument +TypeArgument ::= -ReferenceType +ReferenceType | -"?" ( WildcardBounds )? +"?" ( WildcardBounds )? -WildcardBounds +WildcardBounds ::= -"extends" ReferenceType +"extends" ReferenceType | -"super" ReferenceType +"super" ReferenceType -PrimitiveType +PrimitiveType ::= "boolean" @@ -4226,19 +4194,19 @@

NON-TERMINALS

"short" -ResultType +ResultType ::= -( "void" ( "*" )? | ( "const" )? Type ( "*" | "&" )? ) +( "void" ( "*" )? | ( "const" )? Type ( "*" | "&" )? ) -Name +Name ::= -JavaIdentifier ( "." JavaIdentifier )* +JavaIdentifier ( "." JavaIdentifier )* -NameList +NameList ::= -Name ( "," Name )* +Name ( "," Name )* @@ -4250,12 +4218,12 @@

NON-TERMINALS

-Expression +Expression ::= -ConditionalExpression ( AssignmentOperator Expression )? +ConditionalExpression ( AssignmentOperator Expression )? -AssignmentOperator +AssignmentOperator ::= "=" @@ -4315,109 +4283,109 @@

NON-TERMINALS

"|=" -ConditionalExpression +ConditionalExpression ::= -ConditionalOrExpression ( "?" Expression ":" Expression )? +ConditionalOrExpression ( "?" Expression ":" Expression )? -ConditionalOrExpression +ConditionalOrExpression ::= -ConditionalAndExpression ( "||" ConditionalAndExpression )* +ConditionalAndExpression ( "||" ConditionalAndExpression )* -ConditionalAndExpression +ConditionalAndExpression ::= -InclusiveOrExpression ( "&&" InclusiveOrExpression )* +InclusiveOrExpression ( "&&" InclusiveOrExpression )* -InclusiveOrExpression +InclusiveOrExpression ::= -ExclusiveOrExpression ( "|" ExclusiveOrExpression )* +ExclusiveOrExpression ( "|" ExclusiveOrExpression )* -ExclusiveOrExpression +ExclusiveOrExpression ::= -AndExpression ( "^" AndExpression )* +AndExpression ( "^" AndExpression )* -AndExpression +AndExpression ::= -EqualityExpression ( "&" EqualityExpression )* +EqualityExpression ( "&" EqualityExpression )* -EqualityExpression +EqualityExpression ::= -InstanceOfExpression ( ( "==" | "!=" ) InstanceOfExpression )* +InstanceOfExpression ( ( "==" | "!=" ) InstanceOfExpression )* -InstanceOfExpression +InstanceOfExpression ::= -RelationalExpression ( "instanceof" Type )? +RelationalExpression ( "instanceof" Type )? -RelationalExpression +RelationalExpression ::= -ShiftExpression ( ( "<" | ">" | "<=" | ">=" ) ShiftExpression )* +ShiftExpression ( ( "<" | ">" | "<=" | ">=" ) ShiftExpression )* -ShiftExpression +ShiftExpression ::= -AdditiveExpression ( ( "<<" | RSIGNEDSHIFT | RUNSIGNEDSHIFT ) AdditiveExpression )* +AdditiveExpression ( ( "<<" | RSIGNEDSHIFT | RUNSIGNEDSHIFT ) AdditiveExpression )* -AdditiveExpression +AdditiveExpression ::= -MultiplicativeExpression ( ( "+" | "-" ) MultiplicativeExpression )* +MultiplicativeExpression ( ( "+" | "-" ) MultiplicativeExpression )* -MultiplicativeExpression +MultiplicativeExpression ::= -UnaryExpression ( ( "*" | "/" | "%" ) UnaryExpression )* +UnaryExpression ( ( "*" | "/" | "%" ) UnaryExpression )* -UnaryExpression +UnaryExpression ::= -( "+" | "-" ) UnaryExpression +( "+" | "-" ) UnaryExpression | -PreIncrementExpression +PreIncrementExpression | -PreDecrementExpression +PreDecrementExpression | -UnaryExpressionNotPlusMinus +UnaryExpressionNotPlusMinus -PreIncrementExpression +PreIncrementExpression ::= -"++" PrimaryExpression +"++" PrimaryExpression -PreDecrementExpression +PreDecrementExpression ::= -"--" PrimaryExpression +"--" PrimaryExpression -UnaryExpressionNotPlusMinus +UnaryExpressionNotPlusMinus ::= -( "~" | "!" ) UnaryExpression +( "~" | "!" ) UnaryExpression | -CastExpression +CastExpression | -PostfixExpression +PostfixExpression @@ -4430,49 +4398,49 @@

NON-TERMINALS

-CastLookahead +CastLookahead ::= -"(" PrimitiveType +"(" PrimitiveType | -"(" Type "[" "]" +"(" Type "[" "]" | -"(" Type ")" ( "~" | "!" | "(" | <IDENTIFIER> | "this" | "super" | "new" | Literal ) +"(" Type ")" ( "~" | "!" | "(" | <IDENTIFIER> | "this" | "super" | "new" | Literal ) -PostfixExpression +PostfixExpression ::= -PrimaryExpression ( "++" | "--" )? +PrimaryExpression ( "++" | "--" )? -CastExpression +CastExpression ::= -"(" Type ")" UnaryExpression +"(" Type ")" UnaryExpression | -"(" Type ")" UnaryExpressionNotPlusMinus +"(" Type ")" UnaryExpressionNotPlusMinus -PrimaryExpression +PrimaryExpression ::= -PrimaryPrefix ( PrimarySuffix )* +PrimaryPrefix ( PrimarySuffix )* -MemberSelector +MemberSelector ::= -"." TypeArguments <IDENTIFIER> +"." TypeArguments <IDENTIFIER> -PrimaryPrefix +PrimaryPrefix ::= -Literal +Literal @@ -4487,42 +4455,42 @@

NON-TERMINALS

| -"(" Expression ")" +"(" Expression ")" | -AllocationExpression +AllocationExpression | -ResultType "." "class" +ResultType "." "class" | -Name +Name -PrimarySuffix +PrimarySuffix ::= "." "this" | -"." AllocationExpression +"." AllocationExpression | -MemberSelector +MemberSelector | -"[" Expression "]" +"[" Expression "]" @@ -4532,10 +4500,10 @@

NON-TERMINALS

| -Arguments +Arguments -Literal +Literal ::= <INTEGER_LITERAL> @@ -4562,7 +4530,7 @@

NON-TERMINALS

| -NullLiteral +NullLiteral IntegerLiteral @@ -4585,29 +4553,29 @@

NON-TERMINALS

<STRING_LITERAL> -NullLiteral +NullLiteral ::= "null" -Arguments +Arguments ::= -"(" ( ArgumentList )? ")" +"(" ( ArgumentList )? ")" -ArgumentList +ArgumentList ::= -Expression ( "," Expression )* +Expression ( "," Expression )* -AllocationExpression +AllocationExpression ::= -"new" PrimitiveType ArrayDimsAndInits +"new" PrimitiveType ArrayDimsAndInits | -"new" ClassOrInterfaceType ( TypeArguments )? ( ArrayDimsAndInits | Arguments ( ClassOrInterfaceBody )? ) +"new" ClassOrInterfaceType ( TypeArguments )? ( ArrayDimsAndInits | Arguments ( ClassOrInterfaceBody )? ) @@ -4620,14 +4588,14 @@

NON-TERMINALS

-ArrayDimsAndInits +ArrayDimsAndInits ::= -( "[" Expression "]" )+ ( "[" "]" )* +( "[" Expression "]" )+ ( "[" "]" )* | -( "[" "]" )+ ArrayInitializer +( "[" "]" )+ ArrayInitializer @@ -4639,149 +4607,149 @@

NON-TERMINALS

-Statement +Statement ::= -LabeledStatement +LabeledStatement | -AssertStatement +AssertStatement | -Block +Block | -EmptyStatement +EmptyStatement | -StatementExpression ";" +StatementExpression ";" | -SwitchStatement +SwitchStatement | -IfStatement +IfStatement | -WhileStatement +WhileStatement | -DoStatement +DoStatement | -ForStatement +ForStatement | -BreakStatement +BreakStatement | -ContinueStatement +ContinueStatement | -ReturnStatement +ReturnStatement | -ThrowStatement +ThrowStatement | -SynchronizedStatement +SynchronizedStatement | -TryStatement +TryStatement -AssertStatement +AssertStatement ::= -"assert" Expression ( ":" Expression )? ";" +"assert" Expression ( ":" Expression )? ";" -LabeledStatement +LabeledStatement ::= -<IDENTIFIER> ":" Statement +<IDENTIFIER> ":" Statement -Block +Block ::= -"{" ( BlockStatement )* "}" +"{" ( BlockStatement )* "}" -BlockStatement +BlockStatement ::= -LocalVariableDeclaration ";" +LocalVariableDeclaration ";" | -Statement +Statement | -ClassOrInterfaceDeclaration +ClassOrInterfaceDeclaration -LocalVariableDeclaration +LocalVariableDeclaration ::= -Modifiers Type VariableDeclarator ( "," VariableDeclarator )* +Modifiers Type VariableDeclarator ( "," VariableDeclarator )* -EmptyStatement +EmptyStatement ::= ";" -StatementExpression +StatementExpression ::= -PreIncrementExpression +PreIncrementExpression | -PreDecrementExpression +PreDecrementExpression | -PrimaryExpression ( "++" | "--" | AssignmentOperator Expression )? +PrimaryExpression ( "++" | "--" | AssignmentOperator Expression )? -SwitchStatement +SwitchStatement ::= -"switch" "(" Expression ")" "{" ( SwitchLabel ( BlockStatement )* )* "}" +"switch" "(" Expression ")" "{" ( SwitchLabel ( BlockStatement )* )* "}" -SwitchLabel +SwitchLabel ::= -"case" Expression ":" +"case" Expression ":" @@ -4789,84 +4757,84 @@

NON-TERMINALS

"default" ":" -IfStatement +IfStatement ::= -"if" "(" Expression ")" Statement ( "else" Statement )? +"if" "(" Expression ")" Statement ( "else" Statement )? -WhileStatement +WhileStatement ::= -"while" "(" Expression ")" Statement +"while" "(" Expression ")" Statement -DoStatement +DoStatement ::= -"do" Statement "while" "(" Expression ")" ";" +"do" Statement "while" "(" Expression ")" ";" -ForStatement +ForStatement ::= -"for" "(" ( Modifiers Type <IDENTIFIER> ":" Expression | ( ForInit )? ";" ( Expression )? ";" ( ForUpdate )? ) ")" Statement +"for" "(" ( Modifiers Type <IDENTIFIER> ":" Expression | ( ForInit )? ";" ( Expression )? ";" ( ForUpdate )? ) ")" Statement -ForInit +ForInit ::= -LocalVariableDeclaration +LocalVariableDeclaration | -StatementExpressionList +StatementExpressionList -StatementExpressionList +StatementExpressionList ::= -StatementExpression ( "," StatementExpression )* +StatementExpression ( "," StatementExpression )* -ForUpdate +ForUpdate ::= -StatementExpressionList +StatementExpressionList -BreakStatement +BreakStatement ::= "break" ( <IDENTIFIER> )? ";" -ContinueStatement +ContinueStatement ::= "continue" ( <IDENTIFIER> )? ";" -ReturnStatement +ReturnStatement ::= -"return" ( Expression )? ";" +"return" ( Expression )? ";" -ThrowStatement +ThrowStatement ::= -"throw" Expression ";" +"throw" Expression ";" -SynchronizedStatement +SynchronizedStatement ::= -"synchronized" "(" Expression ")" Block +"synchronized" "(" Expression ")" Block -ResourceDeclaration +ResourceDeclaration ::= -Modifiers Type VariableDeclaratorId "=" Expression +Modifiers Type VariableDeclaratorId "=" Expression -CatchParameter +CatchParameter ::= -Modifiers Type ( ( "&" | "*" ) | "..." )? ( "|" Type )* VariableDeclaratorId +Modifiers Type ( ( "&" | "*" ) | "..." )? ( "|" Type )* VariableDeclaratorId -TryStatement +TryStatement ::= -"try" ( "(" ResourceDeclaration ( ";" ResourceDeclaration )* ( ";" )? ")" )? Block ( "catch" "(" CatchParameter ")" Block )* ( "finally" Block )? +"try" ( "(" ResourceDeclaration ( ";" ResourceDeclaration )* ( ";" )? ")" )? Block ( "catch" "(" CatchParameter ")" Block )* ( "finally" Block )? @@ -4878,12 +4846,12 @@

NON-TERMINALS

-RUNSIGNEDSHIFT +RUNSIGNEDSHIFT ::= ( ">" ">" ">" ) -RSIGNEDSHIFT +RSIGNEDSHIFT ::= ( ">" ">" ) @@ -4895,64 +4863,64 @@

NON-TERMINALS

-Annotation +Annotation ::= -NormalAnnotation +NormalAnnotation | -SingleMemberAnnotation +SingleMemberAnnotation | -MarkerAnnotation +MarkerAnnotation -NormalAnnotation +NormalAnnotation ::= -"@" Name "(" ( MemberValuePairs )? ")" +"@" Name "(" ( MemberValuePairs )? ")" -MarkerAnnotation +MarkerAnnotation ::= -"@" Name +"@" Name -SingleMemberAnnotation +SingleMemberAnnotation ::= -"@" Name "(" MemberValue ")" +"@" Name "(" MemberValue ")" -MemberValuePairs +MemberValuePairs ::= -MemberValuePair ( "," MemberValuePair )* +MemberValuePair ( "," MemberValuePair )* -MemberValuePair +MemberValuePair ::= -<IDENTIFIER> "=" MemberValue +<IDENTIFIER> "=" MemberValue -MemberValue +MemberValue ::= -Annotation +Annotation | -MemberValueArrayInitializer +MemberValueArrayInitializer | -ConditionalExpression +ConditionalExpression -MemberValueArrayInitializer +MemberValueArrayInitializer ::= -"{" MemberValue ( "," MemberValue )* ( "," )? "}" +"{" MemberValue ( "," MemberValue )* ( "," )? "}" @@ -4962,19 +4930,19 @@

NON-TERMINALS

-AnnotationTypeDeclaration +AnnotationTypeDeclaration ::= -"@" "interface" <IDENTIFIER> AnnotationTypeBody +"@" "interface" <IDENTIFIER> AnnotationTypeBody -AnnotationTypeBody +AnnotationTypeBody ::= -"{" ( AnnotationTypeMemberDeclaration )* "}" +"{" ( AnnotationTypeMemberDeclaration )* "}" -AnnotationTypeMemberDeclaration +AnnotationTypeMemberDeclaration ::= -Modifiers ( Type <IDENTIFIER> "(" ")" ( DefaultValue )? ";" | ClassOrInterfaceDeclaration | EnumDeclaration | AnnotationTypeDeclaration | FieldDeclaration ) +Modifiers ( Type <IDENTIFIER> "(" ")" ( DefaultValue )? ";" | ClassOrInterfaceDeclaration | EnumDeclaration | AnnotationTypeDeclaration | FieldDeclaration ) @@ -4982,9 +4950,9 @@

NON-TERMINALS

( ";" ) -DefaultValue +DefaultValue ::= -"default" MemberValue +"default" MemberValue diff --git a/www/doc/JavaCC.txt b/www/doc/JavaCC.txt index e3d34dad1..e92009e4d 100644 --- a/www/doc/JavaCC.txt +++ b/www/doc/JavaCC.txt @@ -11,7 +11,6 @@ TOKENS | <_PARSER_BEGIN: "PARSER_BEGIN"> | <_PARSER_END: "PARSER_END"> | <_JAVACODE: "JAVACODE"> -| <_CPPCODE: "CPPCODE"> | <_TOKEN: "TOKEN"> | <_SPECIAL_TOKEN: "SPECIAL_TOKEN"> | <_MORE: "MORE"> @@ -215,12 +214,10 @@ NON-TERMINALS option_binding := ( | "LOOKAHEAD" | "IGNORE_CASE" | "static" | "PARSER_BEGIN" ) "=" ( IntegerLiteral | BooleanLiteral | StringLiteral | StringList ) ";" StringList := "(" StringLiteral ( "," StringLiteral )* ")" production := javacode_production - | cppcode_production | regular_expr_production | token_manager_decls | bnf_production javacode_production := "JAVACODE" AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? Block - cppcode_production := "CPPCODE" AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? Block bnf_production := AccessModifier ResultType identifier FormalParameters ( "throws" Name ( "," Name )* )? ":" Block "{" expansion_choices "}" AccessModifier := ( "public" | "protected" | "private" )? regular_expr_production := ( "<" "*" ">" | "<" ( "," )* ">" )? regexpr_kind ( "[" "IGNORE_CASE" "]" )? ":" "{" regexpr_spec ( "|" regexpr_spec )* "}"