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

Understanding ABNF syntax "0"

In RFC 3986, they defined the rule: path-empty = 0 For simplicity, let's assume pchar is defined: pchar = 'a' / 'b' / 'c' What does path-empty match and how is it matched? I've read the Wikipedia page on ABNF. My guess is that matches the…
Oliver
  • 1,465
  • 4
  • 17
1
vote
2 answers

Why is this ANTLR grammar reporting errors?

I have a fairly simple grammar designed to parse URIs. It is compiled with the help of antlr4-maven-plugin. Compiling produces no warnings or errors. I wrote a simple test. Uri.g4: /** * Uniform Resource Identifier (RFC 3986). * * @author Oliver…
Oliver
  • 1,465
  • 4
  • 17
1
vote
0 answers

I cannot parse a file because of implicit definitions in ANTLR

I have a problem when I try to parse a file on ANTLR4. I'm using the ANTLR4 plugin on IntelliJ and the program always throws me these warnings which makes me unable to parse any file or text using the plugin. If I use the console I also get the same…
0xracer
  • 9
  • 3
1
vote
1 answer

ANTLR4 grammar: getting mismatched input error

I have defined the following grammar: grammar Test; parse: expr EOF; expr : IF comparator FROM field THEN #comparatorExpr ; dateTime : DATE_TIME; number : …
avs099
  • 10,937
  • 6
  • 60
  • 110
1
vote
1 answer

Tree of variable definitions with and without initializations

my language to parse contains statements like public var a, b = 42, c; I.e. the .g file looks something like: statements : (introduction | expression ';'! | ... )+ ; introduction : head single+ -> ^(head single)+ ; single : Name…
Kijewski
  • 25,517
  • 12
  • 101
  • 143
1
vote
0 answers

How do I make a Simple ANTLR grammar extension?

I'm writing a framework that uses ANTLR to parse Java-style expressions. I had in mind to create a new type of free-form literal. The literal will look similar to a string, so I thought to extend the Java8 grammar I'm using with a new literal…
Andrew B
  • 23
  • 1
  • 4
1
vote
2 answers

ANTLR4 How can I create a regular expression that allows all characters except two selected ones?

Hi for example I have this code for the g4 file: a: [A-Z][A-Z]; b: [a-z]'3'; Now I want to add one line more, which recognizes all characters that do not belong to a or b I tried: a: [A-Z][A-Z]; b: [a-z]'3'; ALLOTHERCHARACTERS: ~[a]|~[b] But i…
gekomorio
  • 11
  • 2
1
vote
1 answer

Antlr parser ambiguous literal

I have a grammar like this: grammar a; rule : cccc direction; cccc: Char Char Char Char; direction: Digit Digit Digit 'V' Digit Digit Digit; Char : [A-Z]; Digit: [0-9]; WS: [ \t\n\r=] ->skip; I want parser String "AVBC 120V230" ,but i got…
Carl Wang
  • 15
  • 2
1
vote
1 answer

Is it possible to use multiple Java versions within same build.xml - ANT build. - ANTLR3.3

I am working on a legacy project which needs to be upgraded to use Java8. During the upgrade we are facing issues with ANTL3.3 as it not compatible with Java8. Now because of certain dependencies we cannot upgrade ANTLR version and ANTLR is used to…
Paul Phoenix
  • 1,403
  • 6
  • 19
  • 33
1
vote
1 answer

ANTLRFileStream is deprecated, what can I use instead?

I am trying to compile a test class to test a simple grammer. import org.antlr.v4.runtime.*; public class Test { public static void main(String[] args) throws Exception { CharStream input = null; // pick an input stream…
1
vote
1 answer

Why doesn't this ANTLR grammar derive the string `baba`?

Using ANTLR v4.9.3, I created the following grammar … grammar G ; start : s EOF ; s : 'ba' a b ; a : 'b' ; b : 'a' ; Given the above grammar, I thought that the following derivation is possible … start → s → 'ba' a b → 'ba' 'b' b → 'ba' 'b' 'a'…
user3134725
  • 1,003
  • 6
  • 12
1
vote
1 answer

ANTLR4 error recovery issues for class bodies

I've found a strange issue regarding error recovery in ANTLR4. If I take the grammar example from the ANTLR book grammar simple; prog: classDef+ ; // match one or more class definitions classDef : 'class' ID '{' member+ '}' // a class has…
sazz
  • 11
  • 1
1
vote
2 answers

how to tell which non-terminal is missing within an expansion in ANTLR

oC_RangeLiteral : '*' SP? ( oC_IntegerLiteral SP? )? ( '..' SP? ( oC_IntegerLiteral SP? )? )? ; Given a parser tree with ctx->oC_IntegerLiteral().size() == 1, How can I tell whether the first one is missing or the second one is…
cpchung
  • 774
  • 3
  • 8
  • 23
1
vote
1 answer

Im just starting with ANTLR and I cant decipher where Im messing up with mismatched input error

I've just started using antlr so Id really appreciate the help! Im just trying to make a variable declaration declaration rule but its not working! Ive put the files Im working with below, please lmk if you need anything else! INPUT CODE: var…
1
vote
2 answers

What do I do in ANTLR if I want to parse something which is extremely configurable?

I'm writing a grammar to recognise simple mathematical expressions. I have it working for English. Now I want to expand the grammar to support i18n. Therefore, the digits, radix separator and so forth depend on the user's locale. What is the best…
Hakanai
  • 12,010
  • 10
  • 62
  • 132
1 2 3
99
100