ArticleslgStudy

computer science

ANTLR

ANTLR is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand ANTLR rather than just read about it. In short: In computer-based language recognition, ANTLR (pronounced antler), or ANother Tool for Language Recognition, is a parser generator that uses a LL(*) algorithm for parsing. ANTLR is the successor to the Purdue Compiler Construction Tool Set (PCCTS), first developed in 1989, and is under active development.

Key takeaways

  • ANTLR belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect ANTLR to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of ANTLR from memory before moving on to harder problems.

Reference excerpt

In computer-based language recognition, ANTLR (pronounced antler), or ANother Tool for Language Recognition, is a parser generator that uses a LL(*) algorithm for parsing. ANTLR is the successor to the Purdue Compiler Construction Tool Set (PCCTS), first developed in 1989, and is under active development. Its maintainer is Professor Terence Parr of the University of San Francisco. PCCTS 1.00 was announced April 10, 1992.

Usage ANTLR takes as input a grammar that specifies a language and generates as output source code for a recognizer of that language. While Version 3 supported generating code in the programming languages Ada95, ActionScript, C, C#, Java, JavaScript, Objective-C, Perl, Python, Ruby, and Standard ML, Version 4 at present targets C#, C++, Dart, Java, JavaScript, Go, PHP, Python (2 and 3), and Swift. A language is specified using a context-free grammar expressed using Extended Backus–Naur Form (EBNF). ANTLR can generate lexers, parsers, tree parsers, and combined lexer-parsers. Parsers can automatically generate parse trees or abstract syntax trees, which can be further processed with tree parsers. ANTLR provides a single consistent notation for specifying lexers, parsers, and tree parsers. By default, ANTLR reads a grammar and generates a recognizer for the language defined by the grammar (i.e., a program that reads an input stream and generates an error if the input stream does not conform to the syntax specified by the grammar). If there are no syntax errors, the default action is to simply exit without printing any message. In order to do something useful with the language, actions can be attached to grammar elements in the grammar. These actions are written in the programming language in which the recognizer is being generated. When the recognizer is being generated, the actions are embedded in the source code of the recognizer at the appropriate points. Actions can be used to build and check symbol tables and to emit instructions in a target language, in the case of a compiler. Other than lexers and parsers, ANTLR can be used to generate tree parsers. These are recognizers that process abstract syntax trees, which can be automatically generated by parsers. These tree parsers are unique to ANTLR and help processing abstract syntax trees.

Licensing ANTLR 3 and ANTLR 4 are free software, published under a three-clause BSD License. Prior versions were released as public domain software. Documentation, derived from Parr's book The Definitive ANTLR 4 Reference, is included with the BSD-licensed ANTLR 4 source. Various plugins have been developed for the Eclipse development environment to support the ANTLR grammar, including ANTLR Studio, a proprietary product, as well as the "ANTLR 2" and "ANTLR 3" plugins for Eclipse hosted on SourceForge.

ANTLR 4 ANTLR 4 deals with direct left recursion correctly, but not with left recursion in general, i.e., grammar rules x that refer to y that refer to x.

Development As reported on the tools page of the ANTLR project, plug-ins that enable features like syntax highlighting, syntax error checking and code completion are freely available for the most common IDEs (Intellij IDEA, NetBeans, Eclipse, Visual Studio and Visual Studio Code).

Projects Software built using ANTLR includes:

Groovy Jython Hibernate OpenJDK Compiler Grammar project experimental version of the javac compiler based upon a grammar written in ANTLR Apex, Salesforce.com's programming language The expression evaluator in Numbers, Apple's spreadsheet Twitter's search query language Weblogic server Apache Cassandra Processing JabRef Trino (SQL query engine) Presto (SQL query engine) MySQL Workbench Over 200 grammars implemented in ANTLR 4 are available on GitHub. They range from grammars for a URL to grammars for entire languages like C, Java and Go.

Example In the following example, a parser in ANTLR describes the sum of expressions can be seen in the form of "1 + 2 + 3":

The following listing demonstrates the call of the parser in a program:

See also

Coco/R DMS Software Reengineering Toolkit JavaCC Modular Syntax Definition Formalism Parboiled (Java) Parsing expression grammar SableCC

References

Bibliography

Further reading

External links Official website

Worked examples

Example 1 — a first encounter with ANTLR

Start with the simplest possible case. Write down what ANTLR claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to ANTLR before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about ANTLR ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of ANTLR

In research
ANTLR appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses ANTLR in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
ANTLR is common in secondary-school and first-year university syllabi. It links to neighbouring topics 1992 software, Parser generators, Public-domain software, so understanding it makes those chapters shorter.
In everyday life
Look for ANTLR outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “ANTLR” →

How to study ANTLR in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what ANTLR means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain ANTLR out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is ANTLR in simple terms?

In computer-based language recognition, ANTLR (pronounced antler), or ANother Tool for Language Recognition, is a parser generator that uses a LL(*) algorithm for parsing. ANTLR is the successor to the Purdue Compiler Construction Tool Set (PCCTS), first developed in 1989, and is under active devel…

Why does ANTLR matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study ANTLR?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on ANTLR.

Tags

  • 1992 software
  • Parser generators
  • Public-domain software
  • Software using the BSD license

Keep exploring