Questions tagged [antlr3]

Version 3 of ANTLR (ANother Tool for Language Recognition) created and written by Dr. Terrence Parr

Version 3 of ANTLR.

What is 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. ANTLR provides excellent support for tree construction, tree walking, translation, error recovery, and error reporting. ..." -- http://www.antlr.org

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.

Useful ANTLR links

Examples and/or useful posts on SO

Related links

Code at Git

Related tags

911 questions
3
votes
2 answers

Two-level grammar with ANTLR 3

I have a grammar which (if you simplify it quite a bit) looks like this: options { backtrack=true; } // parser text: (TEXT)+; and_level2_thing: text | '(' and_thing ')'; and_thing: and_level2_thing (OP_AND and_level2_thing)*; and_expression:…
neverlastn
  • 2,164
  • 16
  • 23
3
votes
1 answer

Reuse a reserved keyword rule in ANTLR

I am working with ANTLR 3.4 .I have defined a lexer rule like Description: 'description' ; If I use this rule I will not be able to use 'description' in my language since it is now a keyword.Is there any way by which I can write a rule for non…
bhavanak
  • 255
  • 1
  • 12
3
votes
2 answers

Matching lexeme variants with Antlr3

I'm trying to match measurements in English input text, using Antlr 3.2 and Java1.6. I've got lexical rules like the following: fragment MILLIMETRE : 'millimetre' | 'millimetres' | 'millimeter' | 'millimeters' | 'mm' …
Stephen Winnall
  • 301
  • 3
  • 14
3
votes
1 answer

Solving ANTLR Mutually left-recursive rules

the 'expr' rule in the ANTLR grammar below obviously mutually left-recursive. As a ANTLR newbie it's difficult to get my head around solving this. I've read "Resolving Non-LL(*) Conflicts" in the ANTLR reference book, but I still don't see the…
Ward Bekker
  • 6,316
  • 9
  • 38
  • 61
3
votes
0 answers

override rule_return class in ANTLR parser class

I want to change the definition of getTree() methode of generated return class like statement_return (see below example). See below Sample parser grammar and respecting generated code which includes statement() and statement_return(). parser…
Sanjiv
  • 1,795
  • 1
  • 29
  • 45
3
votes
0 answers

How to use porcelli plsql-parser (ANTLR)

I am new in ANTLR. My requirement is to programaticaly parse a PL/SQL block and to be able to format it based on some conditions.For example: 1) I want to find all the commented code inside the SQL block. 2) I should be able to write back the…
Vivek Agrawal
  • 617
  • 11
  • 23
3
votes
1 answer

Running methods generated by AntLR 4 grammar

I found a project [GitHub] to parse the natural date string and show the appropriate Date value. I wanted to modify the grammar according to my need and I did to some extent. But when I tried to run the required methods I am getting the below…
Nitin Mesta
  • 1,504
  • 19
  • 32
3
votes
1 answer

ANTLR is not reporting an error when evaluating a string that does not fits my grammar definition

This is the first time I am working with ANTLR for a project at Imperial College London and until now it has been really useful. I have already defined a simple recursive grammar as follows grammar Hello; execution: workflow; workflow :…
user3723800
  • 145
  • 7
3
votes
1 answer

How to use ANTLR for python target?

I'm using ANTLRWorks 1.5.2 for grammar creation and subsequent creation of the lexer and parser. I did that for Java target, but my preferred language is python. I'm quite puzzled by this: how can I specify my target language in ANTLRWorks 1.5.2 and…
sara
  • 81
  • 1
  • 7
3
votes
1 answer

ANTLR 3.x - How to format rewrite rules

I'm finding myself challenged on how to properly format rewrite rules when certain conditions occur in the original rule. What is the appropriate way to rewrite this: unaryExpression: op=('!' | '-') t=term -> ^(UNARY_EXPR $op $t) Antlr doesn't…
Jesse Hallam
  • 6,794
  • 8
  • 48
  • 70
3
votes
1 answer

ANTLR netbeans config Could not find or load main class org.antlr.Tool

I tried to configure antlr and netbeans with build xml, i followed the http://wiki.netbeans.org/AntlrInNetBeansJavaApplication tutorial, but when i clean and build the project i get an error like Error: Could not find or load main class…
Thomas Ny
  • 92
  • 1
  • 8
3
votes
1 answer

What does -> operator mean in ANTLR3?

I'm trying to compile a grammar and get it works in ANTLR4. The grammar was written for ANTLR3 and I'm getting a lot of compilation errors. Here is one of them: syntax error: '->' came as a complete surprise to me while looking for rule…
Stanley
  • 5,057
  • 4
  • 34
  • 44
3
votes
1 answer

How to parse a word that starts with a specific letter with ANTLR3 java target

Is there a way to parse words that start with a specific character? I've been trying the following but i couldn't get any promising results: //This one is working it accepts AD CD and such example1 : .'D' ; //This one is not, it expects character…
Attila Horváth
  • 562
  • 1
  • 5
  • 16
3
votes
1 answer

Getting First and Follow metadata from an ANTLR4 parser

Is it possible to extract the first and follow sets from a rule using ANTLR4? I played around with this a little bit in ANTLR3 and did not find a satisfactory solution, but if anyone has info for either version, it would be appreciated. I would like…
hendryau
  • 426
  • 3
  • 14
3
votes
3 answers

ANTLR3 Syntax reference?

I'm looking for a syntax reference to ANTLR3 and a quick search didn't find one, can someone tell me where one exists?
RCIX
  • 38,647
  • 50
  • 150
  • 207