ANTLR4 Grammar for NASA PDS version 3 Labels
Python ANTLR Shell Makefile
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

ANTLR4 PDSv3 Grammar

This is an ANTLR v4 grammar for the NASA PDSv3 ODL v2.1 label.

This grammar is defined in Chapter 12 of the PDS Standards Reference.

It is BDS licensed, see the following LICENSE file for details:

Visit the Github repo:

Known Bugs


The supporting scripts assume you have ANTLR 4.4 installed at the following location:


You must also have make installed and java. I am using the JDK that comes with Ubuntu 14.04:

java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (7u71-2.5.3-0ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)


To build both the python and java parsers do the following:

cd antlr_grammar

You will find a build-java and build-python directory containing the ANTLR generated output. See the Makefile for details.


This project includes a simple script that will loop over all *.lbl files in the data/ directory, excluding files with invalid in the name. It will run the TestRig diagnostics function. If there are no lexing or parsing errors, this will generate no output. Only errors will generate output. See more in the Developing section.

Note that this is just a simple 'smoke test', it only indicates whether or not the sample inputs lex and parse cleanly. It does not guarantee that the parse trees or tokens are what they should be. More rigorous testing could use the tokenrun and treerun functions. I will probably be doing my testing at a higher level, at the python parser level, where better testing tools are available.


At this point, I consider the generated Python code to be the release product. However, these are not stored in the repo since they are entirely generated products.

# Finish work and commit changes
# Update VERSION.txt
# Generates python code and makes the release tarball
make release
# Tag repo with version
git tag `cat VERSION.txt`
# Push repo and tags
git push --tags
# Manually upload tarball to github.


The general development workflow is

  • Setup with cd antlr_grammar/; source
  • modify and save ODLv21.g4
  • run make
  • examine sample input of input: `guirun data/dates.lbl
  • run the test script: ./

added a few things to make development easier. First off, one should source the file. It will define the following helper functions and aliases:

  • grun - Runs the ANTLR TestRig
  • TestRig commands
    • diagrun - Shows diagnostic output from lexer and parser if any
    • guirun - Shows GUI parse tree browser
    • psrun - Generates a PS of the parsetree
    • tokenrun - Shows tokens detected by lexer
    • treerun - Prints text tree output of parse tree
    • tracerun - Shows trace information when parsing input file

All of the TestRig commands above are run by specifying a sample data file, usually from within the data/ directory. Of course they assume you have already run the make file and have a build-java directory.

Running the following:

guirun data/dates.lbl

will yield:

Dates Parse Tree