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

antlr3 - Generating a Parse Tree

I'm having trouble figuring out the antlr3 API so I can generate and use a parse tree in some javascript code. When I open the grammar file using antlrWorks (their IDE), the interpreter is able to show me the parse tree, and it's even correct. I'm…
HugeAntlrs
  • 33
  • 1
  • 3
3
votes
1 answer

ANTLR Nested Functions

Is ANTLR right for this project? I'm looking to process and transform a string entered in by a user which may include custom functions. For example, the user might write something like $CAPITALIZE('word') in a string and I want to perform the…
Dan Whitehouse
  • 548
  • 1
  • 6
  • 18
3
votes
2 answers

How to make antlr3 parsing "forward?"

I'm trying to parse the following grammar with Antlr3: String... java.lang.String java.lang.Object... This is my .g file (part of it): doc: name DOTS? EOF; name: ATOM ('.' ATOM)*; ATOM: ('a' .. 'z' | 'A' .. 'Z')+; DOTS: '...'; It doesn't work.…
yegor256
  • 102,010
  • 123
  • 446
  • 597
3
votes
1 answer

ANTLR3: Parameters and semantic predicates ("cannot find symbol", "illegal start of type")

I would like to realize a "branch" in ANTLR3. I figured using branch[boolean is_a] : ({ $is_a}? => a) | ({!$is_a}? => b); would do the trick, but I get the compiling errors "cannot find symbol" and "illegal start of type", because in the in…
Kijewski
  • 25,517
  • 12
  • 101
  • 143
3
votes
1 answer

Generate AST in the form of a dot file

I am working with ANTLR4 to generate AST of a java source code and i had to move to ANTLR3 because i was not getting much help and documentation and it was really tough to proceed.I managed to generate AST but not in a visual format. Then i came…
Satnam Sandhu
  • 610
  • 1
  • 10
  • 25
3
votes
1 answer

JAVA Tree parser for ANTLR

I want to make a JAVA AST parser and i came across this extremely useful answer. So as per the instructions i created all the files and there were no errors generating the lexer and parser using the Java.g file but when compiling *.java file i get…
Satnam Sandhu
  • 610
  • 1
  • 10
  • 25
3
votes
1 answer

Antlr4 - representing syntactic predicates that examine arbitrary number of tokens

In Antlr3, I have the following grammar: ruleA: (ruleBStart) => ruleB | ruleC ; For the sake of simplicity let's assume ruleB is the grammar for SELECT statement in SQL, but could be nested in an arbitrary number of LPARENs. This is easy to…
Cod.ie
  • 380
  • 5
  • 14
3
votes
0 answers

Converting Antlr3 Syntactic Predicates to equivalent grammar in Antlr4, when number of syntactic predicates is large

I have Antlr3 parser rule that looks like this: ruleA: (TOKEN_1) => TOKEN_1 ruleToken1 | (TOKEN_2) => TOKEN_2 ruleToken2 .... .... | genericRuleA ; Assume for a moment that the tokens and rules are…
Cod.ie
  • 380
  • 5
  • 14
3
votes
1 answer

Where Are All the Grammar Options in Antlr3?

In Antlr2 there were numerous grammar options that could be set (reference). Now in Antlr3 we have like 1/3 of the amount of options (reference). So I have two questions concerning this: Does anyone know why so many options were taken out and are…
3
votes
2 answers

how to get the line number in an ANTLR3 TreeParser

i'm trying to get line number in an ANTLR3 tree grammar (the code generated by ANTLR3 is of the TreeParser class). google only found solutions for ANTLR2 which sadly don't work in ANTLR3. to clarify i'm trying to access the line number in the .g…
danny
  • 71
  • 6
3
votes
1 answer

ANTLR Tree Grammar and StringTemplate Code Translation

I am working on a code translation project with a sample ANTLR tree grammar as: start: ^(PROGRAM declaration+) -> program_decl_tmpl(); declaration: class_decl | interface_decl; class_decl: ^(CLASS ^(ID…
nobeh
  • 9,784
  • 10
  • 49
  • 66
3
votes
1 answer

How to get the token attributes in Antlr-4 lexer rule's action

I am new to Antlr-4, but have some idea about Antlr-3, where the lexer could be created without the need of any parser rule; in order to match a lexer rule by matching some tokens like: CLASS: 'Class' WS+ id=ID { System.out.println($id.text); } ID :…
Kishore_2021
  • 645
  • 12
  • 38
3
votes
0 answers

Backtracking lexer for ANTLR

I'm extending a JavaScript ANTLR grammar that uses the C target to handle JScript's conditional compilation comments, i.e. /*@cc_on ... @*/. These need to be handled separately from normal block comments since /*@cc_on /* hello */ @*/ results in a…
BruceBerry
  • 1,166
  • 1
  • 9
  • 21
3
votes
1 answer

Natty converting from anlr3 to antlr 4

as I'm new to antlr I have plenty of problems with syntactic predicates. I'v been trying to convert this grammar,which is part of natty grammar, in order to parse it with antlr4,I really got confused how to change it in a meaningful way. date_time …
3
votes
0 answers

Antlr3 with C++ target: invalid conversion from const CommonTokenType*

I'm trying to get a super-simple grammar working for ANTLR3 with a C++ target. I'm finding that if I refer to any variables in my action, I get the following error: invalid conversion from ‘const CommonTokenType* {aka const…
Daniel Bigham
  • 187
  • 3
  • 8