Skip to content

AlanHohn/antlr4-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

ANTLR 4 examples in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published