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
2 answers

ANTLR: Can I have ',' be one token on one context, and another outside of said context?

Specifically, I am trying to implement a RegExp parser in ANTLR. Here are the relevant parts of my grammar: grammar JavaScriptRegExp; options { language = 'CSharp3'; } tokens { /* snip */ QUESTION = '?'; STAR = '*'; PLUS = '+'; …
John Gietzen
  • 48,783
  • 32
  • 145
  • 190
3
votes
1 answer

Special character handling in ANTLR lexer

I wrote the following grammar for string variable declaration. Strings are defined like anything between single quotes, but there must be a way to add a single quote to the string value by escaping using $ letter. grammar test; options { …
Overdose
  • 1,470
  • 3
  • 16
  • 29
2
votes
1 answer

antlr lexer rule matching a prefix of another rule

I am not sure that the issue is actually the prefixes, but here goes. I have these two rules in my grammar (among many others) DOT_T : '.' ; AND_T : '.AND.' | '.and.' ; and I need to parse strings like this: a.eq.b.and.c.ne.d c.append(b) this…
Milan
  • 272
  • 2
  • 12
2
votes
1 answer

Resolving possible ANTLR grammar ambiguities (And general improvement tips)

I'm having an issue building a grammar which is capable of parsing Python 3's AST dump format and converting it into an AST format that's easier for me to play around with. I decided to write an ANTLR grammar to do so, but I'm having an issue…
wibarr
  • 276
  • 1
  • 3
  • 13
2
votes
2 answers

Why is Antlr going into an infinite loop when processing my grammar

I created an ANTLR grammar for parsing mathematical expressions and a second one for evaluating them. As I thought building an AST and then re-parsing in order to actually evaluate it is sort of one operation too much, I wanted to refactor my…
Christofer Dutz
  • 2,305
  • 1
  • 23
  • 34
2
votes
1 answer

Antlr v3 error with parser/lexer rules

I am having problems with my Antlr grammar. I'm trying to write a parser rule for 'typedident' which can accept the following inputs: 'int a' or 'char a' The variable name 'a' is from my lexer rule 'IDENT' which is defined as follows: IDENT :…
Dan_Dan_Man
  • 504
  • 2
  • 6
  • 19
2
votes
0 answers

how to get all tokens from parser in antlr

I want to get all tokens from my parser and then I want to filter the output, getting a List of AST(myAST): ANTLRStringStream stream = new ANTLRStringStream("P + 1 + F(A + 3)"); MyLexer lexer = new MyLexer (stream); MyParser parser = new…
Zinov
  • 3,817
  • 5
  • 36
  • 70
2
votes
1 answer

Why two ANLTR parsers interpret the same string differently?

I have the following ANTLR grammar: grammar Tasks; options { language = Java; } tokens { TODO = 'TODO'; } plan : block; block: '(' TODO ( TODO | block )* ')'; WS : ( ' ' | '\t' | '\r' | '\n' | '\v' ) { $channel = HIDDEN; } ; I and the…
dzieciou
  • 4,049
  • 8
  • 41
  • 85
2
votes
2 answers

Add quoted strings support to Antlr3 grammar

I'm trying to implement a grammar for parsing queries. Single query consists of items where each item can be either name or name-ref. name is either mystring (only letters, no spaces) or "my long string" (letters and spaces, always quoted). name-ref…
Andrey Agibalov
  • 7,624
  • 8
  • 66
  • 111
2
votes
1 answer

How to to create / specify the AST input for testing a tree grammar with ANTLRWorks?

Background: I have created an ANTLR grammar. I am able to test and debug it with ANTLRWorks and have verified that the parser creates the AST that I had in my mind. Now, I want to write a tree grammar for the AST, parse the tree and debug the tree…
nilo de roock
  • 4,077
  • 4
  • 34
  • 62
2
votes
1 answer

ANTLR for C# product private methods for parsing rules

I'm trying to use ANTLR to create a parser for simple language using C# code generation. I have successfully product MyLangLexer.cs and MyLangParser.cs with very very simple rule called 'rule'. The problem is that the generated method rule() is…
Ido Ran
  • 10,584
  • 17
  • 80
  • 143
2
votes
1 answer

ANTLR - allowing for incomplete grammar

I'm using ANTLR to parse strings of mathematical expressions and tag them using MathML. Right now I have the grammar below. Now I have three questions: The grammar allows for complete expressions like 2*(3+4). I want it to also allow incomplete…
rickythefox
  • 6,601
  • 6
  • 40
  • 62
2
votes
1 answer

How can I implement a parser rule in ANTLR that combines two nodes into one?

The second alternative ((1-9)(0-9)) of the following parser rule results in two nodes in the abstract syntax tree. oneToHundred : ('1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9') |…
Jennifer Owens
  • 4,044
  • 5
  • 19
  • 22
2
votes
2 answers

How to resolve this parsing ambiguitiy in Antlr3

Hopefully this is just the right amount of information to help me solve this problem. Given the following ANTLR3 syntax grammar mygrammar; program : statement* | function*; function : ID '(' args ')' '->' statement+ (','statement+) '.' ; args…
user177800
2
votes
3 answers

java Main < inputfile does not work (Main is a java Class to test an ANTLR grammar)

I am trying to test an ANTLR grammar with such a standard test rig import org.antlr.runtime.*; class Main { public static void main(String[] args) throws Exception { SampleLexer lexer = new SampleLexer(new ANTLRStringStream(args[0])); …
zell
  • 9,830
  • 10
  • 62
  • 115