Questions tagged [antlr]

ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages.

What is ANTLR?

"ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build and walk parse trees. From https://www.antlr.org/

Since ANTLR is not commercial software, it is not required and does not maintain backward compatibility with previous major versions and even between some minor versions.

Updated links

On January 24th 2013, the www.antlr.org address was changed from pointing at site for ANTLR version 3 (www.antlr3.org) to ANTLR version 4 (www.antlr4.org). So questions and answers that used www.antlr.org were correct for ANTLR 3.x before this date. The links should be updated to www.antlr3.org for ANTLR 3.x or www.antlr4.org for ATNLR 4.x.

ANTLR IDE

Useful ANTLR links

Examples and/or useful posts on SO

Related links

Code at Git

Related tags

Related projects

Installation

Antlr can most easily be installed through its NuGet package.

Install-Package Antlr

Books

4218 questions
10
votes
1 answer

Is there a working C++ grammar file for ANTLR?

Are there any existing C++ grammar files for ANTLR? I'm looking to lex, not parse some C++ source code files. I've looked on the ANTLR grammar page and it looks like there is one listed created by Sun Microsystems here. However, it seems to be a…
c14ppy
  • 247
  • 3
  • 6
10
votes
3 answers

What are the disadvantages of using ANTLR compared to Flex/Bison?

I've worked on Flex, Bison few years ago during my undergraduate studies. However, I don't remember much about it now. Recently, I have come to hear about ANTLR. Would you recommend that I learn ANTLR or better to brush up Flex/Bison? Does ANTLR…
user855
  • 19,048
  • 38
  • 98
  • 162
10
votes
3 answers

Getting started with ANTLR and avoiding common mistakes

I have started to learn ANTLR and have both the 2007 book "The Definitive ANTLR Reference" and ANTLRWorks (an interactive tool for creating grammars). And, being that sort of person, I started at Chapter 3. ("A quick tour for the impatient"). It's…
peter.murray.rust
  • 37,407
  • 44
  • 153
  • 217
10
votes
2 answers

Is it possible to parse big file with ANTLR?

Is it possible to instruct ANTLR not to load entire file into memory? Can it apply rules one by one and generate topmost list of nodes sequentially, along with reading file? Also may be it is possible to drop analyzed nodes somehow?
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
9
votes
1 answer

Antlr IDE in Eclipse doesn't work

I'm using Antlr v3 and java for a project and all goes well in AntlrWorks, but when I switch to Antlr IDE, the plugin for eclipse, the interpreter cannot match the sentence that I wrote, telling me mismatch. And it seems to me that it cannot…
darkjh
  • 2,821
  • 7
  • 35
  • 43
9
votes
2 answers

Writing a custom Xtext/ANTLR lexer without a grammar file

I'm writing an Eclipse/Xtext plugin for CoffeeScript, and I realized I'll probably need to write a lexer for it by hand. CoffeeScript parser also uses a hand-written lexer to handle indentation and other tricks in the grammar. Xtext generates a…
Adam Schmideg
  • 10,590
  • 10
  • 53
  • 83
9
votes
1 answer

ANTLR @header, @parser, superClass option and basic file io (Java)

I want to use parser actions with basic file io (Java), e. g. PrintWriter in an ANTLR grammar. Must I use the superClass option or can I use @header? In both cases how can I declare the PrintWriter-object and how must I handle the exceptions?
ANTLRStarter
  • 309
  • 1
  • 4
  • 16
9
votes
2 answers

How to match a fixed number of characters in ANTLR 3?

I want to parse ISO 8601 dates in my ANTLR grammar. 2001-05-03 I have the following entries in my grammar file: date : FOUR_DIGIT ('-')? TWO_DIGIT ('-')? TWO_DIGIT ; FOUR_DIGIT : TWO_DIGIT TWO_DIGIT ; TWO_DIGIT : DIGIT DIGIT ; DIGIT …
user177800
9
votes
2 answers

Editor generator for ANTLR grammars?

I'm using ANTLR for creating a new general purpose programming language and I'm quite happy with it. Due to the fact that I would like to provide good tools for ease the development of programs written with my language I'm starting to thinking on…
9
votes
2 answers

What is the equivalent for epsilon in ANTLR BNF grammar notation?

During taking advantage of ANTLR 3.3, I'm changing the current grammar to support inputs without parenthesis too. Here's the first version of my grammar : grammar PropLogic; NOT : '!' ; OR : '+' ; AND : '.' ; …
Amirh
  • 443
  • 1
  • 6
  • 13
9
votes
1 answer

ANTLRInputStream and ANTLRFileStream are deprecated, what are the alternatives?

If I use ANTLRFileStream antlrFileStream = new ANTLRFileStream("myfile.testlang"); or ANTLRInputStream input = new ANTLRInputStream( new FileInputStream("myfile.testlang") ); Compiler shows deprecation error for both the classes what is…
Ameer Tamboli
  • 1,218
  • 12
  • 20
9
votes
1 answer

ANTLR Parser with manual lexer

I'm migrating a C#-based programming language compiler from a manual lexer/parser to Antlr. Antlr has been giving me severe headaches because it usually mostly works, but then there are the small parts that do not and are incredibly painful to…
luiscubal
  • 24,773
  • 9
  • 57
  • 83
9
votes
0 answers

class constructor cannot be invoked without 'new

I am trying to use a 3rd party typescript library(antlr - https://github.com/tunnelvisionlabs/antlr4ts) in my angular 2 project created using angular-cli. It's failing with this error class constructor MyLexer cannot be invoked without 'new. If you…
user911
  • 1,509
  • 6
  • 26
  • 52
9
votes
1 answer

ANTLR: problem differntiating unary and binary operators (e.g. minus sign)

i'm using ANTLR (3.2) to parse some rather simple grammar. Unfortunately, I came across a little problem. Take the follwoing rule: exp : NUM | '(' expression OPERATOR expression ')' -> expression+ | '(' (MINUS | '!') expression ')' -> expression …
Christian
  • 93
  • 1
  • 3
9
votes
3 answers

Is there a utility which given an ANTLR grammar will produce matching strings?

I have an ANTLR grammar and I would like to fuzz my parser.
Jerome B
  • 91
  • 1