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
360
votes
6 answers

lexers vs parsers

Are lexers and parsers really that different in theory? It seems fashionable to hate regular expressions: coding horror, another blog post. However, popular lexing based tools: pygments, geshi, or prettify, all use regular expressions. They seem…
Naveen
  • 5,910
  • 5
  • 30
  • 38
268
votes
5 answers

ANTLR: Is there a simple example?

I'd like to get started with ANTLR, but after spending a few hours reviewing the examples at the antlr.org site, I still can't get a clear understanding of the grammar to Java process. Is there some simple example, something like a four-operations…
Eli
  • 6,353
  • 9
  • 30
  • 25
198
votes
7 answers

How to convert a String to its equivalent LINQ Expression Tree?

This is a simplified version of the original problem. I have a class called Person: public class Person { public string Name { get; set; } public int Age { get; set; } public int Weight { get; set; } public DateTime FavouriteDay { get; set;…
Codebrain
  • 5,565
  • 4
  • 28
  • 21
157
votes
5 answers

Advantages of Antlr (versus say, lex/yacc/bison)

I've used lex and yacc (more usually bison) in the past for various projects, usually translators (such as a subset of EDIF streamed into an EDA app). Additionally, I've had to support code based on lex/yacc grammars dating back decades. So I know…
Don Wakefield
  • 8,693
  • 3
  • 36
  • 54
118
votes
4 answers

What does "fragment" mean in ANTLR?

What does fragment mean in ANTLR? I've seen both rules: fragment DIGIT : '0'..'9'; and DIGIT : '0'..'9'; What is the difference?
Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124
107
votes
2 answers

What is a 'semantic predicate' in ANTLR?

What is a semantic predicate in ANTLR?
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
89
votes
4 answers

How to create AST with ANTLR4?

I've been searching A LOT about this and I couldn't find anything useful that REALLY helps me build an AST. I already know that ANTLR4 doesn't build AST like ANTLR3 used to do. Everyone say: "Hey, use visitors!", but I couldn't find any example or…
Leandro
  • 1,114
  • 1
  • 12
  • 15
72
votes
4 answers

Using ANTLR 3.3?

I'm trying to get started with ANTLR and C# but I'm finding it extraordinarily difficult due to the lack of documentation/tutorials. I've found a couple half-hearted tutorials for older versions, but it seems there have been some major changes to…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
66
votes
1 answer

If/else statements in ANTLR using listeners

I'm creating a simple programming language for a school project. I'm using ANTLR 4 to generate a lexer and a parser from my grammar. Until now, I have been using ANTLRs listener pattern to apply the actual functionality of the programming…
simonbs
  • 7,932
  • 13
  • 69
  • 115
55
votes
25 answers

Why is .NET exception not caught by try/catch block?

I'm working on a project using the ANTLR parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that…
spoulson
  • 21,335
  • 15
  • 77
  • 102
52
votes
3 answers

ANTLR 4.5 - Mismatched Input 'x' expecting 'x'

I have been starting to use ANTLR and have noticed that it is pretty fickle with its lexer rules. An extremely frustrating example is the following: grammar output; test: FILEPATH NEWLINE TITLE ; FILEPATH:…
Chiune Sugihara
  • 1,179
  • 1
  • 7
  • 14
51
votes
4 answers

How to specify a target package for ANTLR?

If I call: java org.antlr.Tool -o outdir sources/com/example/Java5.g ...with antlr-3.1.3 the parser and lexer code will be generated in the directory outdir/sources/com/example. But the generated classes don't have any package statement. I need…
tangens
  • 39,095
  • 19
  • 120
  • 139
47
votes
8 answers

What's better, ANTLR or JavaCC?

Concerns are documentation/learnability, eclipse integration, tooling, community support and performance (in roughly that order).
Jason
  • 2,025
  • 2
  • 21
  • 13
47
votes
3 answers

How do I get the original text that an antlr4 rule matched?

Using the Java 7 grammar https://github.com/antlr/grammars-v4/blob/master/java7/Java7.g4 I want to find methods with a specific name and then just print out that method. I see that I can use the methodDeclaration rule when I match. So I subclass…
monty0
  • 1,759
  • 1
  • 14
  • 22
46
votes
2 answers

What is the purpose of Antlr package in Visual Studio 2013 ASP.NET project?

The ASP.NET (web forms) project template in Visual Studio 2013 includes several packages. I'm trying to figure out which ones are essential (may need to create a separate question for this). The post at…
Alek Davis
  • 10,628
  • 2
  • 41
  • 53
1
2 3
99 100