[antlr-interest] Grammar for block comments?

Andy Doddington andy at doddington.net
Tue Jul 15 10:45:27 PDT 2008


I am trying to write a grammar that includes support for C-style block
comments - i.e. bracketed by '/*' and '*/'.

I have taken the example in the cpp.g grammar on the antlr web site, which
appears as shown below:

	COMMENT: '/*'  ( options {greedy=false;} : . )*  '*/' { _channel=99; };

Unfortunately, when this encounters a comment containing asterisks, I get the error:

        line <line>:<column> mismatched character '*' expecting '/'

Is there any better solution, that avoids this problem?

Thanks,

    Andy D.





More information about the antlr-interest mailing list