2

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 following string:

(TODO (TODO TODO (TODO) TODO))

It is sucessfully parsed by the parser generated by ANTRL from the grammar, e.g., using the following demo:

   import org.antlr.runtime.ANTLRStringStream;
   import org.antlr.runtime.CommonTokenStream;

   public class ANTLRDemo {
     public static void main(String[] args) throws Exception {
       ANTLRStringStream in = new ANTLRStringStream("(TODO (TODO TODO (TODO) TODO))");
       TasksLexer lexer = new TasksLexer(in);
       CommonTokenStream tokens = new CommonTokenStream(lexer);
       TasksParser parser = new TasksParser(tokens);
       parser.block();
     }
   } 

However, Eclipse plugin ANTLR IDE Tools 2.1.1 returns error when interpreting the same string:

MismatchedTokenException: line 1:6 mismatched input '(' expecting '\u0007'

What can be the reason of this inconsistency between both programs?

dzieciou
  • 4,049
  • 8
  • 41
  • 85

1 Answers1

1

What can be the reason of this inconsistency between both programs?

The interpreter is buggy: there's nothing wrong with your grammar.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288