org.antlr
Class Tool

java.lang.Object
  extended by org.antlr.Tool

public class Tool
extends java.lang.Object

The main ANTLR entry point. Read a grammar and generate a parser.


Field Summary
protected  boolean debug
           
protected  boolean deleteTempLexer
           
protected  boolean depend
           
protected  boolean forceAllFilesToOutputDir
           
protected  boolean generate_DFA_dot
           
protected  boolean generate_NFA_dot
           
protected  java.util.List grammarFileNames
           
static boolean internalOption_PrintDFA
           
static boolean internalOption_PrintGrammarTree
           
static boolean internalOption_ShowNFAConfigsInDFA
           
static boolean internalOption_watchNFAConversion
           
protected  java.lang.String libDirectory
           
protected  java.lang.String outputDirectory
           
protected  boolean printGrammar
           
protected  boolean profile
           
protected  boolean report
           
static java.lang.String REV
           
protected  boolean trace
           
static java.lang.String UNINITIALIZED_DIR
           
static java.lang.String VERSION
           
 
Constructor Summary
Tool()
           
Tool(java.lang.String[] args)
           
 
Method Summary
 void generateDFAs(Grammar g)
           
protected  void generateNFAs(Grammar g)
           
protected  void generateRecognizer(Grammar grammar)
          Create NFA, DFA and generate code for grammar.
static java.lang.String getCurrentTimeStamp()
          Return a time stamp string accurate to sec: yyyy-mm-dd hh:mm:ss
 java.lang.String getFileDirectory(java.lang.String fileName)
          Return the directory containing the grammar file for this grammar.
 java.io.File getImportedVocabFile(java.lang.String vocabName)
          Return a File descriptor for vocab file.
 java.lang.String getLibraryDirectory()
           
 java.lang.String getLibraryFile(java.lang.String fileName)
          Name a file in the -lib dir.
 java.io.File getOutputDirectory(java.lang.String fileNameWithPath)
           
 java.io.Writer getOutputFile(Grammar g, java.lang.String fileName)
          This method is used by all code generators to create new output files.
 Grammar getRootGrammar(java.lang.String grammarFileName)
          Get a grammar mentioned on the command-line and any delegates
static void main(java.lang.String[] args)
           
 void panic()
          If the tool needs to panic/exit, how do we do that?
 void process()
           
 void processArgs(java.lang.String[] args)
           
 void setOutputDirectory(java.lang.String outputDirectory)
           
protected  void writeDOTFile(Grammar g, Rule r, java.lang.String dot)
           
protected  void writeDOTFile(Grammar g, java.lang.String name, java.lang.String dot)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REV

public static final java.lang.String REV
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

UNINITIALIZED_DIR

public static final java.lang.String UNINITIALIZED_DIR
See Also:
Constant Field Values

grammarFileNames

protected java.util.List grammarFileNames

generate_NFA_dot

protected boolean generate_NFA_dot

generate_DFA_dot

protected boolean generate_DFA_dot

outputDirectory

protected java.lang.String outputDirectory

libDirectory

protected java.lang.String libDirectory

debug

protected boolean debug

trace

protected boolean trace

profile

protected boolean profile

report

protected boolean report

printGrammar

protected boolean printGrammar

depend

protected boolean depend

forceAllFilesToOutputDir

protected boolean forceAllFilesToOutputDir

deleteTempLexer

protected boolean deleteTempLexer

internalOption_PrintGrammarTree

public static boolean internalOption_PrintGrammarTree

internalOption_PrintDFA

public static boolean internalOption_PrintDFA

internalOption_ShowNFAConfigsInDFA

public static boolean internalOption_ShowNFAConfigsInDFA

internalOption_watchNFAConversion

public static boolean internalOption_watchNFAConversion
Constructor Detail

Tool

public Tool()

Tool

public Tool(java.lang.String[] args)
Method Detail

main

public static void main(java.lang.String[] args)

processArgs

public void processArgs(java.lang.String[] args)

process

public void process()

getRootGrammar

public Grammar getRootGrammar(java.lang.String grammarFileName)
                       throws java.io.IOException
Get a grammar mentioned on the command-line and any delegates

Throws:
java.io.IOException

generateRecognizer

protected void generateRecognizer(Grammar grammar)
Create NFA, DFA and generate code for grammar. Create NFA for any delegates first. Once all NFA are created, it's ok to create DFA, which must check for left-recursion. That check is done by walking the full NFA, which therefore must be complete. After all NFA, comes DFA conversion for root grammar then code gen for root grammar. DFA and code gen for delegates comes next.


generateDFAs

public void generateDFAs(Grammar g)

generateNFAs

protected void generateNFAs(Grammar g)

writeDOTFile

protected void writeDOTFile(Grammar g,
                            Rule r,
                            java.lang.String dot)
                     throws java.io.IOException
Throws:
java.io.IOException

writeDOTFile

protected void writeDOTFile(Grammar g,
                            java.lang.String name,
                            java.lang.String dot)
                     throws java.io.IOException
Throws:
java.io.IOException

setOutputDirectory

public void setOutputDirectory(java.lang.String outputDirectory)

getOutputFile

public java.io.Writer getOutputFile(Grammar g,
                                    java.lang.String fileName)
                             throws java.io.IOException
This method is used by all code generators to create new output files. If the outputDir set by -o is not present it will be created. The final filename is sensitive to the output directory and the directory where the grammar file was found. If -o is /tmp and the original grammar file was foo/t.g then output files go in /tmp/foo. The output dir -o spec takes precedence if it's absolute. E.g., if the grammar file dir is absolute the output dir is given precendence. "-o /tmp /usr/lib/t.g" results in "/tmp/T.java" as output (assuming t.g holds T.java). If no -o is specified, then just write to the directory where the grammar file was found. If outputDirectory==null then write a String.

Throws:
java.io.IOException

getOutputDirectory

public java.io.File getOutputDirectory(java.lang.String fileNameWithPath)

getLibraryFile

public java.lang.String getLibraryFile(java.lang.String fileName)
                                throws java.io.IOException
Name a file in the -lib dir. Imported grammars and .tokens files

Throws:
java.io.IOException

getLibraryDirectory

public java.lang.String getLibraryDirectory()

getFileDirectory

public java.lang.String getFileDirectory(java.lang.String fileName)
Return the directory containing the grammar file for this grammar. normally this is a relative path from current directory. People will often do "java org.antlr.Tool grammars/*.g3" So the file will be "grammars/foo.g3" etc... This method returns "grammars".


getImportedVocabFile

public java.io.File getImportedVocabFile(java.lang.String vocabName)
Return a File descriptor for vocab file. Look in library or in -o output path. antlr -o foo T.g U.g where U needs T.tokens won't work unless we look in foo too.


panic

public void panic()
If the tool needs to panic/exit, how do we do that?


getCurrentTimeStamp

public static java.lang.String getCurrentTimeStamp()
Return a time stamp string accurate to sec: yyyy-mm-dd hh:mm:ss