📄 parsegen.java
字号:
/* * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has * intellectual property rights relating to technology embodied in the product * that is described in this document. In particular, and without limitation, * these intellectual property rights may include one or more of the U.S. * patents listed at http://www.sun.com/patents and one or more additional * patents or pending patent applications in the U.S. and in other countries. * U.S. Government Rights - Commercial software. Government users are subject * to the Sun Microsystems, Inc. standard license agreement and applicable * provisions of the FAR and its supplements. Use is subject to license terms. * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This * product is covered and controlled by U.S. Export Control laws and may be * subject to the export or import laws in other countries. Nuclear, missile, * chemical biological weapons or nuclear maritime end uses or end users, * whether direct or indirect, are strictly prohibited. Export or reexport * to countries subject to U.S. embargo or to entities identified on U.S. * export exclusion lists, including, but not limited to, the denied persons * and specially designated nationals lists is strictly prohibited. */package org.javacc.parser;import java.util.*;import java.io.*;public class ParseGen extends JavaCCGlobals implements JavaCCParserConstants { static public void start() throws MetaParseException { Token t = null; if (JavaCCErrors.get_error_count() != 0) throw new MetaParseException(); if (Options.B("BUILD_PARSER")) { try { ostr = new PrintWriter( new BufferedWriter( new FileWriter( new File(outputDir, cu_name + ".java") ), 8192 ) ); } catch (IOException e) { JavaCCErrors.semantic_error("Could not open file " + cu_name + ".java for writing."); throw new Error(); } Vector tn = (Vector)(toolNames.clone()); tn.addElement(toolName); ostr.println("/* " + getIdString(tn, cu_name + ".java") + " */"); boolean implementsExists = false; if (cu_to_insertion_point_1.size() != 0) { printTokenSetup((Token)(cu_to_insertion_point_1.elementAt(0))); ccol = 1; for (Enumeration enum = cu_to_insertion_point_1.elements(); enum.hasMoreElements();) { t = (Token)enum.nextElement(); if (t.kind == IMPLEMENTS) { implementsExists = true; } else if (t.kind == CLASS) { implementsExists = false; } printToken(t, ostr); } } if (implementsExists) { ostr.print(", "); } else { ostr.print(" implements "); } ostr.print(cu_name + "Constants "); if (cu_to_insertion_point_2.size() != 0) { printTokenSetup((Token)(cu_to_insertion_point_2.elementAt(0))); for (Enumeration enum = cu_to_insertion_point_2.elements(); enum.hasMoreElements();) { t = (Token)enum.nextElement(); printToken(t, ostr); } } ostr.println(""); ostr.println(""); ParseEngine.build(ostr); if (Options.B("STATIC")) { ostr.println(" static private boolean jj_initialized_once = false;"); } if (Options.B("USER_TOKEN_MANAGER")) { ostr.println(" " + staticOpt() + "public TokenManager token_source;"); } else { ostr.println(" " + staticOpt() + "public " + cu_name + "TokenManager token_source;"); if (!Options.B("USER_CHAR_STREAM")) { if (Options.B("JAVA_UNICODE_ESCAPE")) { ostr.println(" " + staticOpt() + "JavaCharStream jj_input_stream;"); } else { ostr.println(" " + staticOpt() + "SimpleCharStream jj_input_stream;"); } } } ostr.println(" " + staticOpt() + "public Token token, jj_nt;"); if (!Options.B("CACHE_TOKENS")) { ostr.println(" " + staticOpt() + "private int jj_ntk;"); } if (jj2index != 0) { ostr.println(" " + staticOpt() + "private Token jj_scanpos, jj_lastpos;"); ostr.println(" " + staticOpt() + "private int jj_la;"); ostr.println(" " + staticOpt() + "public boolean lookingAhead = false;"); ostr.println(" " + staticOpt() + "private boolean jj_semLA;"); } if (Options.B("ERROR_REPORTING")) { ostr.println(" " + staticOpt() + "private int jj_gen;"); ostr.println(" " + staticOpt() + "final private int[] jj_la1 = new int[" + maskindex + "];"); int tokenMaskSize = (tokenCount-1)/32 + 1; for (int i = 0; i < tokenMaskSize; i++) ostr.println(" static private int[] jj_la1_" + i + ";"); ostr.println(" static {"); for (int i = 0; i < tokenMaskSize; i++) ostr.println(" jj_la1_" + i + "();"); ostr.println(" }"); for (int i = 0; i < tokenMaskSize; i++) { ostr.println(" private static void jj_la1_" + i + "() {"); ostr.print(" jj_la1_" + i + " = new int[] {"); for (Enumeration enum = maskVals.elements(); enum.hasMoreElements();) { int[] tokenMask = (int[])(enum.nextElement()); ostr.print("0x" + Integer.toHexString(tokenMask[i]) + ","); } ostr.println("};"); ostr.println(" }"); } } if (jj2index != 0 && Options.B("ERROR_REPORTING")) { ostr.println(" " + staticOpt() + "final private JJCalls[] jj_2_rtns = new JJCalls[" + jj2index + "];"); ostr.println(" " + staticOpt() + "private boolean jj_rescan = false;"); ostr.println(" " + staticOpt() + "private int jj_gc = 0;"); } ostr.println(""); if (!Options.B("USER_TOKEN_MANAGER")) { if (Options.B("USER_CHAR_STREAM")) { ostr.println(" public " + cu_name + "(CharStream stream) {"); if (Options.B("STATIC")) { ostr.println(" if (jj_initialized_once) {"); ostr.println(" System.out.println(\"ERROR: Second call to constructor of static parser. You must\");"); ostr.println(" System.out.println(\" either use ReInit() or set the JavaCC option STATIC to false\");"); ostr.println(" System.out.println(\" during parser generation.\");"); ostr.println(" throw new Error();"); ostr.println(" }"); ostr.println(" jj_initialized_once = true;"); } ostr.println(" token_source = new " + cu_name + "TokenManager(stream);"); ostr.println(" token = new Token();"); if (Options.B("CACHE_TOKENS")) { ostr.println(" token.next = jj_nt = token_source.getNextToken();"); } else { ostr.println(" jj_ntk = -1;"); } if (Options.B("ERROR_REPORTING")) { ostr.println(" jj_gen = 0;"); ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); if (jj2index != 0) { ostr.println(" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } ostr.println(" }"); ostr.println(""); ostr.println(" " + staticOpt() + "public void ReInit(CharStream stream) {"); ostr.println(" token_source.ReInit(stream);"); ostr.println(" token = new Token();"); if (Options.B("CACHE_TOKENS")) { ostr.println(" token.next = jj_nt = token_source.getNextToken();"); } else { ostr.println(" jj_ntk = -1;"); } if (jjtreeGenerated) { ostr.println(" jjtree.reset();"); } if (Options.B("ERROR_REPORTING")) { ostr.println(" jj_gen = 0;"); ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); if (jj2index != 0) { ostr.println(" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } ostr.println(" }"); } else { ostr.println(" public " + cu_name + "(java.io.InputStream stream) {"); if (Options.B("STATIC")) { ostr.println(" if (jj_initialized_once) {"); ostr.println(" System.out.println(\"ERROR: Second call to constructor of static parser. You must\");"); ostr.println(" System.out.println(\" either use ReInit() or set the JavaCC option STATIC to false\");"); ostr.println(" System.out.println(\" during parser generation.\");"); ostr.println(" throw new Error();"); ostr.println(" }"); ostr.println(" jj_initialized_once = true;"); } if (Options.B("JAVA_UNICODE_ESCAPE")) { ostr.println(" jj_input_stream = new JavaCharStream(stream, 1, 1);"); } else { ostr.println(" jj_input_stream = new SimpleCharStream(stream, 1, 1);"); } ostr.println(" token_source = new " + cu_name + "TokenManager(jj_input_stream);"); ostr.println(" token = new Token();"); if (Options.B("CACHE_TOKENS")) { ostr.println(" token.next = jj_nt = token_source.getNextToken();"); } else { ostr.println(" jj_ntk = -1;"); } if (Options.B("ERROR_REPORTING")) { ostr.println(" jj_gen = 0;"); ostr.println(" for (int i = 0; i < " + maskindex + "; i++) jj_la1[i] = -1;"); if (jj2index != 0) { ostr.println(" for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();"); } } ostr.println(" }"); ostr.println(""); ostr.println(" " + staticOpt() + "public void ReInit(java.io.InputStream stream) {"); if (Options.B("JAVA_UNICODE_ESCAPE")) { ostr.println(" jj_input_stream.ReInit(stream, 1, 1);"); } else { ostr.println(" jj_input_stream.ReInit(stream, 1, 1);"); } ostr.println(" token_source.ReInit(jj_input_stream);"); ostr.println(" token = new Token();"); if (Options.B("CACHE_TOKENS")) { ostr.println(" token.next = jj_nt = token_source.getNextToken();"); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -