explaingit

antlr/grammars-v4

11,001ANTLRAudience · developerComplexity · 3/5Setup · moderate

TLDR

A large open collection of ANTLR v4 grammar files covering dozens of programming languages and file formats, so you can generate a working parser without writing grammar rules from scratch.

Mindmap

mindmap
  root((grammars-v4))
    What it does
      Grammar collection
      Parser generation
      Language support
    Coverage
      Programming languages
      SQL dialects
      Config formats
    How to use
      Pick grammar file
      Run ANTLR tool
      Generate parser
    Tech stack
      ANTLR v4
      Java Python C#
      Multiple targets
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Generate a Java or Python parser for SQL, C++, or another listed language using an existing grammar file.

USE CASE 2

Build a code analysis or transformation tool without writing your own grammar rules from scratch.

USE CASE 3

Add syntax validation for a configuration file format by adapting an existing grammar as a starting point.

Tech stack

ANTLRJavaPythonC#

Getting it running

Difficulty · moderate Time to first run · 30min

Requires installing ANTLR v4 and a JVM to generate parsers from the grammar files.

In plain English

This repository is a large collection of grammar files written for ANTLR v4. ANTLR is a tool that reads formal grammar descriptions and generates code capable of parsing text written in that language. A grammar file describes the rules of a language: what tokens are valid, how statements are structured, and how different constructs nest inside each other. Once you have a grammar, ANTLR can produce a parser in Java, Python, C#, or several other target languages. The grammars in this collection cover a wide range of programming languages and file formats: Java, C, C++, C#, Python, SQL dialects, configuration formats, and many others. Each grammar lives in its own directory named after the language it describes, all in lowercase. The stated goal is that the grammars contain no embedded actions, meaning they are pure structural descriptions without language-specific code mixed in. This makes them easier to reuse across different ANTLR target languages. This collection is maintained under the ANTLR organization on GitHub, which is the same group behind the ANTLR parser generator itself. If you are building a tool that needs to read or analyze source code in an existing language, starting from one of these grammars saves considerable time compared to writing the grammar rules from scratch. Contributors can add new grammars or improve existing ones following the project's house rules. The README itself is minimal and points to a project Wiki for frequently asked questions and contribution guidelines. Beyond the directory structure and a continuous integration badge, the repository speaks through its grammar files rather than detailed documentation.

Copy-paste prompts

Prompt 1
Show me how to take the Python3 grammar from grammars-v4 and use ANTLR to generate a Java parser that counts all function definitions in a source file.
Prompt 2
How do I run the ANTLR tool on a grammar file from grammars-v4 to produce a C# parser for SQL?
Prompt 3
I want to parse MySQL queries in a Python application. Which grammar file should I use from grammars-v4 and what ANTLR command generates the parser?
Prompt 4
How do I contribute a new grammar to grammars-v4 and what are the rules about embedded actions in grammar files?
Prompt 5
Show me how to write an ANTLR listener in Python that uses the Java grammar from grammars-v4 to extract all class names from a source file.
Open on GitHub → Explain another repo

← antlr on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.