Skip to content

Latest commit

 

History

History
76 lines (50 loc) · 1.08 KB

README.md

File metadata and controls

76 lines (50 loc) · 1.08 KB

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