Questions tagged [antlr2]

Questions related about version 2 of ANother Tool for Language Recognition.

Questions related to version 2 of 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

Related tags

29 questions
5
votes
2 answers

Migrating ANTLR v2 grammar to ANTLR v4

We have a grammar written for antlr V2 and I would like to migrate to antlr v4. Is there any migration Guide? I would also like to know modifications of existing V2 grammar so that we utilize v4 features well.
Loren Cahlander
  • 1,257
  • 1
  • 10
  • 24
3
votes
1 answer

Spurious nondeterminism warnings from antlr 2.7.6

I'm trying to create a simple expression parser with antlr 2.7.6 and am getting some nondeterminism warnings during compilation. The generated java source seems to work exactly as i want it, but I would like to know if its possible to suppress this…
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
3
votes
0 answers

My ANTLR grammar with optional token fails on simple statements

I use ANTLR 2.7 to create a grammar to parse simple expressions like 1 2% (3%) (4) ((5)) ((6%)) It's simple numbers which can have paranthesis and optional percent characters My grammar looks like this: class MyParser extends Parser; options { …
JayTheKay
  • 1,463
  • 12
  • 22
1
vote
0 answers

ANTLR 2 Token Stream Multiplexing: why are my tokens out of order?

I am writing grammar for multi line strings (Text Block) in java. The delimiter for the start and end of a text block is triple quotes. I can successfully parse and build the AST for the text blocks and its content, except for one issue: the…
1
vote
0 answers

Negated lexer rules/tokens

I am trying to match (and ignore) c-style block comments. To me the sequence is (1) /* followed by (2) anything other than /* or */ until (3) */. BLOCK_COMMENT_START : "/*" ; BLOCK_COMMENT_END : "*/" ; BLOCK_COMMENT :…
Steve Ebersole
  • 9,339
  • 2
  • 48
  • 46
1
vote
1 answer

Cannot understand Antlr tool error parsing grammar

// Parser statement : DELIMITER* statementPart+ DELIMITER* (EOL { newline(); })? ; // Lexer DELIMITER : ';' ; sql-stmt.g:85:13: rule classDef trapped: sql-stmt.g:85:13: unexpected token: DELIMITER Line 85 is the statement rule. …
Steve Ebersole
  • 9,339
  • 2
  • 48
  • 46
1
vote
1 answer

Intermediate and object code generation with ANTLR

As part of the programming assignments of our compilers related class. I've proposed to my teacher to use ANTLR instead of flex bison and here he ask me to ensure that it does all what we want, i.e lexical, syntactical and semantic analysis (thre…
Haroun Mohammedi
  • 2,404
  • 12
  • 25
1
vote
1 answer

Custom error handler methods fail to handle token recognition errors

Here is my .g4 file: grammar Hello; start : compilation; compilation : sql*; sql : altercommand; altercommand : ALTER TABLE SEMICOLON; ALTER: 'alter'; TABLE: 'table'; SEMICOLON : ';'; My main class: public class Main { public static void…
Adib Rajiwate
  • 405
  • 4
  • 19
1
vote
1 answer

Consuming Error tokens in antlr4

Here is my grammar i am trying to give input as alter table ; everything works fine but when i give altasder table; alter table ; it gives me an error on first string as expected but i want is to parse the second command ignoring the first…
Adib Rajiwate
  • 405
  • 4
  • 19
1
vote
1 answer

rewriting AST Action Translation to ANTLR4

I have a grammar file written in antlr2 syntax and need help understanding how to rewrite some of the parser rules in antlr4 syntax. I know antlr4 eliminated the need for building AST so I'm not sure what to do with the rules that are AST action…
Dorothyy
  • 299
  • 1
  • 4
  • 13
1
vote
1 answer

antlr2 to antlr4 class specifier, options, TOKENS and more

I need to rewrite a grammar file from antlr2 syntax to antlr4 syntax and have the following questions. 1) Bart Kiers states there is a strict order: grammar, options, tokens, @header, @members in this SO post. This antlr2.org post disagrees stating…
Dorothyy
  • 299
  • 1
  • 4
  • 13
1
vote
0 answers

Why this errors in Eclipse (java) using ANTLR

I'm using ANTLR 2.7.6 and when i run next class Main.java /** * @param args */ public static void main(String[] args) { FileInputStream fis; try { fis = new FileInputStream("src/main/entrada.txt"); Analex analex = null; …
Danay
  • 21
  • 2
1
vote
1 answer

ANTLR 2 Solving keywords issue

I have a rule which expects a STRING from the user. Currently when the user gives a keyword that I have defined in my grammar, parser gives a segmentation fault. For ex : sampleClause: calc! strName {##->setType(SAMPLE_CLAUSE);}; strName :…
user2761431
  • 925
  • 2
  • 11
  • 26
1
vote
0 answers

Java 8 compile-time heap requirements/settings

Recently, I upgraded my development environment from Java 6 to Java 8. During compilation (over 4,000 source files), I was encountering OutOfMemory errors when compiling with Java 8. In order to work around this issue, I had to increase my ANT javac…
hfontanez
  • 5,774
  • 2
  • 25
  • 37
1
vote
1 answer

How to convert from antlr v2 to v3 grammar?

I have the below grammar in v2 of ANTLR, I need help to convert it to v3 expression : ( simpleLookup | lookup ) ( x:LSQRBRACKET^ {#x.setType(ATTRIBUTES);} attributesExpr RSQRBRACKET! )? ;enter code here Actually I tried below but not sure if…
Rakesh
  • 37
  • 7
1
2