add verbose dfa state option

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9537]
This commit is contained in:
parrt 2011-12-06 12:09:19 -08:00
parent afb89c56b9
commit 6e79c36861
2 changed files with 37 additions and 35 deletions

View File

@ -94,6 +94,7 @@ public class Tool {
public boolean launch_ST_inspector = false;
public boolean force_atn = false;
public boolean log = false;
public boolean verbose_dfa = false;
public static Option[] optionDefs = {
new Option("outputDirectory", "-o", OptionArgType.STRING, "specify output directory where all output is generated"),
@ -106,10 +107,11 @@ public class Tool {
new Option("generate_ATN_dot", "-atn", "generate rule augmented transition networks"),
new Option("msgFormat", "-message-format", OptionArgType.STRING, "specify output style for messages"),
new Option("genListener", "-walker", "generate parse tree walker and listener"),
new Option("saveLexer", "-Xsavelexer", "save temp lexer file created for combined grammars"),
new Option("saveLexer", "-Xsave-lexer", "save temp lexer file created for combined grammars"),
new Option("launch_ST_inspector", "-XdbgST", "launch StringTemplate visualizer on generated code"),
new Option("force_atn", "-Xforceatn", "use the ATN simulator for all predictions"),
new Option("log", "-Xlog", "dump lots of logging info to antlr-timestamp.log"),
new Option("force_atn", "-Xforce-atn", "use the ATN simulator for all predictions"),
new Option("log", "-Xlog", "dump lots of logging info to antlr-timestamp.log"),
new Option("verbose_dfa", "-Xverbose-dfa", "add config set to DFA states"),
};
// helper vars for option management

View File

@ -1,38 +1,41 @@
/*
[The "BSD license"]
Copyright (c) 2011 Terence Parr
All rights reserved.
Copyright (c) 2011 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:
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.
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.
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.v4.tool;
import org.antlr.v4.misc.Utils;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.*;
import org.stringtemplate.v4.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.dfa.DFAState;
import org.stringtemplate.v4.ST;
import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupDir;
import java.util.*;
@ -112,19 +115,17 @@ public class DOTGenerator {
if ( s.isAcceptState ) {
buf.append("=>"+s.prediction);
}
// if ( Tool.internalOption_ShowATNConfigsInDFA ) {
if ( false ) {
Set<Integer> alts = ((DFAState)s).getAltSet();
if ( grammar.tool.verbose_dfa ) {
Set<Integer> alts = s.getAltSet();
if ( alts!=null ) {
buf.append("\\n");
// separate alts
List<Integer> altList = new ArrayList<Integer>();
altList.addAll(alts);
Collections.sort(altList);
Set<ATNConfig> configurations = ((DFAState)s).configs;
Set<ATNConfig> configurations = s.configs;
for (int altIndex = 0; altIndex < altList.size(); altIndex++) {
Integer altI = (Integer) altList.get(altIndex);
int alt = altI.intValue();
int alt = altList.get(altIndex);
if ( altIndex>0 ) {
buf.append("\\n");
}
@ -141,8 +142,7 @@ public class DOTGenerator {
}
int n = 0;
for (int cIndex = 0; cIndex < configsInAlt.size(); cIndex++) {
ATNConfig c =
(ATNConfig)configsInAlt.get(cIndex);
ATNConfig c = configsInAlt.get(cIndex);
n++;
buf.append(c.toString(null, false));
if ( (cIndex+1)<configsInAlt.size() ) {