Setting up ANTLR4 on Windows
I am using ANTLR for a Compilers course, and working on a windows box. Getting ANTLR to work is not difficult since it is just a Java jar file. The quick start instructions on the ANTLR website seem really straightforward, and they probably are if you know what you are doing. However, I had a bit of trouble getting the handy antlr4 and gruncommands to work properly in my environment. This is likely due to my Unix/Linux background and because I am not used to messing with environment variables and batch files on windows. Adding things to the PATH and creating bash aliases in Linux is a piece of cake. This is a bit trickier on Windows so I figured I would make a short tutorial to help anyone else who does not know what they are doing like me.
Download Antlr
You can get the latest ANTLR from here. Save this file toC:\Javalib
Add ANTLR to the CLASSPATH
CLASSPATH is an environmental variable. In order to set an environmental variable in Windows you will need to do the following.- Open Up File Explorer
- Right Click on This PC
- Select Properties
- On the left hand side of the new window select Advanced system settings
- On the bottom of this screen select Environment Variables…
- This is a new computer with no CLASSPATH variable so I had to add a new one. If you have used other Java Libraries it is possible that you may already have CLASSPATH defined. If you see CLASSPATH under System Variables append it with
C:\Javalib\antlr-4.5.3-complete.jar;If you do not have a CLASSPATH variable defined, select **New…* and then enterCLASSPATHfor the Variable Name, andC:\Javalib\antlr-4.5.3-complete.jarfor the Variable value.
Create batch commands for ANTLR Tool and TestRig
In order to make ANTLR easier to run from the command line we will need to add two simple batch files somewhere in the PATH. I decided to put these in C:\Javalib in order to keep them organized and together. C:\Javalib is not in the PATH by default so we must append the existing PATH variable just like we did in the previous step.- Open Up File Explorer
- Right Click on This PC
- Select Properties
- On the left hand side of the new window select Advanced system settings
- On the bottom of this screen select Environment Variables…
- Find the PATH variable
- Append
;C:\Javalib\;to the existing PATH variable
- Create a new file in
C:\Javalibcalledantlr4.bat - In this file enter
java org.antlr.v4.Tool %* - Save this file
- Create a new file in
C:\Javalibcalledgrun.bat - In this file enter
java org.antlr.v4.runtime.misc.TestRig %* - Save this file
antrl4 and grun into a command prompt and launch ANTLR or the Testing Suite respectively.
Make Sure Everything Works
To make sure that all of this worked;- Open up a Command Prompt or Powershell
- Enter the command
antlr4 - You should see something like this:
Output of antlr4 command[/caption]
- Enter the command
grun - You should see somethign like this:
Output of grun command[/caption]
Congrats, you are ready to hack on compilers now. Next, check out The Definitive ANTLR Reference book to learn everything there is to know about ANTLR.
Thank you for reading! Share your thoughts with me on bluesky, mastodon, or via email.
Check out some more stuff to read down below.
Most popular posts this month
- Great Lakes, Illinois
- My Custom Miniflux CSS Theme
- Setting up ANTLR4 on Windows
- Are we inside a Sarlacc?
- Vagrant Box for ROS2 on Apple Silicon
Recent Favorite Blog Posts
This is a collection of the last 8 posts that I bookmarked.
- Grow, Like a Tree Not a Cancer from Jim Nielsen’s Blog
- Pluralistic: All the books I reviewed in 2025 (02 Dec 2025) from Pluralistic: Daily links from Cory Doctorow
- DEP-18: A proposal for Git-based collaboration in Debian from Optimized by Otto
- [RIDGELINE] No Phones in The Ten-don Shop from Craig Mod — Writer + Photographer
- My next chapter with Mastodon from Mastodon Blog
- How many pillars of observability can you fit on the head of a pin? from charity.wtf
- The Software Essays that Shaped Me from Refactoring English
- Give Your Spouse the Gift of a Couple's Email Domain from mtlynch.io
Articles from blogs I follow around the net
GPT-5.2
OpenAI reportedly declared a "code red" on the 1st of December in response to increasingly credible competition from the likes of Google's Gemini 3. It's less than two weeks later and they just announced GPT-5.2, calling it "the most c…
via Simon Willison's Weblog: Entries December 11, 2025Marc was Invited to the “Wake Up Excited” Podcast by Brad Frost
A big part of our chat circled around authenticity and self-worth. A few questions we touched were: How easy is it to overlook your own achievements? How strange does it feel to work alone so much? How often do we […]
via Blog – Brad Frost December 11, 2025Reflections on my first year writing full time
The best essays Johanna and I wrote in 2025, and some reflections on what it was like to write them.
via Escaping Flatland December 11, 2025Generated by openring