Skip to content

ANTLR4 Notes based on "The Definitive ANTLR4 Reference" Book.

License

Notifications You must be signed in to change notification settings

divshekhar/antlr4.g4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ANTLR4.G4

ANTLR4 Notes based on "The Definitive ANTLR4 Reference" Book.

Local Setup

Download ANTLR.jar and put it in the lib folder.

Create antlr.bat file and put the following code.

java -cp .;.\lib\antlr4.jar org.antlr.v4.Tool %*

Create grun.bat file and put the following code.

java -cp .\lib\antlr4.jar org.antlr.v4.gui.TestRig %*

Global Setup

Follow steps on how to install antlr4.

Generate Lexer & Parser

> antlr <FileName>.g4 -o out/

Compile

> javac .\out\*.java

GRUN

Tokens

> cd out
> grun <GrammarName> <Rule> -tokens ../<FileName>.txt

Example for Hello:

> grun Hello r -tokens ../Hello.txt

Tree

> cd out
> grun <GrammarName> <Rule> -tree ../<FileName>.txt

Example for Hello:

> grun Hello r -tree ../Hello.txt

GUI

> cd out
> grun <GrammarName> <Rule> -gui ../<FileName>.txt

Example for Hello:

> grun Hello r -gui ../Hello.txt