Where does ANTLR write output files?

ANTLR writes files to the current directory by default. But, the output filename is sensitive to the output directory and the directory where the grammar file was found. If you reference a grammar with a (relative or absolute) path,
ANTLR will pull the grammar from that directory and write the output to that directory:

$ cd ~parrt
$ java org.antlr.Tool T.g       # write to ~parrt/TParser.java
$ java org.antlr.Tool /foo/T.g  # write to /foo/TParser.java

If you specify an output directory with -o then ANTLR will put the output files in that directory or underneath if you have a relative path on the grammar file:

$ java org.antlr.Tool -o /tmp T.g      # write to /tmp/TParser.java
$ java org.antlr.Tool -o /tmp sub/T.g  # write to /tmp/sub/TParser.java

The output directory -o value takes precedence over the grammar's path when the output directory is absolute.

$ java org.antlr.Tool -o /tmp /usr/lib/T.g  # write to /tmp/TParser.java
$ java org.antlr.Tool -o ick /usr/lib/T.g   # write to ick/TParser.java 
$ java org.antlr.Tool -o . /usr/lib/T.g     # write to TParser.java 

Use -fo option to force output to go explicitly into a directory, ignoring any path on the input grammar name.

$ java org.antlr.Tool -fo /tmp T.g           # write to /tmp/TParser.java
$ java org.antlr.Tool -fo /tmp sub/T.g       # write to /tmp/TParser.java
$ java org.antlr.Tool -fo /tmp /usr/lib/T.g  # write to /tmp/TParser.java

Note: If the outputDir set by -o is not present it will be created.