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
5
votes
4 answers

Antlr3.runtime access denied after updating deployed files

We have an ASP.NET application that was written by a former employee that I have thus far been holding together with duct tape. The app was written with MVC, NHibernate and some other processes, none of which any of our other apps use, so I have…
techturtle
  • 2,519
  • 5
  • 28
  • 54
5
votes
1 answer

how to remove left-recursion

I'd like to make a grammar that will allow curried function calls. That is: a() /// good a()() /// good a()()() /// good a(a) /// good a(a()()) /// good /// etc My first stab was this: ID : ('a'..'z'|'A'..'Z'|'_')…
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
5
votes
1 answer

The Definitive ANTLR Reference - First program not working

I recently purchased The Definitive ANTLR Reference and I am excited to begin using ANTLR. In the first chapter, this grammar is shown: grammar T; options { language = Java; } r : 'call' ID ';' {System.out.println("invoke " + $ID.text);}…
leaf
  • 95
  • 5
5
votes
1 answer

ANTLR lexer rule consumes characters even if not matched?

I've got a strange side effect of an antlr lexer rule and I've created an (almost) minimal working example to demonstrate it. In this example I want to match the String [0..1] for example. But when I debug the grammar the token stream that reaches…
Lichtblitz
  • 213
  • 2
  • 10
4
votes
3 answers

ANTLR Interpreter running error

When i run the interpreter as follows, to create parse tree in ANTLR 3.4(in eclipse 3.7) it shows, An internal error occurred during: "ANTLR Event Listener". For input string: "false" When I run the second option Debug(Java) it doesn't give…
DarRay
  • 2,550
  • 6
  • 27
  • 39
4
votes
1 answer

A simple ANTLR 3.4 example for C target runtime

Does anyone know of (or have) a simple ANTLR 3.4 example main() function for C target? I'm trying to get started with ANTLR in C or C++, and all examples I see (including this) are out of date, e.g. they use functions that don't exist any more. …
ikh
  • 2,336
  • 2
  • 19
  • 28
4
votes
1 answer

ANTLR - Token Enumeration Mismatch Between Grammar and Tree Grammar

BackGround I am trying to write a simple grammar, using AntlrWorks, for boolean equations that test sets of values for the existence (or lack there of) of specified elements. I have created a combined lexer/parser grammar that produces the desired…
Rex Redi
  • 93
  • 8
4
votes
1 answer

sbt and antlr, got simple example?

Does anyone have an example of how to set up sbt to build an ANTLR file (to scala) and then compile the resulting code. My file layout src/main/scala/Test.scala // scala test rig src/main/scala/Test.g // antlr grammar …
wing
  • 171
  • 1
  • 5
4
votes
2 answers

ANTLR3 Hetero nodes are not created

I am trying to create a heterogeneous tree based on a sample provided here: http://www.antlr.org/wiki/display/ANTLR3/Tree+construction#Treeconstruction-Heterogeneoustreenodes I have created a grammar file as follows: grammar T; options { …
dcg
  • 1,144
  • 1
  • 22
  • 38
4
votes
2 answers

ANTLR grammar for reStructuredText (rule priorities)

First question stream Hello everyone, This could be a follow-up on this question: Antlr rule priorities I'm trying to write an ANTLR grammar for the reStructuredText markup language. The main problem I'm facing is : "How to match any sequence of…
Robin
  • 323
  • 2
  • 9
4
votes
1 answer

ANTLR's AST tree grammar + lists

I've have read a lot trying to find a way to cleanly consume lists in ANTLR's tree grammar. Here is what I have tried and their results (I really hope I'm missing something trivial)... Using += Syntax program returns [someInterface result] :…
Andrew White
  • 52,720
  • 19
  • 113
  • 137
4
votes
1 answer

Extract hidden comment content preceding a specific rule or token (Antlr, Java)

I am new to antlr and java so this may be a trivial question (hopefully!). I am using antlr 3.4. I have a grammar for the lexer: lexer grammar MyLexer; options { language = Java; } COMMENT: ( '//' ~('\n'|'\r')* '\r'? '\n' | '/*' .*…
Renoa
  • 385
  • 1
  • 4
  • 10
4
votes
1 answer

How to catch list of tokens in tree grammar of antlr3?

I took a dummy language for example: It simply accepts one or more '!'. its lexer and grammar rules are: grammar Ns; options { output=AST; ASTLabelType=CommonTree; } tokens { NOTS; } @header { package test; } @lexer::header { package…
pf_miles
  • 907
  • 1
  • 8
  • 17
4
votes
1 answer

'IDENTIFIER' rule also consumes keyword in ANTLR Lexer grammar

While working on Antlr 3.5 grammar for Java parsing noticed that 'IDENTIFIER' rule consumes few Keywords in ANTLR Lexer grammar. The Lexer grammar is lexer grammar JavaLexer; options { //k=8; language=Java; filter=true; …
Kishore_2021
  • 645
  • 12
  • 38
4
votes
1 answer

How to do Unicode escape decoding in Antlr tokenizer

I've created a antlr grammar using AntlrWorks, and have created a localization tool for internal use. I would like to convert unicode escape sequences into the actual Java character while parsing, but am unsure of the best way to do this. Here…
Michael Donohue
  • 11,776
  • 5
  • 31
  • 44