ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees.
Antlr Versions
Antlr is separated in two big parts, the grammar (grammar files) and the generated code files, which derive from the grammar based on target language. The antlr versions are in the format of V1.V2.V3 :
Runtime Libraries and Code Generation Targets
The Antlr tool is written in Java, however it is able to generate parsers and lexers in various languages. To run the parser and lexer you will also need having the runtime library of antlr alongside with the parser and lexer code. The supported target language (and runtime libraries) are the following:
Java
C#
Python (2 and 3)
JavaScript
Version | Release Date |
---|---|
2.0 | 1997-05-01 |
3.0 | 2011-01-19 |
4.0 | 2013-01-21 |
4.1 | 2013-07-01 |
4.2 | 2014-02-05 |
4.2.1 | 2014-03-25 |
4.2.2 | 2014-04-07 |
4.3 | 2014-06-19 |
4.4 | 2014-07-16 |
4.5 | 2015-01-23 |
4.5.1 | 2016-07-16 |
4.5.2 | 2016-01-30 |
4.5.3 | 2016-03-31 |
4.6 | 2016-12-15 |
4.7 | 2017-03-30 |
A simple hello world grammar can be found here:
// define a grammar called Hello
grammar Hello;
r : 'hello' ID;
ID : [a-z]+ ;
WS : [ \t\r\n]+ -> skip ;
To build this .g4 sample you can run the following command from your operating systems terminal/command-line:
Java -jar antlr-4.5.3-complete.jar Hello.g4
//OR if you have setup an alias or use the recommended batch file
antlr4 Hello.g4
Building this example should result in the following output in the Hello.g4 file directory:
When using these files in your own project be sure to include the ANTLR jar file. To compile all of these files using Java, in the same operating directory or by path run the following command:
javac *.java