Thanks for the help!!
I tried this new definition of LINE_COMMENT, I also changed the
"operator" grammar definition to
operator
options { k=2;}
:
STAR
| '/'
| '+'
| '-'
| DBLSTAR
| '<<'
| '>>'
;
And now I get a different kind of exception.
line 1:1 rule LINE_COMMENT failed predicate: { getCharPositionInLine()
== 0 }?
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
Regards,
Anand Vidyasagar
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Gavin Lambert
Sent: Tuesday, September 02, 2008 1:32 AM
To: Vidyasagar, Anand; [EMAIL PROTECTED]
Subject: Re: [antlr-interest] Lexer Help, line-comment begins with a
character that is also an operator
At 21:14 1/09/2008, [EMAIL PROTECTED] wrote:
>In our small language we have a notion that if a line begins with
>a '*' character on Column 0 we treat it is a line comment.
>However the '*' happens to be the multiplication operator in the
>language at the same time.
[...]
>LINE_COMMENT
> : '*' ~('\n'|'\r')* '\r'? ('\n')
> {
> if(getCharPositionInLine() == 0){
> System.out.println("Found Line Comment :" +
> getLine());
> $channel=HIDDEN;
> }
> }
> ;
This will match the '*' as a LINE_COMMENT always, but only hide it
part of the time. You need to change your recognition around, and
also provide named tokens for the other variations on the asterisk
(instead of using parser literals):
fragment STAR: '*';
fragment DBLSTAR: '**';
LINE_COMMENT
: '*'
( { getCharPositionInLine() == 0 }? ~('\n'|'\r')* '\r'? '\n'
{ $channel=HIDDEN; }
| '*' { $type = DBLSTAR; }
| { $type = STAR; }
)
;
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-addr
ess
List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org:8080/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
-~----------~----~----~----~------~----~------~--~---