Am Thursday 16 July 2009 12:14:55 schrieb Gokulakannan Somasundaram:
> Hi,
>    I am trying to filter out multi-line comments, for which i am using the
> following Token definition (provided in antlr.org)
> ML_COMMENT
>
>     :    '/*' ( options { greedy = false; } : .* ) '*/' { skip(); };
>

I have done it like this:
in the lexer I added a member openComment:

@member {
        boolean openComment = false;

        //override nextToken:
        @Override
        public Token nextToken() {
                Token t = super.nextToken();
                if (t == Token.EOF_TOKEN && openComment) {
                        System.err.println("gotcha!");
                }
                return t;
        }

}


change your comment rule :

ML_COMMENT
@init { openComment = true: }
    :    '/*' ( options { greedy = false; } : .* ) '*/' { openComment = false; 
skip(); };




don't know if this is nice, but it works :-)
 Michael


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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to