Skip to content
ANTLR 4 examples in Python
Branch: master
Clone or download
Latest commit 163b381 Mar 30, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
arithmetic remove unnecessary walker Mar 30, 2016
hello-multiple add hello-multiple example, refactor Mar 16, 2016
hello-simple add hello-multiple example, refactor Mar 16, 2016
.gitignore arithmetic example Mar 30, 2016
LICENSE Initial commit Mar 16, 2016
README.md README Mar 30, 2016

README.md

ANTLR4 Python Example

This repository is a simple example of ANTLR4 in Python 2.

Subprojects

  • hello-simple: Simplest example, based on the ANTLR documentation.
  • hello-multiple: Slightly more complicated grammar to handle multiple items of input.
  • arithmetic: Walking the tree directly (not using a listener).

Getting started

First, download the ANTLR complete JAR from the ANTLR site.

Next, install the ANTLR4 Python 2 runtime:

pip install antlr4-python2-runtime

Then, run ANTLR to compile the grammar and generate Python. Finally, run the Python main and enter some text.

For example, in the hello-simple directory:

java -Xmx500M -cp <path to ANTLR complete JAR> org.antlr.v4.Tool -Dlanguage=Python2 Hello.g4
$ python Hello.py
hello sir
^D

Output:

Hello: sir
You can’t perform that action at this time.