What is ANTLR?
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.
Check out Terence's latest adventure explained.ai
Terence Parr is the maniac behind ANTLR and has been
working on language tools since 1989. He is a professor of computer
science at the
University of San Francisco.
Samples
OS X
$ cd /usr/local/lib
$ sudo curl -O https://www.antlr.org/download/antlr-4.9.1-complete.jar
$ export CLASSPATH=".:/usr/local/lib/antlr-4.9.1-complete.jar:$CLASSPATH"
$ alias antlr4='java -jar /usr/local/lib/antlr-4.9.1-complete.jar'
$ alias grun='java org.antlr.v4.gui.TestRig'
LINUX
$ cd /usr/local/lib
$ wget https://www.antlr.org/download/antlr-4.9.1-complete.jar
$ export CLASSPATH=".:/usr/local/lib/antlr-4.9.1-complete.jar:$CLASSPATH"
$ alias antlr4='java -jar /usr/local/lib/antlr-4.9.1-complete.jar'
$ alias grun='java org.antlr.v4.gui.TestRig'
grammar Expr;
prog: (expr NEWLINE)* ;
expr: expr ('*'|'/') expr
| expr ('+'|'-') expr
| INT
| '(' expr ')'
;
NEWLINE : [\r\n]+ ;
INT : [0-9]+ ;
$ antlr4 Expr.g4
$ javac Expr*.java
$ grun Expr prog -gui
100+2*34
^D
Linux
Mac