I recently completed two ANTLR3 assignments (I'm working on my MSc in Computer Science) using Eclipse. I did not find a single document in which there was a process of installing, configuring, writing and debugging grammar in Eclipse. So, after working on various issues, I found that it was easiest to stay in Eclipse for testing.
To use this process that I used (described below), you must first install the ANTLR IDE v2.1.2. Add it directly from inside Eclipse Indigo: http://antlrv3ide.sourceforge.net/updates . This site also has a helpful document on using the ANTLR IDE. After installing the IDE you need to configure. Video tutorials are a bit outdated, but useful. See the Detailed Guide to Configuring the ANTLR IDE in Eclipse . The main configuration item is the java output folder. Do it in Eclipse, going to Windows, Preferences, ANTLR, Code Generator, check the relative Project folder, and in the "Output folder name" field, enter the name of the folder (mine is called "antlr-java", others use "generated").
Testing / Debugging Process for ANTLR in Eclipse Indigo with ANTLR IDE
- After creating a new project, right-click it, select Configure, Convert to Project ANTLR ...
- Create a grammar in a .g file and save it. Note: the file name must match the grammar name.
- If there are significant errors, debug the grammar. Eclipse shows an ANTLR error and which lines are affected. At first, these errors seem difficult to understand, but they can be handled using various resources: - The final ANTLR Reference by Terence Parr, who wrote ANTLR - ANTLR Reference Manual - Google's bug; many times you get here in stackoverflow; in particular, Bart Kirs is knowledgeable and helpful (Bart: thanks for the help you did not know that you gave me)
- At the first save, after serious ANTLR errors are resolved, the java output folder you configured in Eclipse will be created and a java file will be created in this folder.
- Right-click on the java output folder, select "Build Path", "Use as Source Folder". This tells Eclipse where to look for the source of the java project.
- There may be errors in the new java file. Select it, then search through for Java errors. Go back to your grammar or java files (s), correct the errors and save the grammar again until both the grammar and java files are error free and then run it.
- From now on, this is the usual change-start-debug cycle.
- The only other Eclipse change I needed was to create several Run Configurations to test command line options.
source share