请输入您要查询的百科知识:

 

词条 ANTLR
释义

  1. Usage

  2. Licensing

  3. ANTLR 4

      Development    ANTLR Studio  

  4. Projects

  5. Example

  6. See also

  7. References

  8. Bibliography

  9. Further reading

  10. External links

{{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|02}}
| latest release version = 4.7
| latest release date = {{Start date and age|2017|03|30|df=yes}}
| status = Active
| 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 LL(*) 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}}

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,[1] the current release at present only targets Java, C#, C++,[2] JavaScript, Python2, Python3, Swift, and Go. A language is specified using a context-free grammar which is expressed using Extended Backus–Naur Form (EBNF).{{citation needed|date=March 2016}}

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.{{citation needed|date=March 2016}}

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}}

Licensing

{{citation needed span|date=September 2017|text=ANTLR 3}} and ANTLR 4 are free software, published under a three-clause BSD License.[3] Prior versions were released as public domain software.[4] Documentation, derived from Parr's book The Definitive ANTLR 4 Reference, is included with the BSD-licensed ANTLR 4 source.[3][5]

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"[6] and "ANTLR 3"[7] plugins for Eclipse hosted on SourceForge.{{citation needed|date=March 2016}}

ANTLR 4

ANTLR 4 deals with left recursion correctly (except for indirect left recursion, i.e., grammars rules x which refer to y which refer to x)[8] and supports actions and attributes flexibly. That is, actions can be defined separately from the grammar, allowing for easier targeting of multiple languages.{{citation needed|date=March 2016}}

Development

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

ANTLR Studio

ANTLR Studio is an IDE ANTLR. It plugs into the Eclipse development environment. It contains features for syntax highlighting, debugging of grammars, etc. ANTLR Studio is published under a proprietary license. User and team licenses are available. There is also a 20-days evaluation license that can be downloaded directly from the web page.

Projects

Here is a non-comprehensive list of software built using ANTLR:

  • Groovy.[10]
  • Jython.{{citation needed|date=October 2017}}
  • Hibernate.{{citation needed|date=October 2017}}
  • OpenJDK Compiler Grammar project experimental version of the javac compiler based upon a grammar written in ANTLR.{{citation needed|date=October 2017}}
  • Apex, Salesforce.com's programming language.{{citation needed|date=October 2017}}
  • The expression evaluator in Numbers, Apple's spreadsheet.{{citation needed|date=October 2017}}
  • Twitter's search query language.{{citation needed|date=October 2017}}
  • Weblogic server.{{citation needed|date=October 2017}}
  • Apache Cassandra.{{citation needed|date=October 2017}}
  • Processing.{{citation needed|date=October 2017}}
  • JabRef.{{citation needed|date=October 2017}}
  • Presto (SQL query engine)

Example

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

 // 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)+;

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

 TextReader reader; // (...) Fill TextReader with character SumLexer lexer = new SumLexer(reader); SumParser parser = new SumParser(lexer);

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

1. ^SML/NJ Language Processing Tools: User Guide
2. ^http://www.soft-gems.net/index.php/tools/49-the-antlr4-c-target-is-here
3. ^{{cite web |date=2017-03-30 |title=antlr4/LICENSE.txt |website=GitHub |url=https://github.com/antlr/antlr4/blob/master/LICENSE.txt }}
4. ^{{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 |deadurl=yes |archiveurl=https://web.archive.org/web/20110718165021/http://www.antlr.org/pipermail/antlr-interest/2004-February/006340.html |archivedate=2011-07-18 |df= }}
5. ^{{cite web |date=2017-03-30 |title=ANTLR 4 Documentation |website=GitHub |url=https://github.com/antlr/antlr4/blob/master/doc/index.md }}
6. ^http://antlreclipse.sourceforge.net
7. ^http://antlrv3ide.sourceforge.net
8. ^[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]
9. ^http://www.antlr.org/tools.html
10. ^http://docs.groovy-lang.org/2.4.0/html/api/org/codehaus/groovy/antlr/parser/GroovyRecognizer.html

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 }}
{{refend}}

External links

  • {{official website|www.antlr.org}}
  • [https://tomassetti.me/antlr-mega-tutorial/ ANTLR (mega) Tutorial]
  • Why Use ANTLR?
  • ANTLR Studio
{{DEFAULTSORT:Antlr}}

6 : 1992 software|Free compilers and interpreters|Parser generators|Software using the BSD license|Public-domain software|Language workbench

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/17 15:20:34