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

ANTLR Template translator match part of grammar

I wrote a grammar for a language and now I want to treat some syntactic sugar constructions, for that I was thinking of writing a template translator. The problem is I want my template grammar to translate only some constructions of the language and…
John Retallack
  • 1,498
  • 2
  • 19
  • 31
2
votes
1 answer

How to transform postfix_expression in ANTLR C grammar to AST?

I'm learning ANTLR by modifying the C grammar and trying something interests myself. The C grammar I started with is from: http://www.antlr.org/grammar/1153358328744/C.g Now I want to transform postfix_expression to its corresponding AST but haven't…
Xiao Jia
  • 4,169
  • 2
  • 29
  • 47
2
votes
1 answer

ANTLR3 common values in 2 different domain values

I need to define a language-parser for the following search criteria: CRITERIA_1= AND/OR CRITERIA_2=; Where can have values from 1-50 and can be from the following set (5, A, B, C) -…
dcg
  • 1,144
  • 1
  • 22
  • 38
2
votes
1 answer

All ANTLR grammars produce error "no viable alternative at input ''"

I am needing to parse a small expression language (and, or, not, parens change precedence) so picked ANTLR for the task, I made good progress (ANTLRWorks is very nice for a newbie). I used some Getting Starting references from the antlr website and…
Michael
  • 2,683
  • 28
  • 30
2
votes
1 answer

How to make an ANTLR 3 work in VS 2010?

Can someone instruct me step by step how to install ANTLR 3 in VS2010, then add grammar to a project so it will generate lexer and parser every time I make a change to a project?
Zbysio
  • 21
  • 1
2
votes
2 answers

Get active Antlr rule

Is it possible to get the "active" ANTLR rule from which a action method was called? Something like this log-function in Antlr-Pseudo-Code which should show the start and end position of some rules without hand over the $start- and $end-tokens with…
Sonson
  • 1,129
  • 1
  • 11
  • 14
2
votes
2 answers

ANTLR: Define new channel in grammar

I know it is possible to switch between the default and hidden token channels in an ANTLR grammar, but lets say I want a third channel. How can I define a new token channel in the gramar? For instance, lets say I want a channel named ALTERNATIVE.
Matthew Sowders
  • 1,640
  • 1
  • 19
  • 32
2
votes
1 answer

Is there a way to extract tokens in order with ANTLR?

Hi I'm currently trying to extract all tokens from ANTLR in C#, i'm using Antlr4.CodeGenerator and Antlr4.Runtime packages. I want them structured in a way i can manipulate them, change their content and so on. I've tried using listeners and…
2
votes
1 answer

antlr3 NOT rule

negExpression : (NOT^)* primitiveElement ; Is the rule I have. I now have this code: !!(1==1) I expected I would end up with this tree: NOT | NOT | == / \ 1 1 However, in Antlr3, it seems the tree ends up like NOT / \ NOT == …
Cine
  • 4,255
  • 26
  • 46
2
votes
1 answer

Multiple alternatives with the same label, only the last gets anything assigned to it

I have some non-reserved keywords I'm matching with rules like: kFOO = {self.input.LT(1).text.lower() == 'foo'}? ID; Where the ID token is a standard alpha-numeric string. These kinds of rules work great, except when I try to do something like…
Glenn Moss
  • 6,812
  • 6
  • 29
  • 23
2
votes
1 answer

Error when compiling with ANTLR in Visual C# Express 2010

I'm trying to build an application in C# that parses (using ANTLR) a C source file and returns me an AST with all the functions and stuff. I did what was explained here : http://www.antlr.org/wiki/pages/viewpage.action?pageId=557075# But after doing…
Leo
  • 500
  • 5
  • 15
2
votes
1 answer

ANTLR no viable alternative at input '/'

Okay, I'm really confused about this error. I know in the past having a '/' as a token in a rule hasn't produced any errors. However, this is simply baffling. Here is my grammar: grammar LilWildC; options { language = Java; } @header { …
Mateo
  • 1,920
  • 2
  • 21
  • 27
2
votes
2 answers

ANTLR generating empty conditions

I'm trying to learn to use ANTLR, but I cannot figure out what's wrong with my code in this case. I hope this will be really easy for anyone with some experience with it. This is the grammar (really short). grammar SmallTest; @header { package…
Trylks
  • 1,458
  • 2
  • 18
  • 31
2
votes
1 answer

Problem with an antlr grammar

I'm trying to figure out the grammar for the following syntax. foreach where x = 1 when some_variable = true where x = 2 when some_variable = false where y = 0 print z // Main block when none //…
Shaung
  • 508
  • 4
  • 11
2
votes
1 answer

Use of StringTemplate in Antlr

I would have this problem : Given this rules defField: type VAR ( ',' VAR)* SEP ; VAR : ('a'..'z'|'A'..'Z')+ ; type: 'Number'|'String' ; SEP : '\n'|';' ; where I have to do is to associate a template with a rule "defField", that…
kafka
  • 949
  • 12
  • 27