[antlr-interest] "no viable alternative at character" error for '; ' and ',' in a wild cast

Indhu Bharathi indhu.b at s7software.com
Wed Mar 18 00:00:20 PDT 2009


Hi,

The problem is because ',' or '=' is not defined anywhere in the lexer rule. To be able to lex an input completely, it is necessary that the lexer grammar must account for every character that can occur in the input and be able to convert it into tokens. If you dont want to intoduce these characters in the lexer rules, you can turn on the 'filter' option in the lexer grammar. This will automatically skip any characters that are not defined in rules.

- Indhu


----- Original Message -----
From: Reynold Xin <reynoldx at gmail.com>
To: antlr-interest at antlr.org
Sent: Wednesday, March 18, 2009 12:10:38 PM GMT+0530 Asia/Calcutta
Subject: [antlr-interest] "no viable alternative at character" error for '; ' and ',' in a wild 	cast

I have the attached rules defined in ANTLR 3. I ran it (Java program)
on a simple SQL query:

SELECT abcd, wewasdf
FROM visit AS v, trial AS t
WHERE v.id = 1234 AND t.city = 'NEW YORK' AND
LINK v.diagnosis WITH t.condition USING synonym

It reports the following error:

line 1:11 no viable alternative at character ','
line 2:15 no viable alternative at character ','
line 3:11 no viable alternative at character '='
line 3:29 no viable alternative at character '='

Those characters should be accepted in rule select_until_link_or_semi,
which is defined as (~(LINK | ';'))* .

If I add ',' and '=' to the grammar definition of LETTER, the error is
gone. However, that changes the behaviour of LETTER. How can I fix
this problem?

Thanks.

-----------------------------------------
Rules
-----------------------------------------

select_stmt
       :       SELECT clause=select_until_link_or_semi
link_clause_expr opt_semicol
       {
              ...
       }
       ;

select_until_link_or_semi
    :    (~(LINK | ';'))*
    ;

NATIVE_LINK
       :       'SYNONYM' | 'HYPONYM' | 'WEIGHTEDJACCARD' ;

WORD    :       LETTER (LETTER|DIGIT|'.')* ;

NUMBER  :       DIGIT+ ;

WHITESPACE
       :       ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+ { $channel = HIDDEN; } ;

// hexadecimal digit
fragment HEX_DIGIT
       :       ('0'..'9'|'A'..'F'|'a'..'f')
       ;

// digit
fragment DIGIT
       :       '0'..'9';

// letters
fragment LETTER
       :       'a'..'z' | 'A'..'Z' | '_' | '$' | '#';

--
Reynold Xin

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list