Boost xpressive library, which is a mix of regular expressions and BNF libraries. The C/C ++ code comments section is displayed.

Source: Internet
Author: User

# Include <boost/xpressive. HPP>
# Include <boost/xpressive/regex_actions.hpp>
Using namespace boost: xpressive;

Sregex e_string = as_xpr ('"')> * (as_xpr ('//')> _) | ~ (Boost: xpressive: Set = '//', '"')> '"';
Sregex e_char = as_xpr ('/'')> * (as_xpr (' // ') >>_) | ~ (Boost: xpressive: Set = '//', '/')> '/'';

sregex e_normal_comment = ("/">-* _> before (_ ln | EOS )) | ("/*">-* _> "*/");
sregex e_if0_start = Bol> * _ S> '#'> * _ S> "if"> * _ S> '0'> + _ s;
sregex e_if_start = Bol> * _ S> '#'> * _ S> "if ";
sregex e_if_end = '#'> * _ S> "endif">-* _> (_ ln | EOS );
sregex e_if_secondhalf =-* _> (e_if_end | (e_string | e_char | e_normal_comment | (e_if_start> Self ));
sregex e_if = e_if_start> by_ref (response);
sregex e_if0_comment = e_if0_start> by_ref (response);
sregex e_comment = e_normal_comment | response;
sregex e_find = e_string | e_char | e_comment [ref (cout) <_ <"/N"];

int main (INT argc, char * argv [])
{< br> string name;
while (CIN> name)
{< br> ifstream F (name. c_str ();
string S (istreambuf_iterator (f), istreambuf_iterator ();
for (sregex_iterator ITER (S. begin (), S. end (), e_find); iter! = Sregex_iterator (); ++ ITER)
{}< BR >}< br> system ("pause");
return exit_success;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.