On Sun, 2009-07-19 at 12:10 -0700, Bryan S Follins wrote:
> 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
The set of strings that can be recognized by your ID rule overlaps with
the set of strings that can be recognized by your KEYWORD rule (e.g.
their set intersection is not empty). Thus the alternative 2 of the
TOKENS rule will never be matched - because any string it would match is
also matched by ID (in alt 1).
The same reasoning applies for LITERAL and ID. The LITERAL in alt 3 of
TOKEN will never match because of the (IHMO strange) way you have
defined ID, usually an identifier must begin with a letter and usuallly
a string like 01234 is not considered an identifier, yet you permit....
Hope this helps
-jbb
>
> 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 :
> ('='|'+'|'-'|'*'|'/'|'<'|'<='|'>'|'>='|'=='|'!='|'&&'|'||'|'!');
>
>
>
>
>
>
>
>
>
>
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---