# AntlrWorks in NetBeans Tutorial
(1) Download the latest version of ANTLR (for example, antlr-4.5-complete.jar) and store it on your machine (for example, in /usr/local/lib).
(2) Download and install the latest version of Netbeans
(3) From within NetBeans, go to Tools -> Plugins. Click on Available Plugins and search for 'Antlr'. Select ANTLRWorks Editor and install it.
(4) Create a new Java project called SimpleCalc.
(5) Add the ANTLR jar file (from step 1) to your Libraries folder. Right-click on the Libraries folder and choose 'Add JAR/Folder...", navigate to the ANTLR jar file, and select Choose.
(6) In your Source Packages folder, create a new package called simplecalc.grammar.
(7) In your simplecalc.grammar package, create a new ANTLR file named SimpleCalc.g4. Right click on simplecalc.grammar and choose New -> Other... Find the ANTLR folder in Categories and choose ANTLR 4 Combined Grammar. Name the file SimpleCalc.g4 and click Finish.
(8) Paste the following into SimpleCalc.g4 (see Programming Language Pragmatics, 3rd ed. by M. Scott).
grammar SimpleCalc;
program : stmt* '$$' ;
stmt : ID ':=' expr # AssignStmt
| 'read' ID # ReadStmt
| 'write' expr # WriteStmt
;
expr : expr ('*' | '/') expr # MulDivExpr
| expr ('+' | '-') expr # AddSubExpr
| '(' expr ')' # ParenExpr
| ID # IdentExpr
| NUMBER # NumberExpr
;
// tokens
READ : 'read' ;
WRITE : 'write' ;
LPAREN : '(' ;
RPAREN : ')' ;
ASSIGN : ':=' ;
ADD : '+' ;
SUB : '-' ;
MUL : '*' ;
DIV : '/' ;
STOP : '$$' ;
ID : [a-z]+ ;
NUMBER : [0-9]+ ;
(9) Highlight the grammar file and select Run -> Generate Recognizer... -> . For Location, choose the default, for Features, choose both Generate listener and Generate visitor, and make sure the package is simplecalc.grammar. Ignore the Advances settings and click Finish.