ANTLR is a parser generator: (like JavaCC, only newer technology). See ANTLRWorks.
To install it on my Mac, I first used fink, but that installed version 2.7.5, not 3.0. It also didn't install ANTLRWorks, so it wasn't a complete install. So I went to the ANTLR website and downloaded ANTLRWorks 1.0.2. It's supposed to include ANTLR. I unzip'd it and got ANTLRWorks.app, which I put in the Applications directory. I was able to execute ANTLRWorks and run a basic tutorial. Looked like I was ready to go, but I didn't know how to build from the command line.
So I went back to the website and downloaded antlr 3.0.1. I double-clicked it, which unzip'd and untar'd it, leaving an antlr-3.0.1 directory. I moved it to ~/antlrplay. The crucial piece is the ANTLR jar files in /Users/siemsen/antlrplay/antlr-3.0.1/lib/. To make it part of my Java CLASSPATH, I added these lines to my .bashrc file:
if [[ -d ~/antlrplay/antlr-3.0.1/lib ]]; then classadd ~/antlrplay/antlr-3.0.1/lib/antlr-3.0.1.jar classadd ~/antlrplay/antlr-3.0.1/lib/antlr-runtime-3.0.1.jar classadd ~/antlrplay/antlr-3.0.1/lib/stringtemplate-3.1b1.jar classadd ~/antlrplay/antlr-3.0.1/lib/antlr-2.7.7.jar fiAfter this, you can run ANTLR from the command line:
oryx$ java org.antlr.Tool ANTLR Parser Generator Version 3.0 (May 17, 2007) 1989-2007 usage: java org.antlr.Tool [args] file.g [file2.g file3.g ...] -o outputDir specify output directory where all output is generated -fo outputDir same as -o but force even files with relative paths to dir -lib dir specify location of token files -depend generate file dependencies -report print out a report about the grammar(s) processed -print print out the grammar without actions -debug generate a parser that emits debugging events -profile generate a parser that computes profiling information -nfa generate an NFA for each rule -dfa generate a DFA for each decision point -message-format name specify output style for messages -X display extended argument list oryx$
Then I looked at the Getting Started webpage, and went and got http://www.antlr.org/download/examples-v3.tar.gz. I unzip'd/untar'd it and saved it in ~/antlrplay/examples-v3. Then I created and compiled a simple C parser:
~cd antlrplay/examples-v3/java/LL-star java org.antlr.Tool SimpleC.g javac *.java
Then I ran it on a provided file containing C code named "input":
java Main input bar is a declaration foo is a definitionTo use Eclipse to edit ANTLR grammars, see AntlrDT on my Eclipse page.