Antlr MismatchedSetException During Interpretation

Posted by user1646481 on Stack Overflow See other posts from Stack Overflow or by user1646481
Published on 2012-11-22T10:39:40Z Indexed on 2012/11/22 11:00 UTC
Read the original article Hit count: 248

Filed under:
|

I am new to Antlr and I have defined a basic grammar using Antlr 3. The grammar compiles and ANTLRWorks generates the Parser and Lexer code without any problems.

The grammar can be seen below:

grammar i;

@header {
package i;
}

module      : 'Module1'| 'Module2';
object      : 'I';
objectType  : 'Name';
filters         : EMPTY | 'WHERE' module;
table       : module object objectType;
STRING      : ('a'..'z'|'A'..'Z')+;
EMPTY           : ' ';

The problem is that when I interpret the table Parser I get a MismatchedSetException. This is due to having the EMPTY. As soon as I remove EMPTY from the grammar, the interpretation works. I have looked on the Antlr website and some other examples and the Empty space is ' '. I am not sure what to do. I need this EMPTY.

As soon as I change the EMPTY to be the following:

EMPTY : '';

instead of:

EMPTY : ' ';

It actually interprets it. However, I am getting the following Exception:

Interpreting...
[10:57:23] problem matching token at 1:4 NoViableAltException(' '@[1:1: Tokens : ( T__4 | T__5 | T__6 | T__7 | T__8 | T__9 | T__10 | T__11 | T__12 | T__13 | T__14 | T__15 | T__16 );])
[10:57:23] problem matching token at 1:9 NoViableAltException(' '@[1:1: Tokens : ( T__4 | T__5 | T__6 | T__7 | T__8 | T__9 | T__10 | T__11 | T__12 | T__13 | T__14 | T__15 | T__16 );])

When I take out the EMPTY, there are no problems at all.

I hope you can help.

© Stack Overflow or respective owner

Related posts about java

Related posts about antlr