[antlr-interest] funny error message

Daniels, Troy (US SSA) troy.daniels at baesystems.com
Thu Feb 14 09:49:42 PST 2008


 


  _____  

	From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
	Sent: Thursday, February 14, 2008 11:51 AM
	To: antlr-interest at antlr.org
	Subject: Re: [antlr-interest] funny error message
	
	

	  

	  

	From: Daniels, Troy \(US SSA\)
[mailto:troy.daniels at baesystems.com] 
	Sent: Thursday, February 14, 2008 7:28 AM
	To: antlr-interest at antlr.org
	Subject: Re: [antlr-interest] funny error message 

	  

	  

		  

  _____  

		   

		From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
		Sent: Wednesday, February 13, 2008 12:45 PM
		To: antlr-interest at antlr.org
		Subject: Re: [antlr-interest] funny error message 

		  

		  

		From: Darien Hager [mailto:darien.hager at etelos-inc.com] 
		Sent: Tuesday, February 12, 2008 6:40 PM
		To: antlr-interest at antlr.org
		Subject: Re: [antlr-interest] funny error message 

		  

		  

		Well, with hindsight it looks like a pretty good error
message.
		
		I guess it might hinge on the definition of
"unreachable" or what component is doing the reaching. Two possible
quick interpretations of the message:
		
		This token cannot be reached...
		1) ...because it is an orphan not used by any parser
rules. 

		The lexer and parser are not connected. The lexer just
has to tokenize and does not care if the consumer (which may not be a
parser) knows about the token.   

	However, I can see "...because it is an orphan not used by any
lexer rules. "  While this lexer grammar is valid, it's likely not what
the user intended. 

	A: B; 

	fragment B: 'B'; 

	fragment C: 'C'; 

	C isn't unreachable in sense #2, but it won't ever be used 

	Except for: 

	  

	A: B 

	  ( 'C' { $type = C; } 

	    | 

	 ); 

	I understand what people are asking for, but it gets into the
realm where 'fixing' something for once person would be braking it for
others. 

	   

If this is the only place you use C, shouldn't you define this as

@tokens { C; }

rather than 

fragment C: 'C';

(Assume the correct syntax; I haven't moved to v3 yet.)

 It seems that the fragment rule rather than the token declaration could
easily lead to confusion, as a subsequent update might yield

 

A: B ( 'C1' { $type = C;} | }

fragment C: 'C';

If you see the C rule but not where C is set, you'd expect C to
correspond to 'C' in the input, but it actually corresponds to 'C1'.
The grammar still works, at least until somebody adds

D: B | C;

Troy

 

	Jim 

	  

	  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080214/7632421f/attachment.html 


More information about the antlr-interest mailing list