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

The interpreter is disabled

I wanted to create a simple compiler using ANTLR 3.5 and java 1.6 + I added jar files but I am getting this error and "Reason could not create a grammar" but I don't understand why any help? It is not the whole code but I tried to the code by bits…
0
votes
1 answer

ANTLR3 String Literals and Disallowing Nested Comments

I've recently been tasked with writing an ANTLR3 grammar for a fictional language. Everything else seems fine, but I've a couple of minor issues which I could do with some help with: 1) Comments are between '/*' and '*/', and may not be nested. I…
0
votes
0 answers

Antlr parsing hexadecimal number

I have following grammar for parsing time expressions like '1 day 2 hour'. time : timeLiteral | FLOAT | INTEGER ; timeLiteral : dayExpr hourExpr? minuteExpr? ; dayExpr : timeVal ('days' | 'day') ; hourExpr : timeVal ('hour'|'hours')…
Manish
  • 33
  • 1
  • 3
0
votes
1 answer

ANTLR Tree Grammar -> Generated java class has errors (getText)

When i generate my Tree Parser, i get errors which says the method getText() is undefined for the type object. Can't enter the whole class here since its about 500000 Characters. But these are the similar error lines I get is public int…
Undisputed007
  • 639
  • 1
  • 10
  • 31
0
votes
0 answers

ANTLR3 Reduce memory usage

I have written a parser in ANTLR3. Targets are both Java and CSharp3. Both are using a lot of memory at parse time. The files I am parsing have a size between 5 and 40 MB. Memory Usage is far beyond that, iirc correctly a .NET Memory profiler showed…
metacircle
  • 2,438
  • 4
  • 25
  • 39
0
votes
1 answer

ANTLR grammar matches incompatible rule instead of throwing NoViableAltException

I have the following ANTLR grammar that forms part of a larger expression parser: grammar ProblemTest; atom : constant | propertyname; constant: (INT+ | BOOL | STRING | DATETIME); propertyname : IDENTIFIER ('/'…
beyond-code
  • 1,423
  • 1
  • 12
  • 20
0
votes
1 answer

How to allow an identifer which can start with a digit without causing MismatchedTokenException

I want to match the following input: statement span=1m 0_dur=12 with the following grammar: options { language = Java; output=AST; ASTLabelType=CommonTree; } statement :'statement' 'span' '=' INTEGER 'm' ident '=' INTEGER; INTEGER : DIGIT+ …
Aeris
  • 45
  • 3
0
votes
1 answer

ANTLR3 grammar works with spaces but gives NoViableAltException when I omit spaces

I need to parse user input that defines queries to a system. The heart of such queries are triplets which can also be combined to form complex queries (the idea is to restrict a result set to only show entries which satisfy these queries). Here are…
peedee
  • 3,257
  • 3
  • 24
  • 42
0
votes
1 answer

Antlr parser for custom requirement

I have a very peculiar requirement to parse inputs using ANTLR. I would like to be able to parse expressions like; Correct Inputs user name user_name user-name | EATALL any thing could come here/ok | EATALL ... Invalid…
consumer
  • 709
  • 3
  • 7
  • 19
0
votes
1 answer

How can I limit the length of a token in antlr3?

I am trying to build a compiler using antlr and for now I want to limit the length of the identifiers in my language to less than 9. My code now look like this: IDENTIFIER: CHAR(CHAR|INT)*; where CHAR and INT are both fragments. I am wondering if…
Bob Fang
  • 6,963
  • 10
  • 39
  • 72
0
votes
2 answers

How to get access to current tree node inside grammar?

The question is about how to get access to current tree node inside {"action"} block in the grammar. I'm talking about Java target, so inside generated rule-method I'd like to gain access to object root_1 (see below, standard generated code, SUBJECT…
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
0
votes
1 answer

Using Tree Walker with Boolean checks + capturing the whole expression

I have actually two questions that I hope can be answered as they are semi-dependent on my work. Below is the grammar + tree grammar + Java test file. What I am actually trying to achieve is the following: Question 1: I have a grammar that parses…
Andy M
  • 119
  • 9
0
votes
0 answers

ANTLR: bug in setUnknownTokenBoundaries()?

CommonTree#setUnknownTokenBoundaries() updates token boundaries of an AST node by using the boundaries of the node's first and last child. This seems to assume that the children of the AST are ordered by the token order. However, such an ordering…
Josh
  • 413
  • 2
  • 7
0
votes
1 answer

ANTLR: rule Tokens has non-LL(*) decision due to recursive rule invocations reachable from alts

I'm learning about parsing/lexing in a course about Computer Science. For that we are using ANTLR. I'm modifying an XML-language, so it's no longer ambigious, but when I make the changes to the grammer, ANTLR complains. I know this specific…
Andersnk
  • 857
  • 11
  • 25
0
votes
1 answer

ANTLR grammar: already known token used within not known expressions

I have a combined ANTLR grammar, which shall be used for parsing several lines of information. It is possible that at the time of writing the grammar, not all lines are already completely known and defined within the grammar. This shall be…