[antlr-interest] "no viable alternative at character" error for '; ' and ',' in a wild cast
Reynold Xin
reynoldx at gmail.com
Tue Mar 17 23:40:38 PDT 2009
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
More information about the antlr-interest
mailing list