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
14
votes
1 answer

Why are antlr3 c# parser methods private?

I'm building a parser in antlr which compiles to a working java target. When I retarget for c#2 it produces a parser in which all of the parse methods are private but marked with a [GrammarRule("rulename")] attribute. What is the approved means to…
Andy Bisson
  • 580
  • 5
  • 19
14
votes
5 answers

Are there tools to convert between ANTLR and other forms of BNF?

Are there any tools to convert ANTLR grammar syntax to and from other BNF syntaxes? There are several forms Backus-Naur Form (BNF, EBNF, ABNF, W3C-BNF, XBNF...) with specification, e.g. see this list. The ANTLR grammar syntax only seems to be…
Jakob
  • 3,570
  • 3
  • 36
  • 49
14
votes
5 answers

ANTLR: Get token name?

I've got a grammar rule, OR : '|'; But when I print the AST using, public static void Preorder(ITree tree, int depth) { if (tree == null) { return; } for (int i = 0; i < depth; i++) { Console.Write(" "); …
mpen
  • 272,448
  • 266
  • 850
  • 1,236
14
votes
2 answers

In antlr4 lexer, How to have a rule that catches all remaining "words" as Unknown token?

I have an antlr4 lexer grammar. It has many rules for words, but I also want it to create an Unknown token for any word that it can not match by other rules. I have something like this: Whitespace : [ \t\n\r]+ -> skip; Punctuation : [.,:;?!]; //…
mdakin
  • 1,310
  • 11
  • 17
14
votes
1 answer

Semantic predicates in ANTLR4?

How would you translate this portion of code written in ANTLR 3 into ANTLR 4? expr: (Identifier '.')=> (refIdentifier) | (Identifier '!')=> (refIdentifier) | (Identifier '=>')=> (lambdaExpression); I mean this kind of semantic predicate does…
Aftershock
  • 5,205
  • 4
  • 51
  • 64
14
votes
4 answers

ANTLR grammar for Scala?

I am trying to build a static analysis tool for a demo project. We are free to choose the language to analyze. I started off by writing a Java code analyzer using ANTLR. I now want to do the same for Scala code. However, I could not find the ANTLR…
Jus12
  • 17,824
  • 28
  • 99
  • 157
13
votes
2 answers

Parsing Context Sensitive Language

i am reading the Definitive ANTLR reference by Terence Parr, where he says: Semantic predicates are a powerful means of recognizing context-sensitive language structures by allowing runtime information to drive recognition But the examples…
Radi
  • 6,548
  • 18
  • 63
  • 91
13
votes
5 answers

Removing Left Recursion in ANTLR

As is explained in Removing left recursion , there are two ways to remove the left recursion. Modify the original grammar to remove the left recursion using some procedure Write the grammar originally not to have the left recursion What people…
prosseek
  • 182,215
  • 215
  • 566
  • 871
13
votes
3 answers

Getting ANTLR to generate a script interpreter?

Say I have the following Java API that all packages up as blocks.jar: public class Block { private Sting name; private int xCoord; private int yCoord; // Getters, setters, ctors, etc. public void setCoords(int x, int y) { …
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
13
votes
2 answers

How can i see the live parse tree using Antlr4 Ide in Eclipse?

I'm new using Antlr4 but I know that exist a plugin for Eclipse. I have a simple question...After I created the g4 file how can I visualize the live parse tree in order to see the tree of an input expression? Thanks
userSimo
  • 165
  • 3
  • 12
13
votes
1 answer

antlr match any character except

I have the following deffinition of fragment: fragment CHAR :'a'..'z'|'A'..'Z'|'\n'|'\t'|'\\'|EOF; Now I have to define a lexer rule for string. I did the following : STRING : '"'(CHAR)*'"' However in string I want to match all of my…
Andrey
  • 479
  • 2
  • 10
  • 20
13
votes
1 answer

Syntax of semantic predicates in Antlr4

In What is a 'semantic predicate' in ANTLR3? Bart Kiers gives a very well overview about the different semantic predicates in Antlr3. Too bad the syntax/semantics were seemingly changed in Antlr4, so this does not compile: end_of_statement : …
Kijewski
  • 25,517
  • 12
  • 101
  • 143
12
votes
4 answers

LL(*) versus PEG parsers : what is the difference?

I am wondering if ANTLR v3, which presents its internal parsing algorithm as "LL(*)" is fully representative of PEG (parsing expression grammar) parsers. Is there a difference ?
JCLL
  • 5,379
  • 5
  • 44
  • 64
12
votes
4 answers

Is it possible to use Xtext without eclipse?

I have a DSL (implemented with ANTLR) for which I need to write a content assist/autocomplete editor. I've ported a prototype of my grammar to Xtext, and I'm quite happy with the quality of the editor it generates. Unfortunately, I cannot use…
Juan Tamayo
  • 155
  • 1
  • 7
12
votes
1 answer

Can I add Antlr tokens at runtime?

I have a situation where my language contains some words that aren't known at build time but will be known at run time causing the need to constantly rebuild / redeploy the program to take into account new words. I was wandering if it was possible…
probably at the beach
  • 14,489
  • 16
  • 75
  • 116