1

I'm excepting to write between brackets letters/ numbers. However, my Grammar is not accepting numbers.

The rules are defined in my grammar file like this:

id_list
    :   '(' ID (',' ID)* ')' 
    ->  ID+
    ;

ID
    :   ('a'..'z' | 'A'..'Z' | '_' | '.' | '-' | Digit)* 
    ;

Number
    :   Int ('.' Digit*)?
    ;

fragment Int
    :  '1'..'9' Digit*
    |  '0'
    ;

fragment Digit 
    :  '0'..'9'
    ;

But I'm not able to write (1, 2). It tells me "mismatched input '1' expecting ID" It is only accepting letters or letters with numbers, not just numbers.

Can you tell my what is wrong?

user2144555
  • 1,315
  • 11
  • 34
  • 55
  • As you have included it in this question, the grammar should work properly. In creating the question, you either removed some rules from your grammar, or you changed the order of the rules in such a way that it no longer produces the results you describe. (That, or you found a bug in ANTLR 3.) – Sam Harwell Jun 16 '14 at 14:28
  • Well, it's strange. I can now accept just numbers if I add " '(' Number (',' Number)* ')' -> Number+ " to "id_list". – user2144555 Jun 17 '14 at 10:51

1 Answers1

1

When given 1234444, the lexer cannot guess either you mean an ID or a number. This problem is similar to : ANTLR lexer rule consumes too much

Community
  • 1
  • 1