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

Good CSS grammar in Antlr v4

Are there any good CSS grammars out there for antlr4? I know there are some grammars for antlr3, but it turns out CSS is not trivial to parse without "lexer modes", which were added in v4. Why? Consider the following CSS selectors: .hello.world { /*…
gzak
  • 3,908
  • 6
  • 33
  • 56
6
votes
1 answer

How to collect errors during run time given by a parser in Antlr4

I have upgraded from Antlr 3 to Antlr 4. I was using this code to catch exceptions using this code. But this is not working for Antlr 4. partial class XParser { public override void ReportError(RecognitionException e) { …
diyoda_
  • 5,274
  • 8
  • 57
  • 89
6
votes
1 answer

caret prefix instead of postfix in antlr

I know what the caret postfix means in antlr(ie. make root) but what about when the caret is the prefix as in the following grammar I have been reading(this grammar is brand new and done by a new team learning antlr).... selectClause : SELECT…
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
5
votes
1 answer

Dynamically create lexer rule

Here is a simple rule: NAME : 'name1' | 'name2' | 'name3'; Is it possible to provide alternatives for such rule dynamically using an array that contains strings?
Villa F.
  • 55
  • 1
  • 5
5
votes
1 answer

Different lexer rules in different state

I've been working on a parser for some template language embeded in HTML (FreeMarker), piece of example here: ${abc} Welcome!

Welcome ${user}<#if user == "Big Joe">, our beloved…

Bood
  • 193
  • 1
  • 8
5
votes
1 answer

ANTLR3 lexer precedence

I want to create a token from '..' in the ANTLR3 lexer which will be used to string together expressions like a..b // [1] c .. x // [2] 1..2 // [3] 3 .. 4 // [4] So, I have added, DOTDOTSEP : '..' ; The problem is that I…
tjm
  • 7,500
  • 2
  • 32
  • 53
5
votes
1 answer

What does ^ and ! stand for in ANTLR grammar

I was having difficulty figuring out what does ^ and ! stand for in ANTLR grammar terminology.
ssingh3
  • 125
  • 1
  • 8
5
votes
2 answers

Help with parsing a log file (ANTLR3)

I need a little guidance in writing a grammar to parse the log file of the game Aion. I've decided upon using Antlr3 (because it seems to be a tool that can do the job and I figured it's good for me to learn to use it). However, I've run into…
Unknown
  • 5,722
  • 5
  • 43
  • 64
5
votes
2 answers

Seeking very simple ANTLR error handling example when generating C code

I want to generate C code. I will not be reading from an input file, one line at a time (as, for instance, a compiler might). Rather, I will be parsing user input as it arrives, one line at a time. I would prefer to detect and handle bad input in…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
5
votes
1 answer

antlr 3.5.1 generates code for C runtime with undeclared indentifier: _empty. any fix available?

It seems that antlr-3.5.1-complete.jar and antlr-3.5.1-complete-no-st3.jar generates code targeting C runtime that has a lot of the "_empty" identifier in the DFA that is not defined anywhere. antlr-3.4 generates the code using dfa31_T_empty which…
Adrian Pop
  • 4,034
  • 13
  • 16
5
votes
2 answers

Error: Could not find or load main class org.antlr.Tool

I am a beginner in both java and ANTLR. I am trying to use ANTLR in Netbeans IDE. I was trying to run a sample example and did follow all the important steps required like setting the environment variable, including jar file and modifying…
user134816
  • 51
  • 1
  • 3
5
votes
1 answer

Query parsing in ANTLR for Lucene

Probably it will combine several questions, but the context is the same. Background: I need to implement custom query parsing for Lucene. The reason is that i dont store some fields in Lucene, but just keep them in a separate db, because they are…
NeatNerd
  • 2,305
  • 3
  • 26
  • 49
5
votes
2 answers

boolean and arithmetic expression grammar in ANTLR

I'm trying to write a grammar for arithmetic and boolean expressions. I don't understand what I'm doing wrong. For my grammar, ANTLR says: [fatal] rule logic_atom has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2. …
5
votes
1 answer

Catch-all second alternative for my start rule

I'm trying to write an ANTLR grammar for a little query language. Queries are a list of search terms restricted to specific fields: field1:a field2:b field3:c That's supposed to return a list of entities where field1 matches a, field2 matches b, and…
5
votes
3 answers

How to walk an AST with tail recursion in Clojure

I have an ANTLR3 AST which I need to traverse using a post-order, depth-first traversal which I have implemented as roughly the following Clojure: (defn walk-tree [^CommonTree node] (if (zero? (.getChildCount node)) (read-string (.getText…