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

How to get rid of " around my string in ANTLR?

When I get the token with these rules STRINGA : '"' (options {greedy=false;}: ESC | .)* '"'; STRINGB : '\'' (options {greedy=false;}: ESC | .)* '\''; it ends up grabbing 'text' instead of just text. I can easily remove the ' and ' myself but…
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
0
votes
1 answer

antlr, I can't seem to find how to match the rest of the line(including whitespace)

I have a text "ON something blah blah blah could be anything" I want to match the ON, something, and "blah blah blah could be anything" I have my tokens as ON : ('O'|'o')('N'|'n'); INDEX: (options {greedy=false;}: ESC | .)* WS : ( ' ' …
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
0
votes
0 answers

AST tree in antlr. Can I add a state object to it?

Right now, we have code that translates from one AST tree to their own tree. I would prefer to get rid of this second tree(it is hard enough to understand one tree, let alone two when you join a project as trees are complex as it is). One of the…
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
0
votes
2 answers

ANTLR Tree Walker should not output AST?

I have made an own language using ANTLR. The Grammar is complete, but I want to make a tree walker that verifies the input. But this doesn't work. When I (accidentally) used output=AST in the tree walker it compiles without error, but it doesn't…
user1255553
  • 960
  • 2
  • 15
  • 27
0
votes
2 answers

What is wrong with whitespaces in ANTLR?

I have really simple XML (HTML) parsing ANTLR grammar: wiki: ggg+; ggg: tag | text; tag: '<' tx=TEXT { System.out.println($tx.getText()); } '>'; text: tx=TEXT { System.out.println($tx.getText()); }; CHAR: ~('<'|'>'); TEXT: CHAR+; With such…
pablo
  • 384
  • 2
  • 5
  • 17
0
votes
1 answer

Building C target grammar parser, need to know how to include when compile

I am tring to build a parser (in C language) with antlrIDE on Windows 7 platform. I finished the grammar (.g of combined grammar), which automatically generates lexer and parser for me. However, I don't know how to compile the .c and .h file. I…
0
votes
1 answer

Finding Next Expected token If error occures ANTLR 3

I am using ANTLR 3 , I have a question is that How can i find the next expected token if any error is occurred in input . I have tried to override getErrorMessage(RecognitionException e, String[] tokenNames) of the Parser, I can get the error but i…
Vijay
  • 1,024
  • 6
  • 18
0
votes
1 answer

Identifier with > and Whitespaces in ANTLR possible?

I try to make a grammer with ANTLR with the following specifics. It can parse an identifier like: foo > bar > 67 where foo > bar is the identifier, because if > followed by a letter it contains to the identifier and else its a greater than…
Sebastian
  • 952
  • 1
  • 14
  • 41
0
votes
1 answer

I've written a ANTLR grammar, want to convert to JSON

I've created an ANTLR Grammar that properly makes trees of the file type associated with it. Now what? I don't really get how I make this .g file now parse something. How do I make it do it in my file system and what does it parse it to? Goal is to…
Jono
  • 3,393
  • 6
  • 33
  • 48
0
votes
1 answer

StringTemplate and Xtext

In my current work, I have written code generator using String Template without thinking about Parser ( I am instantiating Template files using direct Java Object). and code generator generator generates nice Java code. Now, I have started to write…
user-517752
  • 1,188
  • 5
  • 21
  • 54
0
votes
1 answer

ANTLR Grammar for literal string with length prefix

How do I write following BNF Grammar in ANTLR? literal = "{" number "}" CRLF *CHAR8 ; Number represents the number of CHAR8s For example {6}\r\nLENGTH should be mapped to "LENGTH" string. Will following work? literal: | '{' ('0'..'9')+…
Akash Kava
  • 39,066
  • 20
  • 121
  • 167
0
votes
1 answer

Antlr 3 can't deal with syntactic predicate

This problem has occurred to me many times. I do not completely understand the problem fully. My syntax looks like this: grammar Syntax; options { language = Java; backtrack = true; } rule: ('syntax' (INTEGER | HEX) ';')? (structure |…
NullData
  • 394
  • 2
  • 8
0
votes
0 answers

Antlr3 confusion about the word IS

I would like to ask if the word "IS" is a reserved word. Here is why I am asking. The language that I am trying to create a parser for is a priority language. I have an assignment that looks like this: %VARIABLE IS STRING Using the Antlr…
0
votes
1 answer

Using the ANTLR C target, how can I use actions to print tokens?

I'm new to ANTLR and having trouble with printing tokens using actions. I have the following grammar file: grammar SimpleGrammar; options { language = C; } prog : string { printf("hello\n"); printf($string.text); }; string : LETTER+; LETTER :…
Khutsi
  • 73
  • 1
  • 1
  • 6
0
votes
1 answer

Antlr syntactic predicate - mismatched character

I have the following grammar: SPACE : (' '|'\t'|'\n'|'\r')+ {$channel = HIDDEN;}; NAME_TAG : 'name'; IS_TAG : 'is'; START : 'START'; END : ('END START') => 'END START' ; WORD : 'A'..'Z'+; rule : START NAME_TAG IS_TAG WORD END; and want to…
1 2 3
60
61