[antlr-interest] Can never be matched

Bryan S Follins asalh at mindspring.com
Sun Jul 19 14:27:39 PDT 2009


Sorry group, perhaps I should have made myself clear.  This code is just
skeleton.  I just wanted to be sure I was on the right track.  I have to add
my actions later.

-----Original Message-----
From: Patrick Higgins [mailto:patrick133t at yahoo.com] 
Sent: Sunday, July 19, 2009 13:45
To: Bryan S Follins
Cc: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Can never be matched


I don't know what your grammar is supposed to be doing, but from the looks
of it, there's a lot of confusion and unfortunately I wouldn't say that
you're "almost done".

Are you using ANTLR because your course asks you to specifically use it and
you have some examples and explanations of how to use it, or does your
course not specify any particular tool and you're just using ANTLR as a tool
to understand grammars? I ask this because of your INTEGER rule. The way you
have defined it is not optimal for ANTLR and makes me think you grabbed it
from a grammar that was not intended for use with ANTLR.

Your token for DIGIT and INTEGER will actually match the same input. Can you
take a look at it and explain why?

The general problem I see is that you seem to be confused about what should
be lexer rules and what should be parser rules, and ANTLR makes it a little
confusing (although convenient) by allowing both in a single file. That bit
of confusion is also what makes me suspect you've been looking at some
grammars that were not designed for ANTLR.

Do you not have access to a professor, TA, or even a book to gain an
understanding of the basics?



----- Original Message ----
From: Bryan S Follins <asalh at mindspring.com>
To: John B. Brodie <jbb at acm.org>
Cc: antlr-interest at antlr.org
Sent: Sunday, July 19, 2009 1:10:11 PM
Subject: [antlr-interest] Can never be matched

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          :
('='|'+'|'-'|'*'|'/'|'<'|'<='|'>'|'>='|'=='|'!='|'&&'|'||'|'!');
                                

                                


                                
                                




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list