[antlr-interest] Seems like a bug?

Christopher Nebel c.nebel at apple.com
Tue Feb 10 11:22:59 PST 2004


Consider the following grammar:

	class L extends Lexer;
	WS :    (' ' | '\t' | '\n')+ { $setType(antlr::Token::SKIP); } ;
	protected LETTER: 'A'..'Z' | 'a'..'z' | '_';
	protected DIGIT:  '0'..'9';
	ID:    LETTER (LETTER | DIGIT)+;
	STRING: '"' ( ~('"') )* '"' ;

	class P extends Parser;
	options { buildAST = true; }
	root: "foo"^ (STRING)+ ;

If you build this and feed it 'foo "foo"', you get ( foo "foo" ), as 
you'd expect.  Now comes the tricky bit: add bangs to the STRING rule 
to exclude the enclosing quote marks, so now it reads '"'! ( ~('"') )* 
'"'! .  Try the input 'foo "foo"' again, and now you get a complaint 
about an unexpected token foo -- it thought the string was a keyword!

This is easy enough to work around -- just don't use the bangs, and 
account for the quotes elsewhere -- but it seems odd.  Is this working 
(badly) as designed, or is it just plain busted?  (I'm using antlr 
2.7.1.)


--Chris Nebel



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list