JavaCCChunks.jrag 8.38 KB
Newer Older
1 2
/* -*-Java-*- */

3
/* 
4
 * Copyright (C) 2006,2010  Anders Nilsson <anders.nilsson@control.lth.se>
5 6
 *
 * This file is part of OntologyCompiler.
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * OntologyCompiler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * OntologyCompiler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 
 * You should have received a copy of the GNU General Public License
 * along with OntologyCompiler.  If not, see <http://www.gnu.org/licenses/>.
20 21
 */

22 23 24 25 26 27 28 29 30 31 32 33
aspect JavaCCChunks {
	void Start.genJavaCCHeader(PrintStream pStream) {
		pStream.println("options {");
		pStream.println("    MULTI                       = true;");
		pStream.println("    VISITOR                     = true;");
		pStream.println("    NODE_DEFAULT_VOID           = true;");
		pStream.println("    NODE_SCOPE_HOOK             = false;");
		pStream.println("    NODE_PREFIX                 = \"\";");
		pStream.println("    JAVA_UNICODE_ESCAPE         = true;");
		pStream.println("    STATIC                      = false;");
		pStream.println("} ");
		pStream.println();
34
		pStream.println("PARSER_BEGIN("+grammarName()+"Parser)");
35
		pStream.println("    package AST;");
36
		pStream.println("    public class "+grammarName()+"Parser {");
37
		pStream.println("}");
38
		pStream.println("PARSER_END("+grammarName()+"Parser)");
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
		pStream.println();
		pStream.println("//----------------------------------------------//");
		pStream.println("//                LEXICAL TOKENS                //");
		pStream.println("//----------------------------------------------//");
		pStream.println("<DEFAULT, BOUNDS> SKIP : /* WHITE SPACE */");
		pStream.println("{");
		pStream.println("    \" \"");
		pStream.println("    |");
		pStream.println("    \"\\t\"");
		pStream.println("    |");
		pStream.println("    \"\\n\"");
		pStream.println("    |");
		pStream.println("    \"\\r\"");
		pStream.println("    |");
		pStream.println("    \"\\f\"");
		pStream.println("}// WHITE SPACE");
		pStream.println();
		pStream.println("SPECIAL_TOKEN : /* COMMENTS */ ");
		pStream.println("{");
		pStream.println("    < \"<!--\" ( ~[\"-\"] | ( \"-\" ~[\"-\"] ) )* \"-->\">");
		pStream.println("  | < \"<rdfs:comment\" ( ~[\"<\"] | ( \"<\" ~[\"/\"] ) )* \"</rdfs:comment>\" >");
		pStream.println("}// COMMENTS");
		pStream.println();
	}

	void Start.genJavaCCLiterals(PrintStream pStream) {
		pStream.println("<DEFAULT, BOUNDS> TOKEN : /* LITERALS */");
		pStream.println("{");
		pStream.println("    < INTEGER_LITERAL:");
		pStream.println("        <DECIMAL_LITERAL> ([\"l\",\"L\"])?");
		pStream.println("        |");
		pStream.println("        <HEX_LITERAL> ([\"l\",\"L\"])?");
		pStream.println("        |");
		pStream.println("        <OCTAL_LITERAL> ([\"l\",\"L\"])?");
		pStream.println("    >");
		pStream.println("    |");
		pStream.println("    < #DECIMAL_LITERAL: [\"1\"-\"9\"] ([\"0\"-\"9\"])* >");
		pStream.println("    |");
		pStream.println("    < #HEX_LITERAL: \"0\" [\"x\",\"X\"] ([\"0\"-\"9\",\"a\"-\"f\",\"A\"-\"F\"])+ >");
		pStream.println("    |");
		pStream.println("    < #OCTAL_LITERAL: \"0\" ([\"0\"-\"7\"])* >");
		pStream.println("    |");
		pStream.println("    < FLOAT_LITERAL:");
		pStream.println("        ([\"0\"-\"9\"])+ \".\" ([\"0\"-\"9\"])* (<EXPONENT>)? ([\"f\",\"F\",\"d\",\"D\"])?");
		pStream.println("        |");
		pStream.println("        \".\" ([\"0\"-\"9\"])+ (<EXPONENT>)? ([\"f\",\"F\",\"d\",\"D\"])?");
		pStream.println("        |");
		pStream.println("        ([\"0\"-\"9\"])+ <EXPONENT> ([\"f\",\"F\",\"d\",\"D\"])?");
		pStream.println("        |");
		pStream.println("        ([\"0\"-\"9\"])+ (<EXPONENT>)? [\"f\",\"F\",\"d\",\"D\"]");
		pStream.println("    >");
		pStream.println("    |");
		pStream.println("    < #EXPONENT: [\"e\",\"E\"] ([\"+\",\"-\"])? ([\"0\"-\"9\"])+ >");
		pStream.println("    |");
		pStream.println("    < CHARACTER_LITERAL:");
		pStream.println("        \"\'\"");
95
		pStream.println("        (   (~[\"\'\",\"\\\\\",\"\\n\",\"\\r\"])");
96
		pStream.println("            |");
97 98
		pStream.println("            (\"\\\\\"");
		pStream.println("                (   [\"n\",\"t\",\"b\",\"r\",\"f\",\"\\\\\",\"'\",\"\\\"\"]");
99 100 101 102 103 104 105 106 107 108 109 110
		pStream.println("                    |");
		pStream.println("                    [\"0\"-\"7\"] ( [\"0\"-\"7\"] )?");
		pStream.println("                    |");
		pStream.println("                    [\"0\"-\"3\"] [\"0\"-\"7\"] [\"0\"-\"7\"]");
		pStream.println("                )");
		pStream.println("            )");
		pStream.println("        )");
		pStream.println("        \"'\"");
		pStream.println("    >");
		pStream.println("    |");
		pStream.println("    < STRING_LITERAL:");
		pStream.println("        \"\\\"\"");
111
		pStream.println("        (   (~[\"\\\"\",\"\\\\\",\"\\n\",\"\\r\"])");
112
		pStream.println("            |");
113 114
		pStream.println("            (\"\\\\\"");
		pStream.println("                (    [\"n\",\"t\",\"b\",\"r\",\"f\",\"\\\\\",\"'\",\"\\\"\"]");
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
		pStream.println("                     |");
		pStream.println("                     [\"0\"-\"7\"] ( [\"0\"-\"7\"] )?");
		pStream.println("                     |");
		pStream.println("                     [\"0\"-\"3\"] [\"0\"-\"7\"] [\"0\"-\"7\"]");
		pStream.println("                )");
		pStream.println("            )");
		pStream.println("        )*");
		pStream.println("        \"\\\"\"");
		pStream.println("    >");
		pStream.println("}// LITERALS");
	}

	void Start.genJavaCCIdentifiers(PrintStream pStream) {
		pStream.println("<DEFAULT, BOUNDS> TOKEN : /* IDENTIFIERS */");
		pStream.println("{");
		pStream.println("    < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>|\"-\")* >");
		pStream.println("    |");
		pStream.println("    < #LETTER:");
		pStream.println("        [");
		pStream.println("        \"\\u0024\",");
		pStream.println("        \"\\u0041\"-\"\\u005a\",");
		pStream.println("        \"\\u005f\",");
		pStream.println("        \"\\u0061\"-\"\\u007a\",");
		pStream.println("        \"\\u00c0\"-\"\\u00d6\",");
		pStream.println("        \"\\u00d8\"-\"\\u00f6\",");
		pStream.println("        \"\\u00f8\"-\"\\u00ff\",");
		pStream.println("        \"\\u0100\"-\"\\u1fff\",");
		pStream.println("        \"\\u3040\"-\"\\u318f\",");
		pStream.println("        \"\\u3300\"-\"\\u337f\",");
		pStream.println("        \"\\u3400\"-\"\\u3d2d\",");
		pStream.println("        \"\\u4e00\"-\"\\u9fff\",");
		pStream.println("        \"\\uf900\"-\"\\ufaff\"");
		pStream.println("        ]");
		pStream.println("    >");
		pStream.println("    |");
		pStream.println("    < #DIGIT:");
		pStream.println("        [");
		pStream.println("        \"\\u0030\"-\"\\u0039\",");
		pStream.println("        \"\\u0660\"-\"\\u0669\",");
		pStream.println("        \"\\u06f0\"-\"\\u06f9\",");
		pStream.println("        \"\\u0966\"-\"\\u096f\",");
		pStream.println("        \"\\u09e6\"-\"\\u09ef\",");
		pStream.println("        \"\\u0a66\"-\"\\u0a6f\",");
		pStream.println("        \"\\u0ae6\"-\"\\u0aef\",");
		pStream.println("        \"\\u0b66\"-\"\\u0b6f\",");
		pStream.println("        \"\\u0be7\"-\"\\u0bef\",");
		pStream.println("        \"\\u0c66\"-\"\\u0c6f\",");
		pStream.println("        \"\\u0ce6\"-\"\\u0cef\",");
		pStream.println("        \"\\u0d66\"-\"\\u0d6f\",");
		pStream.println("        \"\\u0e50\"-\"\\u0e59\",");
		pStream.println("        \"\\u0ed0\"-\"\\u0ed9\",");
		pStream.println("        \"\\u1040\"-\"\\u1049\"");
		pStream.println("        ]");
		pStream.println("    >");
		pStream.println("}// IDENTIFIERS");
	}

	void Start.genJavaCCSeparators(PrintStream pStream) {
		pStream.println("<DEFAULT,BOUNDS> TOKEN : /* SEPARATORS */");
		pStream.println("{");
		pStream.println("     < LBRACE               : \"{\"    >");
		pStream.println("    | < RBRACE               : \"}\"    >");
		pStream.println("    | < LBRACKET             : \"[\"    >");
		pStream.println("    | < RBRACKET             : \"]\"    >");
		pStream.println("    | < SEMICOLON            : \";\"    >");
		pStream.println("}// SEPARATORS");
	}

	void Start.genJavaCCOperators(PrintStream pStream) {
		pStream.println("<DEFAULT,BOUNDS> TOKEN : /* OPERATORS */");
		pStream.println("{");
		pStream.println("      < ASSIGN               : \"=\"    >");
		pStream.println("}// OPERATORS");
	}
}