ANTLR

ANTLR is an object-oriented parser generator that is being developed at the University of San Francisco since 1989 by Terence Parr. The abbreviation stands for ANTLR Another Tool for Language Recognition.

Description

ANTLR supports the generation of parsers, Lexern and TreeParsern for LL (k ) grammars with arbitrary k The input language used is a mixture of formal grammar and elements of object-oriented languages ​​( see example below ).

The translator itself is a Java application available as free software and runs on the Java platform. An older version of ANTLR ( 3.1.x ) has also been ported to C # and is thus under. NET and Mono to run.

The target languages ​​, inter alia, ActionScript, Ada95, C, C , C #, Java, JavaScript, Objective- C and Python are supported. The output from ANTLR code files require functionality that can be made ​​available in a parser library ( eg antlr.runtime.dll ). This abstract syntax trees and corresponding TreeParser can be created automatically.

Example

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

/ / General options, such as 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 the Lexer class SumLexer extends Lexer; options {    k = 1; / / Lexer lookahead: 1 character } PLUS: ' '; DIGIT: ('0 '.. '9 '); INTEGER: (DIGIT ) ; The following listing demonstrates the invocation of the parser in a program:

TextReader reader; / / (...) Fill text reader with characters SumLexer lexer = new SumLexer ( reader ); SumParser parser = new SumParser ( lexer ); parser.expression (); literature

  • Terence Parr: The Definitive ANTLR Reference Guide: Building Domain - Specific Languages ​​. 1st edition. Pragmatic Programmers, 2007 ISBN 0978739256th
69556
de