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
1
vote
1 answer

ANTLR exception handling with "$", Java

For my grammar in ANTLR, my java code can catch and print errors for inputs containing "$". In my implementation, I need to print out "success" for successful input. So, I do following in my java code, CharStream charStream = new…
John David
  • 111
  • 1
  • 6
1
vote
1 answer

Capturing a group with a generic SQL dialect

I would like to define an expression of the grammar: =expr + #native(...) expr can be any valid expression in our grammar, and this currently works. However, #native(...) is a valid SQL statement in a target (potentially multiple) dialects, meaning…
David542
  • 104,438
  • 178
  • 489
  • 842
1
vote
1 answer

ANTLR - test class not found error when debugging

I am getting error of Test class not found error, even when I have made it via command java org.antlr.Tool something.g when debugging via ANTLRworks. I have been searching this on the web, but no success with it. Do you know, how to solve my…
Waypoint
  • 17,283
  • 39
  • 116
  • 170
1
vote
1 answer

Antlr setText not working in the way I expected

I have a requirement to convert an identifier into a beanutil string for retrieving an item from an object. The the identifiers to string conversions look like: name ==> name attribute.name …
nuzz
  • 647
  • 7
  • 18
1
vote
1 answer

ANTLR reg. expression error

Can you see any error with the following regular expression? I am defining it in Antlr 3.4, but it accepts arguments like $one, £one although it shouldn't. However, it doesn't accept o£ne, or o$ne. ID : ('a'..'z'|'A'..'Z'|' _ ')…
John David
  • 111
  • 1
  • 6
1
vote
1 answer

Problems with comparisons in ANTLR4 grammar

I've build a small parser for writing filters in my application and most of it works fine. But now I noticed something weird. I have comparisons like '==', '!=', '>=' etc and they also work fine. But for some reason antlr (or my grammar) also…
UglyBob
  • 247
  • 1
  • 14
1
vote
1 answer

How to separate nested islands from the sea in ANTLR4?

I am trying to implement an ANTLR4 grammar for a quite simple language, that extends the one from StringSubstitutor (but I'm using C#, so this library is no bueno). Basically it allows substitutions in a regular text, e.g. text ${aaa}${/asd/${yyy}}…
Marcin Tarsier
  • 192
  • 2
  • 9
1
vote
1 answer

How do I fix this ANTRL4, scanner precedence error?

I'm puzzled by the behavior of the following grammar. grammar MyParser; options { caseInsensitive = true; } // Parser Rules parameterName : DOLLAR_SIGN separatedIdentifier ; separatedIdentifier : EXTENDED_IDENTIFER ; //…
1
vote
1 answer

Any C project that use antlr3?

I am a java programmer and currently learning antlr3. I have to use antlr in a C project. It is a little difficult for a java programmer to write C code use antlr. So, I want to look some C project that use antlr I find a lot of java project that…
hellojinjie
  • 1,868
  • 3
  • 17
  • 23
1
vote
0 answers

antlr4 c++ runtime not compiling using conan package manager

I'm trying to create a simple application that uses antlr4 c++ runtime to parse Java source files. However, I could not compile it due to problems with conan package manager. I'm following antlr recommendation to use conan package manager. My…
bczup
  • 11
  • 1
1
vote
0 answers

Transform a DSL (proprietary SEEXML) to Java

Problem Currently we are running software from Seeburger company to transform e.g Edifact to iDoc. Therefore a lot of mapping files exist to describe this transformation in a proprietary language SEEXML. It has a file ending xml but it has just a…
timguy
  • 2,063
  • 2
  • 21
  • 40
1
vote
2 answers

How to get "previous" node in ANTLR ParseTree

I have the following rule: regExp : branch (PIPE branch)*. I built a listener and on my exitBranch method I want to know if a branch comes after a PIPE token. Something like @Override public void exitBranch(BranchContext ctx) { if (/*branch is…
136
  • 1,083
  • 1
  • 7
  • 14
1
vote
2 answers

Allow any order between grammar rules including optional ones in ANTLR4

I have a rule defined like this: rule: ( a | b | c | d | e )*; I do this expression because I want to allow any ordering of the individual grammar objects - with no assumptions whatsoever. But now, I would like to express that rule a for example is…
huzzm
  • 489
  • 9
  • 24
1
vote
0 answers

Should ANTLR handle the case of two grammars with the same name?

Consider two ANTLR grammars in a directory structure like the following: antlr-4.12.0-complete.jar generated-code/ grammars/ com/ example/ version1/ Grammar.g4 version2/ Grammar.g4 The idea is to keep around a…
1
vote
0 answers

Using ANTLR4 on python grammars

I have a problem using antlr4. I installed it using brew install antlr and pip install antlr4-python3-runtime. Now when I want to use it with antlr4 -Dlanguage=Python3 PSLGrammar.g4. But this results in those 3 errors: ssl.SSLCertVerificationError:…
Lucas Winkler
  • 51
  • 1
  • 8