boost xpressive库,介于正则和bnf库之间的混血。显示c/c++代码注释部分。

#include <boost/xpressive/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)) >> self));
sregex e_if = e_if_start >> by_ref(e_if_secondhalf);
sregex e_if0_comment = e_if0_start >> by_ref(e_if_secondhalf);
sregex e_comment = e_normal_comment | e_if0_comment;
sregex e_find = e_string | e_char | e_comment[ref(cout) << _ << "/n"];

int main(int argc, char *argv[])
{
    string name;
    while (cin >> name)
    {
        ifstream f(name.c_str());
        string s((istreambuf_iterator<char>(f)), istreambuf_iterator<char>());
        for (sregex_iterator iter(s.begin(), s.end(), e_find); iter != sregex_iterator(); ++iter)
        {}
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值