[antlr-interest] nested comments
Bastian Schmitz
bastian.schmitz at udo.edu
Sun Jul 3 03:36:37 PDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
hi,
i'm trying to figure out a lexer rule for c-style nested comment
regognition. what i got so far looks like this:
ML_COMMENT
:
"/*" ML_COMMENT_CONTENT
( options {greedy=true;} : ML_COMMENT ML_COMMENT_CONTENT ) *
"*/"
{$setType(Token.SKIP);}
;
protected
ML_COMMENT_CONTENT
:
(
{ LA(2)!='/' }? '*'
| { LA(2)!='*' }? '/'
| '\r' '\n' {newline();}
| '\r' {newline();}
| '\n' {newline();}
| ~('*'|'/'|'\n'|'\r')
)*
;
this matches mutliline nested comments (i havn't found a counterexample)
but i get 3 errors about lexical nondeterminisms. the one about
linefeeds is ok for me; when i change the subrule matching behavior to
greedy/non-greedy the lexer doesn't work correctly anymore.
so what do i have to change to eleminate the warnings or is there an
easier or better way to handle this task.
best regards,
bastian schmitz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
iD8DBQFCx7+16Jg7o3nQ6wARAup0AJoCs/GAtUWFq+vThHNMpW+EQOdpVQCeK/SC
4KTnwWPNhgepGrJGyh+Mpi4=
=2siZ
-----END PGP SIGNATURE-----
More information about the antlr-interest
mailing list