[antlr-interest] Nested Multi-Line Commentary

Kay Röpke kroepke at classdump.org
Thu Aug 14 19:27:30 PDT 2008


On Aug 15, 2008, at 3:16 AM, John B. Brodie wrote:

> and I get this error message from ANTLR v3.1:
>
> ANTLR Parser Generator  Version 3.1 (August 12, 2008)  1989-2008
> error(206): Lambda.g:1:8: Alternative 15: after matching input such  
> as '/''*''/''*''/''*''/''*''/'<EOT> decision cannot predict what  
> comes next due to recursion overflow to FRAG_ML_COMMENT from  
> FRAG_ML_COMMENT


That's funny, I don't get that message at all (and shouldn't, I think).

$ cat Comment.g
grammar Comment;

// nestable multiple-line comments
ML_COMMENT : FRAG_ML_COMMENT { $channel=HIDDEN; } ;

fragment FRAG_ML_COMMENT :
        '/*'
        ( options { greedy=false; } : (('/*')=>FRAG_ML_COMMENT) | . )*
        '*/'
   ;

CHAR	:	'a'..'z';
WS	:	(' ' | '\t' | '\n' | '\r') {$channel=HIDDEN;}
	;

foo	:	CHAR+;

$ java org.antlr.Tool Comment.g
ANTLR Parser Generator  Version 3.1 (August 12, 2008)  1989-2008
$ javac Comment*java
$ java CommentMain faulty.txt
line 1:30 mismatched character '<EOF>' expecting '*'
$ cat faulty.txt
id foo /* test /* test  */ bar
$ java CommentMain good.txt
$ cat good.txt
id foo /* test /* test */ */ bar

are you sure you don't reference it from a different location?  
"Alternative 15" looks odd in that context.
And I agree, it shouldn't overflow because it can decide without  
recursing at all thanks to the predicate.
The generated DFA for the decision in FRAG_ML_COMMENT looks like you  
would expect, too.

cheers,
-k
-- 
Kay Röpke
http://classdump.org/








More information about the antlr-interest mailing list