antlr - vvoovv/notes GitHub Wiki
Installation
- Install Java Development Kit (JDK)
- Download the latest complete ANTLR 4.7.1 Java binaries jar.
- Download ANTLR Python 3 runtime from pypi.python.org
- Download ANTLR Javascriprt runtime from here.
bat files
Place the following bat files in the same directory where antlr-4.7.1-complete.jar is located.
antlr4.bat java -classpath C:\software\antlr\antlr-4.7.1-complete.jar org.antlr.v4.Tool %*
grun.bat java -classpath C:\software\antlr\antlr-4.7.1-complete.jar;%CD% org.antlr.v4.gui.TestRig %*
javac.bat "C:\Program Files\Java\jdk-10\bin\javac.exe" -classpath C:\software\antlr\antlr-4.7.1-complete.jar %*
Chat tutorial by Federico Tomassetti
The tutorial can be found at tomassetti.me. The source code can be found at the companion github repository.
cd
to the directory where Chat.g4 is located (C:\software\antlr\tutorial)C:\software\antlr\antlr4 Chat.g4
C:\software\antlr\javac Chat*.java
Test the result. grun is the testing tool, Chat is the name of the grammar, chat is the rule that we want to parse
C:\software\antlr\grun Chat chat
- Start entering input strings, e.g.
john SAYS: hello @michael this will not work
- Press
Ctrl Z
to parse the input
To get the recognized tokens, execute:
C:\software\antlr\grun Chat chat -tokens
To get graphical representation of the the recognized tokens, execute:
C:\software\antlr\grun Chat chat -gui
Javascript example
Install Javascript runtime in the directory where Chat.g4 is located:
C:\software\node\npm install antlr4
cd
to the directory where Chat.g4 is located (C:\software\antlr\tutorial)C:\software\antlr\antlr4 -Dlanguage=JavaScript Chat.g4
Using nodejs webserver:
cd
to the directory where Chat.g4 is located (C:\software\antlr\tutorial)C:\software\node\node.exe antlr.js
- Open http://localhost:1337 in a webbrowser
Python example
cd
to the directory where Chat.g4 is located (C:\software\antlr\tutorial)C:\software\antlr\antlr4 -Dlanguage=Python3 Chat.g4