0

How to create Antlr tree Parser Diagram through CMD Line?

Currently i have some grammar content which am trying to parse as Tree in Antlr.

Currently am executing this grammar file thriugh CMD line

C:\Users\mohan\ANTLR>java -jar antlr4-4.1-complete.jar grammar.g4
Mohan Raj
  • 447
  • 1
  • 5
  • 18

2 Answers2

0

After creating the Lexer and Parser java files i recommand to use the ANTLR testing tool taht provided in the ANTLR jar org.antlr.v4.gui.TestRig

java -cp .;D:\Work\lib\antlr-4.5.3-complete.jar org.antlr.v4.gui.TestRig <GrammarName> <startRuleName> -gui [input-filename]

should do the trick.

you can read more about this in The Definitive ANTLR 4 Reference its have more details on how to use it.

pesonaly i prefer using notepad++ ANTLR plugin to test my grammar its basicly does the same thing except its more comfterble for me not to always go back to the Command Prompt after every change in my grammar. here is a link to the notepad++ plugin and how to install it :notepad++ antlr pigin

Tal Malul
  • 1
  • 2
0

After writing my grammar file for my corresponding code block, i have compiled and executed as follows

set path=%path%;C:\Program Files\Java\jdk1.8.0_92\bin

set path=%path%;C:\Users\Mohan\ANTLR\antlr-4.5.3-complete.jar

java -jar antlr-4.5.3-complete.jar Grammar.G4

javac -cp .;antlr-4.5.3-complete.jar Grammar*.java

java -cp .;antlr-4.5.3-complete.jar org.antlr.v4.gui.TestRig Grammar prog -gui

 C:\Users\Mohan\ANTLR> java -cp .;antlr-4.5.3-complete.jar org.antlr.v4.gui.TestRig Grammar prog -gui

After Compiling all commands in Command prompt give Ctrl + Z if you are using Windows and Ctrl + D if you are using **nix, to generate parser diagram.

Mohan Raj
  • 447
  • 1
  • 5
  • 18