Antlr

> Antlr

1 - About

ANTLR is lexer generator. It translates the grammar to a parser/lexer

ANTLR is implemented in Java and generates lexer and parser in the following languages:

  • Java,
  • Ruby,
  • Python,
  • C,
  • C++,
  • C#
  • Javascript
  • and Objective C.

It grew from the old C/C++ PCCTS project. Java is then a “recent” addition in the ANTLR's lifetime.

A GUI by the name ANTLRWorks helps you generate the grammar and its corresponding lexer+parser code. ANTLR is licensed under BSD.

Advertising

3 - Use cases

There are three use cases:

  • “validators.” to validate an input. Grammars for validators don't use actions or rewrite rules.
  • “processors.” to validate an input and process it. Grammars for processors use actions, but not rewrite rules.
  • “translators.” to validate and translate the input data structure into another data structure. Grammars for translators use actions (containing printlns) and/or rewrite rules.

4 - LifeCyle

  • Write the grammar using one or more files.
  • Optionally write StringTemplate templates for producing output.
  • Generate the lexer and parser classes from the grammar.
  • Write an application that uses the the generated classes.

5 - Documentation

Advertising

6 - Eclipse

7 - Sample

8 - Glossary

8.1 - StringTemplate

StringTemplate is a library that supports using templates with placeholders for outputting text (ex. Java source code)

antlr/antlr.txt · Last modified: 2018/09/24 10:35 by gerardnico