[antlr-interest] Grammar refuses to compile (Simple ANTLR gotcha)
Ilia Kantor
ilia at obnovlenie.ru
Tue Apr 24 05:40:51 PDT 2007
Hello,
Haven't used antlr for a bit... And need to write a grammar once again =)
Version is:3.0b7
This grammar doesn't compile (ambiguitiy)
I want "rule_call" to match "#a.b.c" from arbitrary text
Could you please explain what's the reason of error I have here and how to fix it ?
warning(200): My.g:8:24: Decision can match input such as "DOT WORD" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(200): My.g:8:24: Decision can match input such as "MINUS GT WORD" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
-----------------------------------------
document:
(text | rule_call)+;
rule_call:
GET_SCOPE_VALUE WORD rule_long_def_part+;
rule_long_def_part
:
(MINUS GT WORD) => MINUS GT WORD |
(DOT WORD) => DOT WORD;
text:
DOT | MINUS | WORD | WS| GT | SPECIAL_CHAR ;
LCURL : '{';
RCURL : '}';
GET_SCOPE_VALUE
: '#';
DOT : '.';
MINUS
: '-';
GT : '>';
SPECIAL_CHAR
: '`' | '!' | '@' | '$' | '%' | '^' | '&' | '*' | '(' | ')' |
'+' | '=' | '[' | ']' | ';' | ':' | '\'' | '"' | '\\' | '|' | ',' | '<' |
'/' | '?';
fragment WS_CHAR :
(' '|'\r'|'\t'|'\u000C'|'\n' )
;
WS : WS_CHAR+;
// not SPECIAL_CHAR not WS_CHAR
WORD:
(~ ('`' | '!' | '@' | '$' | '%' | '^' | '&' | '*' | '(' | ')' |
'+' | '=' | '[' | ']' | ':' | '\'' | '"' | '\\' | '|' | ',' | '<' | '/' | '?'
| '{' | '~' | '}' | '#' | ';' | '.' | '-' | '>' | ' '|'\r'|'\t'|'\u000C'|'\n' ) )+
;
More information about the antlr-interest
mailing list