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
23
votes
4 answers

How to make CMake target executed whether specified file was changed?

I'm trying to use ANTLR in my C++ project. I made a target for running ANTLR generator for specified grammar and made main prjct dependent from it. ADD_CUSTOM_TARGET(GenerateParser COMMAND ${ANTLR_COMMAND} ${PROJECT_SOURCE_DIR}/src/MyGrammar.g …
DikobrAz
  • 3,557
  • 4
  • 35
  • 53
23
votes
1 answer

ANTLR4 mutually left-recursive error when parsing

I have this ANTLR 4 grammar: constantFixedExpresion : term (('+'|'-') term)+; term : factor (('*'|'//'|'REM')factor)+; factor : ('+'|'-')* ( wholeNumberConstant | constantFixedExpresion | 'TOFIXED' (stringConstant…
Alican
  • 261
  • 1
  • 2
  • 3
22
votes
4 answers

Tutorial for walking ANTLR ASTs in C#?

Is anyone aware of tutorials for walking ANTLR-generated ASTs in C#? The closest I was able to find is this, but it's not terribly helpful. My goal is to walk through trees that I'm generating based on a domain-specific language that I'm working on,…
kpozin
  • 25,691
  • 19
  • 57
  • 76
22
votes
6 answers

How to match a string, but case-insensitively?

Let's say that I want to match "beer", but don't care about case sensitivity. Currently I am defining a token to be ('b'|'B' 'e'|'E' 'e'|'E' 'r'|'R') but I have a lot of such and don't really want to handle…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
21
votes
1 answer

Negating inside lexer- and parser rules

How can the negation meta-character, ~, be used in ANTLR's lexer- and parser rules?
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
21
votes
4 answers

How to handle escape sequences in string literals in ANTLR 3?

I've been looking through the ANTLR v3 documentation (and my trusty copy of "The Definitive ANTLR reference"), and I can't seem to find a clean way to implement escape sequences in string literals (I'm currently using the Java target). I had hoped…
Sam Martin
  • 1,030
  • 1
  • 8
  • 16
21
votes
5 answers

Good parser generator (think lex/yacc or antlr) for .NET? Build time only?

Is there a good parser generator (think lex/yacc or antlr) for .NET? Any that have a license that would not scare lawyers? Lot’s of LGPL but I am working on embedded components and some organizations are not comfortable with me taking an LGPL…
Eric Schoonover
  • 47,184
  • 49
  • 157
  • 202
20
votes
1 answer

What are features of ANTLR that XText Does not provide?

I just came across very nice tool Xtext to create DSL as well as IDE for editing. I did some search on the web and found people saying it does not provide all the features of ANTLR. I am using ANTLR as my parser generator. I am not even sure what…
Tasawer Khan
  • 5,994
  • 7
  • 46
  • 69
20
votes
4 answers

ANTLR 4: Avoid error printing to console

With ANTLR I parse a grammar. The ANTLR errors are indicated in a custom editor for the grammar. However I would like to disable the printing of error messages to a Java console. I've implemented my own BaseErrorListener and removed the default as…
Marcel
  • 502
  • 3
  • 11
20
votes
3 answers

Is there a simple example of using antlr4 to create an AST from java source code and extract methods, variables and comments?

Can someone provide a detailed example as to how I can do this using antlr4? Instructions right from installing antlr4 and its dependencies would be highly appreciated.
user3266901
  • 293
  • 1
  • 2
  • 8
20
votes
1 answer

When is EOF needed in ANTLR 4?

The TestDriver in ANTLRWorks2 seems kind of finicky about when it'll accept a grammer without and explicit EOF and when it will not. The Hello grammar in the ANTLR4 Getting Started Guide doesn't use EOF anywhere, so I inferred that it's better to…
DaoWen
  • 32,589
  • 6
  • 74
  • 101
20
votes
0 answers

Validate antlr-grammar online

Does anyone know if there exists some kind of online-testing environment for antlr-grammars where i can validate and test a given grammar against some input strings...? Would be glad for any help!
r3try
  • 667
  • 8
  • 20
19
votes
4 answers

Parsing Objective-C code for static analysis

I love static analysis and compile-time checks, almost to a fault, but most of my day job is in Objective-C. To resolve this tension, I'd like to be able to write my own analysis tools that I can run on my Objective-C projects. But googling around…
Bill
  • 44,502
  • 24
  • 122
  • 213
19
votes
3 answers

Can Xtext be used for parsing general purpose programming languages?

I'm currently developing a general-purpose agent-based programming language (its syntaxt will be somewhat inspired by Java, and we are also using object in this language). Since the beginning of the project we were doubtful about the fact of using…
19
votes
1 answer

ANTLR4 what does ATN stand for?

I'm surprised this is not explained anywhere on the ANTLR website nor in any of the documentation, but what does ATN (not ANT) stand for? Knowing what the acronym stands for would help me understand the role of the ATN, ATNSimulator, etc. components…
rolling_codes
  • 15,174
  • 22
  • 76
  • 112