The introduction to the IDE ANTLR eclipse plugin

The instalation

(You can skip it) if already installed.

On the wiki page of the ANTLR project we can find:

We can also find it on the bottom of the "download" page of the project. Regardless from the way we are here I advice you to choose the second environment - ANTLR IDE, the first is strange.

After entering the page, choose "Download/Install" panel as you can see below. Impotrant! Check twice which version of the eclipse do you have and choose the according plug-in version (the plug-in for Indigo was the last published but it works fine under succesive eclipses). Versions of additional prerequisites are also important, particularly DLTK, which - look carefully - is not specified as "3.0.0+" but particular version is demanded for the particular eclipse and the particular ANTLR IDE. Amen (feel warned!). BTW: this version was published in Indigo main update repository.


As we have all things installed, we can make a new project.

Java project. Maybe we will be asked for the switching of the perspective. Be kind, let the eclipse change it.

Certainly we are to choose the project name. Next, choose the proper Project layout. The current plugin version working in Luna or newer eclipse works with separate source folders but you MUST set the output folder to src not bin (bottom of the "Source" tab). Check also the version of java - must be up to date. Now click the Next, not Finish yet.

Next, what for? The answer is on the following three pictures.

add ext jar

Here as the output folder set the src not bin.

add ext jar

Here we can choose antlr-X.Y.jar or antlrworks-X.Y.Z.jar. I would advice antlr-3.4-complete.jar - the current version of the antlrworks does NOT contain the proper set of tools and libraries versions. This jar is in /opt/antlr3/3.4/ directory.

Now we can click Finish and ensure that the library appeared in the Package Explorer.

The last thing to make the project the ANTLR type is:

It would be fine to look at the page for a moment, and return here when the following dialog will be noticed.

When we try to open a grammar file, the following question should to appear. The correct answer is "Yes".

In case of lack of the question or incorrect answer, do not panic. You can choose the Preferences from the Window menu.

After the "Yes" answer or after the preferences choise we have the following.

  1. here go deeper a bit - to /opt/antlr3/3.4/
  2. do not care about the 3.3 version in pictures, we will use 3.4 version
  3. Here you can click "OK".

Now the promised file Certainly the name is of your choice, this one is an example. At the beginning check the existence of the following imports as well as if they are not red underscored.

Now the name consistency problem. From the grammar file XXXX of type Lexer, Parser or Tree the class XXXX in the file is derived. From the Combined grammar having the same name, two classes and files are generated - and
Red lines depicts the data flows. Name of the starting syntax rule is marked yellow.

Similarly. Here we have the file TTExpr.g which is useless now. The printing of the tree on the console may be left for the debug purposes or may be deleted (commented out).

Now some words about templates.

More you can find in this document.