[antlr-interest] Can never be matched
Bryan S Follins
asalh at mindspring.com
Sun Jul 19 12:10:11 PDT 2009
I'm almost done with a lesson grammar but I ran into a problem I get an
error referencing the TOKEN RULE, which is on Line 17 (TOKEN : ID) It also
references Line 20, where there is a blank before SEPERATOR.
The error reads: error (line)20.1: groupassign.g(file name) (line)17:8: The
following alternatives can never be matched: 2,3
Does anyone know what that error code means?
Code is below:
grammar groupassign;
@header{
import java.util.HashMap;
}
@members{
HashMap memory = new HashMap();
}
prog : WS
| COMMENT
| TOKEN;
WS : (' '|'\t'|'\n'|'\r\n')+{skip();};
COMMENT : '//'
{~('\n'|'\r'|'\r\n'))*
('\n'|'\r'|'\r\n'('\n')?)
{$setType(Token.SKIP};
newline();};
TOKEN : ID
| KEYWORD
| LITERAL
| SEPERATOR
| OPERATOR;
ID : (LETTER| DIGIT) (LETTER)*;
LETTER : ('a'..'z'|'A'..'Z')+;
DIGIT : ('0'..'9')+;
KEYWORD :
('boolean'|'else'|'if'|'int'|'main'|'void'|'while'|'print');
LITERAL : BOOLEAN
| INTEGER;
INTEGER : DIGIT
| INTEGER DIGIT;
SEPERATOR : ('('|')'|'{'|'}'|';'|',');
BOOLEAN : ('true'|'false');
OPERATOR :
('='|'+'|'-'|'*'|'/'|'<'|'<='|'>'|'>='|'=='|'!='|'&&'|'||'|'!');
More information about the antlr-interest
mailing list