ANTLR
ANTLR | |
---|---|
Basic data
|
|
developer | Terence Parr |
Current version |
4.8 ( January 16, 2020 ) |
programming language | Java |
License | BSD |
www.antlr.org |
ANTLR (pronounced Antler) is an object-oriented parser generator that has been developed by Terence Parr at the University of San Francisco since 1989 . The abbreviation ANTLR stands for AN other T ool for L anguage R ecognition.
description
ANTLR supports the generation of parsers , lexers and tree parsers for LL (k) grammars with any k. The input language used is a mixture of formal grammar and elements from object-oriented languages (see example below).
The translator itself is a Java application, available as free software and can run on the Java platform . An older version of ANTLR (3.1.x) has also been ported to C # and can therefore run under .NET and Mono .
ANTLR3 supports as target languages u. a. ActionScript , Ada95 , C , C ++ , C # , Java , JavaScript , Objective-C and Python . With the appearance of ANTLR4, all runtime libraries had to be rewritten because the entire parsing logic was relocated to the runtime environment. There are now runtime packages for Java , C # , Python 2/3, JavaScript, Go , C ++, Swift and PHP . Other languages such as Kotlin and Rust are in planning / work.
The runtime environment provides all classes and functions that are required to compile the generated parser and lexer files. With ANTLR3 abstract syntax trees can be created automatically during the parsing process (together with a corresponding TreeParser). This changed with ANTLR4, where a parse tree (syntax tree) is generated instead of the AST . Instead of a tree parser, listener + visitor classes are now produced, which allow the parse tree to be traversed in a variety of ways.
example
The following example describes a parser in ANTLR3 that can recognize sum expressions in the form "1 + 2 + 3":
// allgemeine Optionen, zum Beispiel die Zielsprache
options
{
language = "CSharp";
}
// es folgt der Parser
class SumParser extends Parser;
options
{
k = 1; ''// Parser-[[Lookahead]]: 1 [[Token (Compilerbau)|Token]]''
}
// Definition eines Ausdrucks
statement : INTEGER (PLUS^ INTEGER)*;
// hier der Lexer
class SumLexer extends Lexer;
options
{
k = 1; ''// Lexer-[[Lookahead]]: 1 Zeichen''
}
PLUS : '+';
DIGIT : ('0'..'9');
INTEGER : (DIGIT)+;
The following listing demonstrates calling the parser in a program:
TextReader reader;
// (...) Textreader mit Zeichen füllen
SumLexer lexer = new SumLexer(reader);
SumParser parser = new SumParser(lexer);
parser.expression();
See also
literature
- Terence Parr: The Definitive ANTLR Reference Guide: Building Domain-Specific Languages . 1st edition. The Pragmatic Programmers, 2007, ISBN 978-0-9787392-5-6 (English).
- Terence Parr: The Definitive ANTLR 4 Reference . The Pragmatic Programmers, 2013, ISBN 978-1-934356-99-9 (English).
Web links
- www.antlr.org
- supportweb.cs.bham.ac.uk - short tutorial in ANTLRv2 (Java as target language)
- antlreclipse.sourceforge.net - Eclipse plugin for ANTLR ( free software )
- placidsystems.com - ANTLR and Eclipse
Individual evidence
- ↑ Release 4.8 . January 16, 2020 (accessed January 16, 2020).
- ^ Terence Parr: The Definitive ANTLR Reference . Building Domain-Specific Languages. The Pragmatic Bookshelf, 2007, ISBN 0-9787392-5-6 , Preface, pp. 15 (American English).
- ↑ ANTLR v3 documentation - Code Generation Targets
- ↑ Download ANTLR. Accessed January 30, 2020 .
- ↑ antlr / antlr4. Accessed January 30, 2020 (English).
- ↑ antlr / antlr4. Accessed January 30, 2020 (English).