Questions tagged [antlr4]

Version 4 of ANother Tool for Language Recognition (ANTLR), a flexible lexer/parser generator. ANTLR4 features an enhanced adaptive LL(*) parsing algorithm, that improves on the simpler LL(*) algorithm used in ANTLR3.

ANTLR stands for ANother Tool for Language Recognition, a powerful parser generator for reading, processing, executing, or translating structured text or binary files. At its core, ANTLR uses a grammar, with syntax loosely based on Backus–Naur_Form, to generate a parser. That parser produces easily traversable parse trees, which can be processed further by the user. ANTLR's simplistic and powerful design has allowed it to be used in many projects, from the expression evaluator in Apple's Numbers application1, to IntelliJ's IDEA IDE2.

The main improvement between ANTLR4 and ANTLR3 is a change in the parsing algorithm. This new variation of the LL(*) parsing algorithm, coined adaptive LL(*), pushes all of the grammar analysis effort to runtime, making ANTLR able to handle left recursive rules. This new resilience lead to the name "Honey Badger", on which Terence Parr had this to say:

ANTLR v4 is called the honey badger release after the fearless hero of the YouTube sensation, "The Crazy Nastyass Honey Badger". To quote the honey badger, ANTLR v4 just doesn't give a damn. It's pretty bad ass. It'll take just about any grammar you give it at parse correctly. And, without backtracking!*

-- Terence Parr

(To read more, check out the full conversation!)

If you are interested in learning to use ANTLR4, a good place to start would be the official documentation, which provides an excellent introduction to the library itself.

Further Reading:

1 Sourced from a paper written by Terrence Parr himself.

2 Sourced from Jetbrain's official list of third party software in IDEA.

3 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 ANTLR 4.x.

3877 questions
5
votes
3 answers

How to leave out unimportant nodes?

I am using ANTLR 4.9.2 to parse a grammar that represents assembly instructions. grammar IrohAsm; main: line* | EOF; line: (rangedec | instruction | comment)? EOL; instruction: MNEMONIC firstoperand COMMA secondoperand; rangedec : range…
Michael
  • 63
  • 1
  • 6
5
votes
2 answers

Is there a way to easily adapt the error messages of ANTLR4?

Currenlty I'm working on my own grammar and I would like to have specific error messages on NoViableAlternative, InputMismatch, UnwantedToken, MissingToken and LexerNoViableAltException. I already extended the Lexer.class and have overridden the…
stefan94452
  • 111
  • 1
  • 9
5
votes
1 answer

what is the DFA Cache miss shown by ANTLR4 profiler in IntelliJ?

what is the DFA Cache miss shown by ANTLR4 profiler in IntelliJ? I can see that the DFA Cache miss has to do with increased parse time. What can I do to reduce it? Any Examples?
user1870400
  • 6,028
  • 13
  • 54
  • 115
5
votes
1 answer

How to process c and c++ source code to calculate metrics for static code analysis?

Iam extending a software tool to calculate metrics for software projects. The metrics are then used to do a static code analysis. My task is to implement the calculation of metrics for c and c++ projects. In the developing process i encountered…
Tarexx
  • 131
  • 1
  • 5
5
votes
1 answer

ANTLR4: grun errors while using separate grammar (ClassCastException)

Description I'm trying to create a custom language that I want to separate lexer rules from parser rules. Besides, I aim to divide lexer and parser rules into specific files further (e.g., common lexer rules, and keyword rules). But I don't seem to…
mbadawi23
  • 1,029
  • 2
  • 21
  • 43
5
votes
0 answers

What are the ways to speed up parsing in Antlr4?

I have some doubts regarding the performance of Antlr4. I am currently using Python with Antlr4. It is terribly slow compared to Java (Verified using Antlr4 IntelliJ plugin). Since I need to work with bigger codes for parsing, I am planning to…
vineeshvs
  • 479
  • 7
  • 32
5
votes
1 answer

Is there a language specification document for PowerShell 5 or later

Hi I'm developing an ANTLR4 grammar for PowerShell and am looking for the language specification for PowerShell 5 or later. At the moment the grammar is based on Microsoft's Powershell 3 specification doc…
diegobt
  • 53
  • 6
5
votes
2 answers

Migrating ANTLR v2 grammar to ANTLR v4

We have a grammar written for antlr V2 and I would like to migrate to antlr v4. Is there any migration Guide? I would also like to know modifications of existing V2 grammar so that we utilize v4 features well.
Loren Cahlander
  • 1,257
  • 1
  • 10
  • 24
5
votes
1 answer

sqlite3.g4 grammar does not handle left join correctly

The github sqlite3 grammar github.com/antlr/grammars-v4/blob/master/sqlite/SQLite.g4 has issue with left join. For this sql select * from t1 left join t2 on t1.owner = t2.email the word 'left' is parsed as a table_alias. Things go rapidly downhill…
pm100
  • 48,078
  • 23
  • 82
  • 145
5
votes
0 answers

Is it possible to force-build a complete DFA cache for an ANTLR4 grammar?

I'm looking into porting a JavaScript grammar that uses the C++ runtime from ANTLR3 to ANTLR4 (well technically the ANTLR3 version uses the C runtime, but that's not relevant right now). The main issue I'm struggling with is performance. I have…
BruceBerry
  • 1,166
  • 1
  • 9
  • 21
5
votes
0 answers

Antlr: parse tree not showed in Eclipse

The view Parse Tree in Eclipse Oxygen is empty and white. I can compile my Hello.g4 grammar, see the Syntax Diagram but the Parse Tree view is empty. How can I fix it?
SctALE
  • 509
  • 2
  • 10
  • 30
5
votes
1 answer

How to understand ATN graph generated for ANTLR grammar?

I have 2 simple lexer rules in my ANTLR4 grammar: fragment Attrs : '.' ARCH; fragment ARCH : 'IA32' | 'X64' | 'IPF' | 'EBC' | 'common'; The generated ATN with ANTLR4.7 is like this (Visual Studio Code): I searched some references about "ATN",…
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
5
votes
2 answers

ANTLR4.7: rule XXX contains a closure with at least one alternative that can match an empty string'

I am trying to create a grammar to match content like below: (For a simple grammar to repro this issue please see ADD 1) [Defines] INF_VERSION = 0x00010005 BASE_NAME = WebServer FILE_GUID …
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
5
votes
1 answer

How solve OutOfMemoryException when parsing large files with Antlr4 in c#?

I am trying to parse a large file (about 500MB) with Antlr4 using c#. But I am having an OutOfMemoryException. My current code is described below: var path = GetInput(Path.Combine(DatFilePath)); // Build the large file var inputStream = new…
5
votes
3 answers

No module named antlr4 in python 2.7

I would like to use ANTLR4 with Python 2.7 and for this I did the following: I installed the package antlr4-4.6-1 on Arch Linux with sudo pacman -S antlr4. I wrote a MyGrammar.g4 file and successfully generated Lexer and Parser Code with antlr4…
ec-m
  • 779
  • 1
  • 5
  • 15