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
4
votes
1 answer

ANTLR3: match everything until a specific keyword

I am using ANTLR 3 to do the below. Assume I have an SQL query. I know that in general it's WHERE, ORDER BY and GROUP BY clauses are optional. In terms of ANTLR's grammar I would describe that like this: query : select_clause from_clause…
preeze
  • 1,061
  • 1
  • 12
  • 18
4
votes
1 answer

ANTLR generating invalid java exceptions throws code

I've been using ANTLRwork 1.5 these days, together with antlr runtime 3.5. Here is a weird thing i found: Antlr is generating this kind of java code for me: public final BLABLABLAParser.addExpression_return addExpression() throws { …
tylaar
  • 41
  • 2
4
votes
1 answer

Invalid casting Issues with antlr grammar / parser in C#

I'm using Anlr 3.5 to generate a parser and lexer from the below included grammar. This grammar is to be used to read strings so as to convert them into an object graph for later evaluation. I however am having issues when I attempt to use a…
rheone
  • 1,517
  • 1
  • 17
  • 30
4
votes
2 answers

ANTLR Implicit Multiplication

I'm new to ANTLR, and I'm trying to expand upon the example of a simple calculator presented here. Specifically, I've tried adding some simple functions, negative numbers and so on, to familiarize myself with ANTLR. However, I've run into a bit of…
Tyler
  • 151
  • 6
4
votes
2 answers

Lexer tokenises unexpectedly

The following extremely simple example grammar doesn't lex as I expected (at all). Declaration : 'VAR'; Letter: ('A'..'Z'); message : Declaration Letter+; what I expected as a result is that any sequence of letters would lex as individual…
Martijn
  • 11,964
  • 12
  • 50
  • 96
4
votes
1 answer

How to throw an exception in Antlr grammar

I have this kind of a grammar, locationPath returns [CustomParser xpathParser] :^(LOCATION_PATH relativeLocationPath {**Want to throw a exception if this condition matches**}) |^(LOCATION_PATH absoluteLocationPath…
andunslg
  • 781
  • 14
  • 38
4
votes
1 answer

How to change ANTLR2 to ANTLR3

I am developing a practice problem in Java with ANTLR 3.4. The instructions that are given us in ANTLR 2.7 and change with respect to version 3. I found pages show some differences, but not those that seek. In ANTLR 2.7 MiToken can load a class like…
4
votes
1 answer

ANTLR lexer can't lookahead at all

I have the following grammar: rule: 'aaa' | 'a' 'a'; It can successfully parse the string 'aaa', but it fails to parse 'aa' with the following error: line 1:2 mismatched character '' expecting 'a' FYI, it is the lexer's problem not the…
K J
  • 4,505
  • 6
  • 27
  • 45
4
votes
2 answers

How to translate the AST generated by ANTLR to its source code

I am writing an simple parser&rewriter tools for PL/SQL, and I've complete the parser and get the AST,but now I got two problems : How can I get certain nodes of the AST ,so as to change the value of them? After change the nodes ,how can i…
Ivan
  • 41
  • 3
4
votes
1 answer

Resolving a token conflict in antlr

I have a Token OR:'OR'; that I use for evaluating a boolean expression( a==b OR a==c) I have another rule for parsing state abbreviation that are in a char list AZ,AK,OR,GA... What I am finding is that antlr has error on the state list thinking OR…
Aaron Fischer
  • 20,853
  • 18
  • 75
  • 116
4
votes
2 answers

What problems would arise in constructing a Java Decompiler through a grammar?

I am currently constructing a Java decompiler. In order to assist in pattern recognition, I am constructing a simple grammar through ANTLR and using ANTLRWorks interpreter to debug. Below's the preliminary grammar so far. In going down this route, I…
chuacw
  • 1,685
  • 1
  • 23
  • 35
4
votes
1 answer

How do I perform custom error reporting in ANTLR using python?

I'm writing a simple parser for my compilers class (just a proof of concept that I can get the tools working) and am using ANTLR with python bindings. I've gotten our trivial grammar to properly tokenize and parse, but I want to also handle the…
Chris Covert
  • 2,684
  • 3
  • 24
  • 31
3
votes
1 answer

Replace token in ANTLR

I want to replace a token using ANTLR. I tried with TokenRewriteStream and replace, but it didn't work. Any suggestions? ANTLRStringStream in = new ANTLRStringStream(source); MyLexer lexer = new MyLexer(in); TokenRewriteStream tokens = new…
user1019710
  • 321
  • 5
  • 14
3
votes
1 answer

How to remove ANTLR3 Warning 'multiple alternatives'

I found number of questions related to 'multiple alternatives'in stackoverflow but nothing was much helpful. Here is a part of my g file in antlr3. statement: selection_stmt | expression_stmt | compound_stmt | iteration_stmt …
Bee
  • 12,251
  • 11
  • 46
  • 73
3
votes
2 answers

ANTLR grammar error

I'm trying to built C-- compiler using ANTLR 3.4. Full set of the grammar listed here, program : (vardeclaration | fundeclaration)* ; vardeclaration : INT ID (OPENSQ NUM CLOSESQ)? SEMICOL ; fundeclaration :…
DarRay
  • 2,550
  • 6
  • 27
  • 39