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

syntactic predicates - Upgrading from Antlr 3 to Antlr 4

I have syntactic predicated that I have to convert into the Antlr 4. The grammar is not written my me so I have no idea how to convert them in a meaningful way. These are the main variations of the grammar that I have to convert. 1. …
diyoda_
  • 5,274
  • 8
  • 57
  • 89
3
votes
2 answers

How to serialise an antlr3 AST

I have just started using antlr3 and am trying to serialize the AST output of a .g grammar. Thanks, Lezan
Lezan
  • 667
  • 2
  • 7
  • 20
3
votes
1 answer

ANTLR 3, what does LT!* mean?

I was looking at the code for a Javascript grammar written in ANTLR 3, http://www.antlr3.org/grammar/1206736738015/JavaScript.g In many instances I found program : LT!* sourceElements LT!* EOF! ; what does LT!* mean ? EDIT: From…
Gautam
  • 7,868
  • 12
  • 64
  • 105
3
votes
1 answer

ANTLR: match tokens with whitespace

I want to match an expression with white space as single token. Following are my lexer rules: HOUR : (INTEGER) ('hour'|'hours') ; MINUTE : (INTEGER) ('min'|'minute'|'minutes') ; INTEGER : '0' 'x' (HEXDIGIT)+ | (DIGIT)+ ; fragment DIGIT :…
Manish
  • 33
  • 1
  • 3
3
votes
2 answers

antlr identifier name same as pre-defined function name cause MismatchedTokenException

I have defined a ANTLR grammer: grammar test5; stats_statement : STATS IDENT ASSIGN_SYM functions_stats ; functions_stats : COUNT LPAREN IDENT RPAREN ; STATS : 'STATS' ; COUNT : 'count' ; IDENT : (LETTER | '_')…
Aeris
  • 45
  • 3
3
votes
1 answer

Tree construction: propagate a subtree to child

Suppose that I have this simple and meaningless grammar: propagate : what^ where*; what : CHAR^; where : NUMBER -> ^(PLUS NUMBER); NUMBER : '0'..'9'; CHAR : 'a'..'z'; PLUS : '+'; If it…
marka.thore
  • 2,795
  • 2
  • 20
  • 35
3
votes
1 answer

How to implement a computer language translator using two separate grammars

I want to create a computer language translator between two languages LANG1 and LANG2. More specifically, I want to translate code written in LANG1 into source code in LANG2. I have the BNF Grammar for both LANG1 and LANG2. LANG1 is a small DSL I…
Homunculus Reticulli
  • 65,167
  • 81
  • 216
  • 341
3
votes
1 answer

Antlr3 matching tokens without whitespace

Given the input "term >1", the number(1) and comparison operator(>) should generate seperate nodes in an AST. How can this be achieved? In my tests matching only occured if "c" and "1" where seperated with a space like so "term < 1". Current…
Th 00 mÄ s
  • 3,776
  • 1
  • 27
  • 46
3
votes
1 answer

ANTLR best way to include meta-data in lexing/parsing (custom objects, kind of annotation)

I plan to include text metadata (like bold, font-size, etc.) in the process of parsing to achieve better recognition. For instance, I have a given structure, where a word on its own line word/r/n which is bold and sized 24px, is the title for some…
turrican
  • 41
  • 4
3
votes
2 answers

ANTLR grammar for variables

Have a look at my grammar grammar protocol; options { language = Java; output = AST; } //imaginary tokens tokens{ BOOL; CHAR; STRING; } parse : declaration ; declaration : variable ; variable : …
Rizwan Abbasi
  • 151
  • 2
  • 10
3
votes
4 answers

How to get rid of useless nodes from this AST tree?

I have already looked at this question and even though the question titles seem to be the same; it doesn't answer my question, at least not in any way that I can understand. Parsing Math Here is what I am parsing: PI -> 3.14. Number area(Number…
user177800
3
votes
1 answer

How do I replace a missing optional token with a default?

Imagine I have the following rules. I want to make TYPE_ID optional, but replace it with some default value in the AST if it is missing. assignment : TYPE_ID? ID '->' expression TYPE_ID : ('A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9')* ; For example I…
user177800
3
votes
1 answer

How do I install ANTLR IDE with Eclipse Juno and PDT (PHP)

I develop in both PHP and Java. Eclipse PDT appears to require DLTK 4.0, which it has no problem getting. ANTLR IDE appears to require DLTK3. I've tried copying the plugins 3.0 into my Eclipse plugins / features…
Arcymag
  • 1,037
  • 1
  • 8
  • 18
3
votes
1 answer

ANTLR lexer exclude string

Hej everyone I'm trying to build a lexer used to parse a domain specific language. I have a set of reserved token (fragment RESERVED) and an escape character. The lexer should split whenever a reserved token shows up that is not escaped. a…
user1549692
  • 93
  • 1
  • 7
3
votes
2 answers

ANTLR making a grammar for parsing insert/update/delete SQL query

I am new to ANTLR & grammar writing. My requirement is to parse insert/update/delete SQL queries to get details like which table is being update/inserted/deleting a row, list of columns & their values etc. Yes there is a good documentation of ANTLR,…
hemu
  • 3,199
  • 3
  • 44
  • 66