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
7
votes
3 answers

How do I get an Antlr Parser rule to read from both default AND hidden channel

I use the normal whitespace separation into the hidden channel but I have one rule where I would like to include any whitespace for later processing but any example I have found requires some very strange manual coding. Is there no easy option to…
David Mårtensson
  • 7,550
  • 4
  • 31
  • 47
7
votes
2 answers

How do I match unicode characters in antlr

I am trying to pick out all tokens in a text and need to match all Ascii and Unicode characters, so here is how I have laid them out. fragment CHAR : ('A'..'Z') | ('a'..'z'); fragment DIGIT : ('0'..'9'); fragment UNICODE : …
Lezan
  • 667
  • 2
  • 7
  • 20
7
votes
2 answers

"FOLLOW_set_in_"... is undefined in generated parser

I have written a grammar for vaguely Java-like DSL. While there are still some issues with it (it doesn't recognize all the inputs as I would want it to), what concerns me most is that the generated C code is not compilable. I use AntlrWorks 1.5…
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
7
votes
2 answers

Is C++ code generation in ANTLR 3.2 ready?

I was trying hard to make ANTLR 3.2 generate parser/lexer in C++. It was fruitless. Things went well with Java & C though. I was using this tutorial to get started: http://www.ibm.com/developerworks/aix/library/au-c_plusplus_antlr/index.html When I…
Viet
  • 17,944
  • 33
  • 103
  • 135
7
votes
4 answers

Testing ANTLR Grammar

So I've been making a grammar in Eclipse with ANTLR v3.4 and I've made one that works and I want to make sure when I edit it everything still works. I can go into the interpretter everytime but that seems like a huge waste of time. Questions: I've…
Jono
  • 3,393
  • 6
  • 33
  • 48
6
votes
1 answer

How can I differentiate between reserved words and variables using ANTLR?

I'm using ANTLR to tokenize a simple grammar, and need to differentiate between an ID: ID : LETTER (LETTER | DIGIT)* ; fragment DIGIT : '0'..'9' ; fragment LETTER : 'a'..'z' | 'A'..'Z' ; and a RESERVED_WORD: RESERVED_WORD : 'class' |…
Chris Covert
  • 2,684
  • 3
  • 24
  • 31
6
votes
2 answers

How can I simplify token prediction DFA?

Lexer DFA results in "code too large" error I'm trying to parse Java Server Pages using ANTLR 3. Java has a limit of 64k for the byte code of a single method, and I keep running into a "code too large" error when compiling the Java source generated…
erickson
  • 265,237
  • 58
  • 395
  • 493
6
votes
1 answer

Get original text of an Antlr rule

I am an ANTLR beginner and want to calculate a SHA1-Hash of symbols. My simplified example grammar: grammar Example; method @after{calculateSha1($text); }: 'call' ID; ID: 'A'..'Z'+; WS: (' '|'\n'|'\r')+ {skip(); } COMMENT: '/*' (options…
Sonson
  • 1,129
  • 1
  • 11
  • 14
6
votes
1 answer

ANTLR: Syntax Errors are ignored when running parser programmatically

I am currently creating a more or less simple expression evaluator using ANTLR. My grammar is straightforward (at least i hope so) and looks like this: grammar SXLGrammar; options { language = Java; output = AST; } tokens { OR = 'OR'; …
huzi
  • 180
  • 2
  • 13
6
votes
1 answer

ANTLR grammar for defining/calling multi-parameter functions

I have a grammar that I'd like to include multi-parameter functions in (like f(x,y)). I'm using AST output with my own tree parser. Right now my parameter list production is paramdefs: (ID COMMA)* ID ; This works fine, but the AST output…
Cajunluke
  • 3,103
  • 28
  • 28
6
votes
1 answer

if then else conditional evaluation

I have a language which basically is meant to map columns to a new structure in an array. The language is meant for product managers to define mappings without having to know a lot of programming details. I'm sure there is a lot more to improve here…
Jasper Floor
  • 4,632
  • 6
  • 26
  • 21
6
votes
1 answer

antlr match input using multiple alternatives error

I'm receiving a warning when antlr v3.1 compiles on this rule sentence : (CAPITAL_LETTERS_AND_NUMBERS | INT | ANY_WORD ) ( INT | CAPITAL_LETTERS_AND_NUMBERS | ANY_WORD )*; The warning is: 5:2: Decision can match input such as…
probably at the beach
  • 14,489
  • 16
  • 75
  • 116
6
votes
3 answers

Why my antlr lexer java class is "code too large"?

This is the lexer in Antlr (sorry for a long file): lexer grammar SqlServerDialectLexer; /* T-SQL words */ AND: 'AND'; BIGINT: 'BIGINT'; BIT: 'BIT'; CASE: 'CASE'; CHAR: 'CHAR'; COUNT: 'COUNT'; CREATE: 'CREATE'; CURRENT_TIMESTAMP:…
yegor256
  • 102,010
  • 123
  • 446
  • 597
6
votes
1 answer

Parsing Newlines, EOF as End-of-Statement Marker with ANTLR3

My question is in regards to running the following grammar in ANTLRWorks: INT :('0'..'9')+; SEMICOLON: ';'; NEWLINE: ('\r\n'|'\n'|'\r'); STMTEND: (SEMICOLON (NEWLINE)*|NEWLINE+); statement : STMTEND | INT STMTEND ; program:…
aliahy
  • 509
  • 6
  • 15
6
votes
4 answers

How can I modify the text of tokens in a CommonTokenStream with ANTLR?

I'm trying to learn ANTLR and at the same time use it for a current project. I've gotten to the point where I can run the lexer on a chunk of code and output it to a CommonTokenStream. This is working fine, and I've verified that the source text is…
mmcdole
  • 91,488
  • 60
  • 186
  • 222
1 2
3
60 61