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("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

@ -31,8 +31,11 @@ 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() ) {