Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers > Preserve C/C++ ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 2283 of 2529
Post > Topic >>

Preserve C/C++ comments in ANTLR v3

by Amal <akhailtash@[EMAIL PROTECTED] > Jan 6, 2008 at 06:02 PM

I need to extract comments from C/C++/Java source file.  Normally
comments
are thrown away and they are defined as lexer rules (in ANTLR v3):

  // Single-line comments
  SL_COMMENT
    : '//' ( ~('\r'|'\n')* ) '\r'? '\n' {skip();}
    ;

  // Multi-line comments
  ML_COMMENT
    : '/*' (options {greedy=false;} : .)* '*/' {skip();}
    ;

Basically I need something like this:

  comment : sl_comment | ml_comment ;

  sl_comment : '//' COMMENT_LINE ;

  ml_comment : '/*' COMMENT_TEXT '*/' ;

How do I define COMMENT_LINE and COMMENT_TEXT?  Especially if I am
ignoring
whitespace, it becomes more confusing.

Any hints or pointers would be appreciated,
-- Amal
 




 2 Posts in Topic:
Preserve C/C++ comments in ANTLR v3
Amal <akhailtash@[EMAI  2008-01-06 18:02:27 
Re: Preserve C/C++ comments in ANTLR v3
Joel Yliluoma <bisqwit  2008-01-17 12:54:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:06:17 CDT 2008.