⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tool.java

📁 antlr最新版本V3源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* [The "BSD licence"] Copyright (c) 2005-2006 Terence Parr All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright    notice, this list of conditions and the following disclaimer. 2. 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. 3. The name of the author may not be used to endorse or promote products    derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 org.antlr;import org.antlr.tool.*;import org.antlr.codegen.CodeGenerator;import org.antlr.analysis.*;import org.antlr.runtime.misc.Stats;import java.io.*;import java.util.*;/** The main ANTLR entry point.  Read a grammar and generate a parser. */public class Tool {	public static final String VERSION = "3.0";	public static final String UNINITIALIZED_DIR = "<unset-dir>";    // Input parameters / option    protected List grammarFileNames = new ArrayList();	protected boolean generate_NFA_dot = false;	protected boolean generate_DFA_dot = false;	protected String outputDirectory = UNINITIALIZED_DIR;	protected String libDirectory = ".";	protected boolean debug = false;	protected boolean trace = false;	protected boolean profile = false;	protected boolean report = false;	protected boolean printGrammar = false;	protected boolean depend = false;	protected boolean forceAllFilesToOutputDir = false;	// the internal options are for my use on the command line during dev	public static boolean internalOption_PrintGrammarTree = false;	public static boolean internalOption_PrintDFA = false;	public static boolean internalOption_ShowNFConfigsInDFA = false;	public static boolean internalOption_watchNFAConversion = false;    public static void main(String[] args) {		ErrorManager.info("ANTLR Parser Generator  Version " +						  VERSION + " (May 17, 2007)  1989-2007");		Tool antlr = new Tool(args);		antlr.process();		System.exit(0);	}	public Tool() {	}	public Tool(String[] args) {		processArgs(args);	}	public void processArgs(String[] args) {		if ( args==null || args.length==0 ) {			help();			return;		}		for (int i = 0; i < args.length; i++) {			if (args[i].equals("-o") || args[i].equals("-fo")) {				if (i + 1 >= args.length) {					System.err.println("missing output directory with -fo/-o option; ignoring");				}				else {					if ( args[i].equals("-fo") ) { // force output into dir						forceAllFilesToOutputDir = true;					}					i++;					outputDirectory = args[i];					if ( outputDirectory.endsWith("/") ||						 outputDirectory.endsWith("\\") )					{						outputDirectory =							outputDirectory.substring(0,outputDirectory.length()-1);					}					File outDir = new File(outputDirectory);					if( outDir.exists() && !outDir.isDirectory() ) {						ErrorManager.error(ErrorManager.MSG_OUTPUT_DIR_IS_FILE,outputDirectory);						libDirectory = ".";					}				}			}			else if (args[i].equals("-lib")) {				if (i + 1 >= args.length) {					System.err.println("missing library directory with -lib option; ignoring");				}				else {					i++;					libDirectory = args[i];					if ( libDirectory.endsWith("/") ||						 libDirectory.endsWith("\\") )					{						libDirectory =							libDirectory.substring(0,libDirectory.length()-1);					}					File outDir = new File(libDirectory);					if( !outDir.exists() ) {						ErrorManager.error(ErrorManager.MSG_DIR_NOT_FOUND,libDirectory);						libDirectory = ".";					}				}			}			else if (args[i].equals("-verbose")) {				DecisionProbe.verbose=true;			}			else if (args[i].equals("-nfa")) {				generate_NFA_dot=true;			}			else if (args[i].equals("-dfa")) {				generate_DFA_dot=true;			}			else if (args[i].equals("-debug")) {				debug=true;			}			else if (args[i].equals("-trace")) {				trace=true;			}			else if (args[i].equals("-report")) {				report=true;			}			else if (args[i].equals("-profile")) {				profile=true;			}			else if (args[i].equals("-print")) {				printGrammar = true;			}			else if (args[i].equals("-depend")) {				depend=true;			}			else if (args[i].equals("-message-format")) {				if (i + 1 >= args.length) {					System.err.println("missing output format with -message-format option; using default");				}				else {					i++;					ErrorManager.setFormat(args[i]);				}			}			else if (args[i].equals("-Xgrtree")) {				internalOption_PrintGrammarTree=true; // print grammar tree			}			else if (args[i].equals("-Xdfa")) {				internalOption_PrintDFA=true;			}			else if (args[i].equals("-Xnoprune")) {				DFAOptimizer.PRUNE_EBNF_EXIT_BRANCHES=false;			}			else if (args[i].equals("-Xnocollapse")) {				DFAOptimizer.COLLAPSE_ALL_PARALLEL_EDGES=false;			}			else if (args[i].equals("-Xdbgconversion")) {				NFAToDFAConverter.debug = true;			}			else if (args[i].equals("-Xmultithreaded")) {				NFAToDFAConverter.SINGLE_THREADED_NFA_CONVERSION = false;			}			else if (args[i].equals("-Xnomergestopstates")) {				DFAOptimizer.MERGE_STOP_STATES = false;			}			else if (args[i].equals("-Xdfaverbose")) {				internalOption_ShowNFConfigsInDFA = true;			}			else if (args[i].equals("-Xwatchconversion")) {				internalOption_watchNFAConversion = true;			}			else if (args[i].equals("-XdbgST")) {				CodeGenerator.EMIT_TEMPLATE_DELIMITERS = true;			}			else if (args[i].equals("-Xnoinlinedfa")) {				CodeGenerator.GEN_ACYCLIC_DFA_INLINE = false;			}			else if (args[i].equals("-Xm")) {				if (i + 1 >= args.length) {					System.err.println("missing max recursion with -Xm option; ignoring");				}				else {					i++;					NFAContext.MAX_SAME_RULE_INVOCATIONS_PER_NFA_CONFIG_STACK = Integer.parseInt(args[i]);				}			}			else if (args[i].equals("-Xmaxdfaedges")) {				if (i + 1 >= args.length) {					System.err.println("missing max number of edges with -Xmaxdfaedges option; ignoring");				}				else {					i++;					DFA.MAX_STATE_TRANSITIONS_FOR_TABLE = Integer.parseInt(args[i]);				}			}			else if (args[i].equals("-Xconversiontimeout")) {				if (i + 1 >= args.length) {					System.err.println("missing max time in ms -Xconversiontimeout option; ignoring");				}				else {					i++;					DFA.MAX_TIME_PER_DFA_CREATION = Integer.parseInt(args[i]);				}			}			else if (args[i].equals("-X")) {				Xhelp();			}            else {                if (args[i].charAt(0) != '-') {                    // Must be the grammar file                    grammarFileNames.add(args[i]);                }            }        }    }    /*    protected void checkForInvalidArguments(String[] args, BitSet cmdLineArgValid) {        // check for invalid command line args        for (int a = 0; a < args.length; a++) {            if (!cmdLineArgValid.member(a)) {                System.err.println("invalid command-line argument: " + args[a] + "; ignored");            }        }    }    */    public void process()  {		int numFiles = grammarFileNames.size();		for (int i = 0; i < numFiles; i++) {			String grammarFileName = (String) grammarFileNames.get(i);			if ( numFiles > 1 && !depend ) {			    System.out.println(grammarFileName);			}			try {				if ( depend ) {					BuildDependencyGenerator dep =						new BuildDependencyGenerator(this, grammarFileName);					List outputFiles = dep.getGeneratedFileList();					List dependents = dep.getDependenciesFileList();					//System.out.println("output: "+outputFiles);					//System.out.println("dependents: "+dependents);					System.out.println(dep.getDependencies());					continue;				}				Grammar grammar = getGrammar(grammarFileName);				processGrammar(grammar);				if ( printGrammar ) {					grammar.printGrammar(System.out);				}				if ( generate_NFA_dot ) {					generateNFAs(grammar);				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -