[antlr-interest] What multiple alternative?
James Ladd
james_ladd at hotmail.com
Sat Jan 7 00:30:01 PST 2012
I have a grammar I'm working on (below) and the error I have when validating the
grammar is:
[19:22:12] warning(200): Temp.g:57:13:
Decision can match input such as "KEYWORD" using multiple alternatives: 1, 2
When I look at line 57 I just can't see how the input is matched by anything
other than the lex token KEYWORD.
How can I fix this, and how can I see the multiple matches so I can fix this myself
if it occurs again?
Rgs,James.
grammar Temp;
options {
language = Java;
}
@lexer::members {
List<RecognitionException> exceptions = new ArrayList<RecognitionException>();
public List<RecognitionException> getExceptions() { return exceptions; }
public void reportError(RecognitionException e) { super.reportError(e); exceptions.add(e); }
}
program
: primary* EOF
;
primary returns [Primary primary]
: WHITESPACE?
( IDENTIFIER {primary = new Identifier($IDENTIFIER.text, $IDENTIFIER.line);}
| NUMBER {primary = new Number($NUMBER.text, $NUMBER.line);}
| symbol_constant
| CHARACTER_CONSTANT {primary = new CharacterConstant($CHARACTER_CONSTANT.text.substring(1), $CHARACTER_CONSTANT.line);}
| STRING {primary = new StringConstant($STRING.text, $STRING.line);}
| array_constant
) // BLOCK | EXPRESSION
;
array_constant
: '#' array
;
array
: '(' array_element* ')'
;
array_element
: WHITESPACE
| NUMBER
| symbol
| STRING
| CHARACTER_CONSTANT
| array
;
symbol_constant
: '#' symbol
;
symbol
: IDENTIFIER
| BINARY_SELECTOR
| (KEYWORD)+
;
WHITESPACE: (' '|'\t'|'\r'|'\n')+;
COMMENT: '"' .* '"' {$channel = HIDDEN;};
BINARY_SELECTOR: ('-' (SPECIAL_CHAR)?) | (SPECIAL_CHAR)+;
KEYWORD: IDENTIFIER ':';
IDENTIFIER: LETTER (LETTER | DIGIT)*;
NUMBER: ((NUMBER_LEFT)? ('-')? DIGITS (NUMBER_RIGHT_P1)? (NUMBER_RIGHT_P2)?);
CHARACTER_CONSTANT: '$' ('\'' | '"' | SPECIAL_CHAR | NORMAL_CHAR | DIGIT | LETTER);
STRING: '\'' (~'\''|'\'\'')* '\'';
fragment NUMBER_LEFT: DIGITS 'r';
fragment NUMBER_RIGHT_P1: '.' DIGITS;
fragment NUMBER_RIGHT_P2: 'e' ('-')? DIGITS;
fragment LETTER: ('a'..'z' | 'A'..'Z');
fragment DIGIT: '0'..'9';
fragment DIGITS: DIGIT+;
fragment SPECIAL_CHAR: '+'|'/'|'\\'|'*'|'~'|'<'|'>'|'='|'@'|'%'|'|'|'&'|'?'|'!'|',';
fragment NORMAL_CHAR: '['|']'|'{'|'}'|'('|')'|'^'|'_'|';'|'$'|'#'|':'|'.'|'\'';
More information about the antlr-interest
mailing list