From 6e79c3686104695a31a5240aac839cf3cbef3530 Mon Sep 17 00:00:00 2001 From: parrt Date: Tue, 6 Dec 2011 12:09:19 -0800 Subject: [PATCH] add verbose dfa state option [git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9537] --- tool/src/org/antlr/v4/Tool.java | 8 ++- tool/src/org/antlr/v4/tool/DOTGenerator.java | 64 ++++++++++---------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/tool/src/org/antlr/v4/Tool.java b/tool/src/org/antlr/v4/Tool.java index e89335c71..9b50b5173 100644 --- a/tool/src/org/antlr/v4/Tool.java +++ b/tool/src/org/antlr/v4/Tool.java @@ -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 diff --git a/tool/src/org/antlr/v4/tool/DOTGenerator.java b/tool/src/org/antlr/v4/tool/DOTGenerator.java index 21a042f89..b3dcdad55 100644 --- a/tool/src/org/antlr/v4/tool/DOTGenerator.java +++ b/tool/src/org/antlr/v4/tool/DOTGenerator.java @@ -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 alts = ((DFAState)s).getAltSet(); + if ( grammar.tool.verbose_dfa ) { + Set alts = s.getAltSet(); if ( alts!=null ) { buf.append("\\n"); // separate alts List altList = new ArrayList(); altList.addAll(alts); Collections.sort(altList); - Set configurations = ((DFAState)s).configs; + Set 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)