antlr
TLDR
Generate parser from a grammar file (default: Java)
SYNOPSIS
antlr4 [options] grammar-file...
DESCRIPTION
ANTLR (ANother Tool for Language Recognition) is a parser generator that creates lexers, parsers, and tree walkers from grammar files. It generates code that can read, process, and translate structured text or binary data.
ANTLR grammars use an extended BNF notation with semantic actions. The tool processes .g4 grammar files and generates source code for the target language. Generated parsers build parse trees that can be traversed using listener or visitor patterns.
The grammar defines both lexical rules (tokens) and parser rules. ANTLR handles left-recursive rules automatically and supports features like semantic predicates, actions, and grammar imports. The generated parser uses an adaptive LL(*) parsing algorithm called ALL(*).
Common workflow: write a grammar file, run antlr4 to generate code, compile the generated code with your application, and use the parser to process input text.
PARAMETERS
-o directory
Output directory for generated files (default: current directory)-lib directory
Location to search for imported grammars and token files-Dlanguage=lang
Target language: Java, Python3, CSharp, JavaScript, Go, Cpp, Swift-package name
Package or namespace for generated code-listener
Generate parse tree listener classes (default)-no-listener
Do not generate parse tree listener-visitor
Generate parse tree visitor classes-no-visitor
Do not generate parse tree visitor (default)-encoding name
Grammar file encoding (default: UTF-8)-atn
Generate DOT graph files for ATN visualization-depend
Generate file dependency information-message-format format
Output message format: antlr, gnu, vs2005-long-messages
Show detailed exception information for errors-Werror
Treat warnings as errors-Xlog
Create detailed log file (antlr-timestamp.log)
CAVEATS
Requires Java Runtime Environment to execute. The antlr4 command is typically an alias or wrapper script; the actual tool runs as a Java JAR file. Generated code requires the ANTLR runtime library for the target language. Large or ambiguous grammars may result in slow parsers.
HISTORY
ANTLR was created by Terence Parr at the University of San Francisco starting in 1989. ANTLR4, released in 2013, introduced the ALL(*) parsing algorithm that handles more grammar constructs than previous LL(k) versions. The tool is widely used for building languages, data formats, and domain-specific languages in both academic and commercial settings.


