Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ANTLR
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Parser generator program}} {{more citations needed|date=March 2016}} {{Infobox software | name = ANTLR | logo = | screenshot = | caption = | author = [[Terence Parr]] and others | developer = | released = {{Start date and age|1992|04|10}} | latest release version = 4.13.2 | latest release date = {{Start date and age|2024|08|03|df=yes}} | programming language = [[Java (programming language)|Java]] | operating system = | platform = [[Cross-platform]] | language = | genre = | license = [[BSD License]] | website = {{URL|www.antlr.org}} }} In computer-based language recognition, '''ANTLR''' (pronounced ''[[antler]]''), or '''ANother Tool for Language Recognition''', is a [[parser generator]] that uses a [[LL parser|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]].{{citation needed|date=March 2016}} PCCTS 1.00 was announced April 10, 1992.<ref>{{Cite web |date=10 Apr 1992 |title=Comp.compilers: Purdue Compiler-Construction Tool Set 1.00 available |url=https://compilers.iecc.com/comparch/article/92-04-048 |access-date=2023-05-05 |website=compilers.iecc.com}}</ref><ref>{{Cite web |date=30 Apr 1992 |title=Comp.compilers: More on PCCTS |url=https://compilers.iecc.com/comparch/article/92-05-006 |access-date=2023-05-05 |website=compilers.iecc.com}}</ref> ==Usage== ANTLR takes as input a [[formal grammar|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 language]]s [[Ada95]], [[ActionScript]], [[C (programming language)|C]], [[C Sharp (programming language)|C#]], [[Java (programming language)|Java]], [[JavaScript]], [[Objective-C]], [[Perl]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], and [[Standard ML]],<ref>[http://www.classes.cs.uchicago.edu/archive/2007/winter/22610-1/docs/lpt-manual.pdf SML/NJ Language Processing Tools: User Guide]</ref> Version 4 at present targets C#, C++, [[Dart (programming language)|Dart]],<ref name="github">{{cite web |title=Runtime Libraries and Code Generation Targets |url=https://github.com/antlr/antlr4/blob/master/doc/targets.md |website=github|date=6 January 2022 }}</ref><ref>{{Cite web | url=https://soft-gems.net/the-antlr4-c-runtime-reached-home | title=The ANTLR4 C++ runtime reached home – Soft Gems | date=16 November 2016 }}</ref> Java, JavaScript, [[Go (programming language)|Go]], [[PHP]], Python (2 and 3), and [[Swift (programming language)|Swift]]. A language is specified using a [[context-free grammar]] expressed using [[Extended Backus–Naur Form]] (EBNF).{{citation needed|date=March 2016}}<ref name=":0">{{Cite book|last=Parr|first=Terence|url=https://books.google.com/books?id=gA9QDwAAQBAJ|title=The Definitive ANTLR 4 Reference|date=2013-01-15|publisher=Pragmatic Bookshelf|isbn=978-1-68050-500-9|language=en}}</ref> ANTLR can generate [[lexical analysis|lexer]]s, [[parser]]s, [[Parse tree|tree parsers]], and combined [[Lexical analysis|lexer-parsers]]. Parsers can automatically generate [[parse tree]]s or [[abstract syntax tree]]s, 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.{{citation needed|date=March 2016}}<ref name=":0" /> 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.{{citation needed|date=March 2016}}<ref name=":0" /> ==Licensing== {{citation needed span|date=September 2017|text=ANTLR 3}} and ANTLR 4 are [[free software]], published under a three-clause [[BSD License]].<ref name=antlr4-license>{{cite web |date=2017-03-30 |title=antlr4/LICENSE.txt |website=GitHub |url=https://github.com/antlr/antlr4/blob/master/LICENSE.txt }}</ref> Prior versions were released as [[public domain software]].<ref>{{cite mailing list|url=http://www.antlr.org/pipermail/antlr-interest/2004-February/006340.html |title=licensing stuff |date=2004-02-05 |accessdate=2009-12-15 |mailing-list=antlr-interest |last=Parr |first=Terence |url-status=dead |archiveurl=https://web.archive.org/web/20110718165021/http://www.antlr.org/pipermail/antlr-interest/2004-February/006340.html |archivedate=2011-07-18 }}</ref> Documentation, derived from Parr's book ''The Definitive ANTLR 4 Reference'', is included with the BSD-licensed ANTLR 4 source.<ref name=antlr4-license/><ref>{{cite web |date=2017-03-30 |title=ANTLR 4 Documentation |website=GitHub |url=https://github.com/antlr/antlr4/blob/master/doc/index.md }}</ref> Various plugins have been developed for the [[Eclipse IDE|Eclipse development environment]] to support the ANTLR grammar, including [[ANTLR Studio]], a [[Proprietary software|proprietary product]], as well as the "ANTLR 2"<ref>{{cite web |url=http://antlreclipse.sourceforge.net |title = ANTLR plugin for Eclipse}}</ref> and "ANTLR 3"<ref>{{cite web |url=http://antlrv3ide.sourceforge.net |title = ANTLR IDE. An eclipse plugin for ANTLR grammars}}</ref> plugins for Eclipse hosted on [[SourceForge]].{{citation needed|date=March 2016}} == 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''.<ref>[https://github.com/antlr/antlr4/blob/master/doc/faq/general.md#what-is-the-difference-between-antlr-3-and-4 What is the difference between ANTLR 3 & 4]</ref> === Development === As reported on the tools<ref>{{Cite web|url=http://www.antlr.org/tools.html|title = ANTLR Development Tools}}</ref> 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 (software)|Eclipse]], [[Visual Studio]]<ref>{{Cite web|url=https://marketplace.visualstudio.com/items?itemName=SamHarwell.ANTLRLanguageSupport|title = ANTLR Language Support - Visual Studio Marketplace}}</ref> and [[Visual Studio Code]]). == Projects == Software built using ANTLR includes: * [[Groovy (programming language)|Groovy]]<ref>{{Cite web|url=http://docs.groovy-lang.org/2.4.0/html/api/org/codehaus/groovy/antlr/parser/GroovyRecognizer.html|title = GroovyRecognizer (Groovy 2.4.0)}}</ref> * [[Jython]]<ref>{{Cite web|url=https://hg.python.org/jython/rev/31d97f0de5fe|title=Jython: 31d97f0de5fe}}</ref> * [[Hibernate (java)|Hibernate]]<ref>{{cite web |last1=Ebersole |first1=Steve |title=Hibernate ORM 6.0.0.Alpha1 released |url=https://in.relation.to/2018/12/06/hibernate-orm-600-alpha1-out/ |website=In Relation To, The Hibernate team blog on everything data |access-date=2020-07-11 |date=2018-12-06}}</ref> * OpenJDK Compiler Grammar project experimental version of the [[javac]] compiler based upon a grammar written in ANTLR<ref>{{Cite web|url=https://openjdk.java.net/projects/compiler-grammar/|title=OpenJDK: Compiler Grammar}}</ref> * [[Salesforce.com#Apex|Apex]], [[Salesforce.com]]'s programming language{{citation needed|date=October 2017}} * The expression evaluator in [[Numbers (spreadsheet)|Numbers]], Apple's spreadsheet{{citation needed|date=October 2017}} * [[Twitter]]'s search query language<ref>{{cite web | url = https://www.antlr.org/testimonials.html | title = ANTLR Testimonials | accessdate = 2024-10-30}} </ref> * Weblogic server{{citation needed|date=October 2017}} * [[Apache Cassandra]]{{citation needed|date=October 2017}} * [[Processing (programming language)|Processing]]{{citation needed|date=October 2017}} * [[JabRef]]{{citation needed|date=October 2017}} * [[Trino (SQL query engine)]] * [[Presto (SQL query engine)]] * [[MySQL Workbench]] Over 200 grammars implemented in ANTLR 4 are available on [[GitHub]].<ref>{{Citation|title=Grammars written for ANTLR v4; expectation that the grammars are free of actions.: antlr/grammars-v4|date=2019-09-25|url=https://github.com/antlr/grammars-v4|publisher=Antlr Project|access-date=2019-09-25}}</ref> 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": <syntaxhighlight lang="antlr"> // Common options, for example, the target language options { language = "CSharp"; } // Followed by the parser class SumParser extends Parser; options { k = 1; // Parser Lookahead: 1 Token } // Definition of an expression statement: INTEGER (PLUS^ INTEGER)*; // Here is the Lexer class SumLexer extends Lexer; options { k = 1; // Lexer Lookahead: 1 characters } PLUS: '+'; DIGIT: ('0'..'9'); INTEGER: (DIGIT)+; </syntaxhighlight> The following listing demonstrates the call of the parser in a program: <syntaxhighlight lang="java"> TextReader reader; // (...) Fill TextReader with character SumLexer lexer = new SumLexer(reader); SumParser parser = new SumParser(lexer); parser.statement(); </syntaxhighlight> == See also == {{Portal|Free and open-source software}} * [[Coco/R]] * [[DMS Software Reengineering Toolkit]] * [[JavaCC]] * [[Modular Syntax Definition Formalism]] * [[Parboiled (Java)]] * [[Parsing expression grammar]] * [[SableCC]] == References == {{reflist|30em}} == Bibliography == {{Refbegin}} * {{citation | first1=Terence |last1=Parr |date=May 17, 2007 | title=The Definitive Antlr Reference: Building Domain-Specific Languages |edition=1st | publisher=[[Pragmatic Bookshelf]] |pages=376 |isbn=978-0-9787392-5-6 | url=http://www.pragprog.com/titles/tpantlr/the-definitive-antlr-reference }} * {{citation | first1=Terence |last1=Parr |date=December 2009 | title=Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages | edition=1st |publisher=[[Pragmatic Bookshelf]] |pages=374 |isbn=978-1-934356-45-6 | url=http://www.pragprog.com/titles/tpdsl/language-implementation-patterns }} * {{citation | first1=Terence |last1=Parr |date= January 15, 2013 | title=The Definitive ANTLR 4 Reference |edition=1st | publisher=[[Pragmatic Bookshelf]] |pages=328 |isbn=978-1-93435-699-9 | url=http://pragprog.com/book/tpantlr2/the-definitive-antlr-4-reference }} {{Refend}} ==Further reading== {{refbegin}} * {{cite journal |first1=T.J. |last1=Parr |first2=R.W. |last2=Quong |title=ANTLR: A Predicated-LL(k) Parser Generator |journal=Software: Practice and Experience |volume=25 |issue=7 |pages=789–810 |date=July 1995 |doi=10.1002/spe.4380250705 |citeseerx=10.1.1.54.6015 |s2cid=13453016 }} {{refend}} == External links == <!-- Per [[WP:ELMINOFFICIAL]], choose one official website only --> * {{official website|www.antlr.org}} * [https://tomassetti.me/antlr-mega-tutorial/ ANTLR (mega) Tutorial] * [http://www.bearcave.com/software/antlr/antlr_expr.html Why Use ANTLR?] *[http://www.placidsystems.com/antlrstudio.aspx ANTLR Studio] [[Category:1992 software]] [[Category:Parser generators]] [[Category:Software using the BSD license]] [[Category:Public-domain software]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation
(
edit
)
Template:Citation needed
(
edit
)
Template:Citation needed span
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite mailing list
(
edit
)
Template:Cite web
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Main other
(
edit
)
Template:More citations needed
(
edit
)
Template:Official website
(
edit
)
Template:Portal
(
edit
)
Template:Refbegin
(
edit
)
Template:Refend
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Template other
(
edit
)